How to use the rx.BehaviorSubject function in rx

To help you get started, we’ve selected a few rx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tomlarkworthy / animaxe / dist / examples / example6.js View on Github external
Slider.rectangular = function (value, postprocessor) {
        var hotspot = Ax.create()
            .withinPath(Ax.create()
            .lineTo([20, 0])
            .lineTo([20, 20])
            .lineTo([0, 20])
            .lineTo([0, 0]));
        value.subscribe(function (x) { return console.log("pre construction value changed", x); });
        var slider = new Slider(hotspot, new events.ComponentMouseState(), new events.ComponentMouseState(), value, Ax.create().fillStyle("red"), /* pressed */ Ax.create().fillStyle("orange"), /* over */ Ax.create().fillStyle("white") /* idle */); /* idle */
        if (postprocessor)
            postprocessor(slider);
        return slider;
    };
    return Slider;
})(Ax.Operation);
var value = new Rx.BehaviorSubject(0);
//each frame, first draw black background to erase the previous contents
animator.play(Ax.create().fillStyle(Parameter.rgba(Parameter.updateFrom(0, value).mapValue(function (x) { return x * 2.5; }), 0, 0, 1)).fillRect([0, 0], [100, 100]));
animator.play(Ax.create()
    .pipe(Slider.rectangular(value)));
helper.playExample("@name", 2, animator, 100, 100);
github byteclubfr / copycast / client / drivers / cycle-socket.io.js View on Github external
export default function createSocketIODriver() {
	let socketOptions = {}
	if (document.location.hostname.match(/(\.localtunnel\.me|\.ngrok\.io)$/)) {
		// Websocket transports screws the whole thing when tunnelling through localtunnel
		socketOptions = { transports: ['polling'] }
	}

	const socket = io.connect(socketOptions)

	// 'connect' and 'disconnect' cannot be implemented just like 'get' as
	// those events could be emitted BEFORE observable is actually ready
	const statusSubject = new BehaviorSubject({ connected: false, status: 'connecting', error: null })
	const status$ = statusSubject.asObservable()
	const watchStatusChange = (status, connected, isErr = false) =>
		socket.on(status, e => statusSubject.onNext({
			connected,
			status,
			error: isErr ? e : null
		}))
	watchStatusChange('error', false, true)
	watchStatusChange('connect', true)
	watchStatusChange('disconnect', false)
	watchStatusChange('reconnect', true)
	//watchStatusChange('reconnect_attempt', false)
	//watchStatusChange('reconnecting', false)
	watchStatusChange('reconnect_error', false, true)
	//watchStatusChange('reconnect_failed', false)
github fdecampredon / rx-react / test / stateStreamMixin.js View on Github external
t.test('cleanAllSubscriptions', function (t) {
    var stateStream = new Rx.BehaviorSubject({ foo: 'bar'});
    var Component = React.createClass({
      displayName: 'Component',
      mixins: [StateStreamMixin],
      getStateStream: function () {
        return stateStream;
      },
      render: function () {
        return null;
      }
    });
    
    var component = testUtils.render(React.createElement(Component));
    cleanAllSubscriptions();
    stateStream.onNext({ hello: 'world'});
    t.deepEquals(component.state, { foo: 'bar'}, 'the state should not been bound anymore to stateStream after a call to `cleanAllSubscriptions`');
    t.notOk(stateStream.hasObservers(), 'the subscrition to stateStream should have been cleaned after a call tp `cleanAllSubscriptions` ');
github milankinen / ffux / test / state-spec.js View on Github external
      state: (value) => new Rx.BehaviorSubject(value + 2)
    })
github marinels / webrx-react / src / WebRx / Command.ts View on Github external
constructor(
    protected executeAction: (parameter: any) => Observable,
    canExecute?: Observable,
  ) {
    this.isExecutingSubject = new BehaviorSubject(false);
    this.canExecuteSubject = new BehaviorSubject(canExecute == null);
    this.resultsSubject = new Subject();
    this.thrownErrorsSubject = new Subject();

    this.canExecuteSubscription = (canExecute || asObservable(true))
      .combineLatest(this.isExecutingSubject, (ce, ie) => ce === true && ie === false)
      .catch(e => {
        handleError(e, this.thrownErrorsSubject);

        return asObservable(false);
      })
      .distinctUntilChanged()
      .subscribe(this.canExecuteSubject);
  }
github stomita / rxdux / src / index.js View on Github external
export function createStore(reducer, initialState, errorRecoveryHandler = defaultErrorRecoveryHandler) {
  const action$ = new BehaviorSubject({ type: '@@rxdux/INIT' });
  const state$ = createState(reducer, initialState, action$, errorRecoveryHandler);
  return new Store(action$, state$);
}
github oscarduignan / react-rxjs-elasticsearch-faceted-search-example / src / js / search / observables.factory.js View on Github external
var ObservablesFactory = function({
    query='',
    selectedTags=[],
    selectedTypes=[],
    resultsPerPage=5,
    page=1,
}) {
    var subjects = {
        query: new Rx.BehaviorSubject(query),
        selectedTags: new Rx.BehaviorSubject(selectedTags),
        selectedTypes: new Rx.BehaviorSubject(selectedTypes),
        resultsPerPage: new Rx.BehaviorSubject(resultsPerPage),
        resultsFrom: new Rx.BehaviorSubject(resultsPerPage * (page - 1)),
        searchInProgress: new Rx.BehaviorSubject(false)
    };

    var actions = {
        changeQuery(nextQuery) {
            return subjects.query.onNext(nextQuery);
        },

        changePage(nextPage) {
            return subjects.resultsFrom.onNext((nextPage - 1) * subjects.resultsPerPage.value);
        },

        toggleFilter(filter, term) {
github tusharmath / Multi-threaded-downloader / src / mtd.js View on Github external
constructor (ob, options) {
    this.options = initParams(options)
    this.ob = ob
    this.fd = createFD(ob, this.options.mtdPath)
    this.stats = new Rx.BehaviorSubject()
    this.toStat = _.curry((event, message) => this.stats.onNext({event, message}))
    this.toStat('INIT', this.options)
  }