How to use zen-observable - 10 common examples

To help you get started, we’ve selected a few zen-observable 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 4lejandrito / creepyface / src / points.js View on Github external
export default function points() {
    return new Observable(observer => {
        let cancelMouse = listen(document, 'mousemove').subscribe(
            event => observer.next(point(event.pageX, event.pageY, event.target))
        );
        let cancelFinger = listen(document, 'touchmove').subscribe(event => {
            // sum all the vectors and return the angle
            var touch = event.changedTouches[0];
            observer.next(point(touch.pageX, touch.pageY, event.target));
        });
        return () => {
            cancelMouse();
            cancelFinger();
        };
    });
}
github sw-yx / reactive-react / reactive-react / swyxjs.js View on Github external
export function Interval(tick = 1000, tickData = Symbol('tick')) {
  return new Observable(observer => {
    let timer = () => setTimeout(() => {
      if (typeof tickData === 'function') tickData = tickData()
      observer.next(tickData);
      timer()
      // observer.complete();
    }, tick);
    timer()
  
    // On unsubscription, cancel the timer
    return () => clearTimeout(timer);

  })
}
github sw-yx / reactive-react / reactive-react / swyxjs.js View on Github external
export function startWith(obs, val) {
  return new Observable(observer => {
    observer.next(val) // immediately output this value
    const handler = obs.subscribe(x => observer.next(x))
    return () => handler()
  })
}
github sw-yx / reactive-react / build / reactive-react.es.js View on Github external
function renderStream(element, instance, state, stateMap) {
  // this is a separate function because scope gets messy when being recursive
  var isNewStream = false; // assume no stream switching by default
  // this is the first ping of data throughout the app
  var source = Observable.of(state);
  var addToStream = function addToStream(_source) {
    // visit each source and merge with source
    if (_source) return source = merge(source, _source);
  };
  var markNewStream = function markNewStream() {
    return isNewStream = true;
  };
  var newInstance = render(source, addToStream, markNewStream)(element, instance, state, stateMap);
  return { source: source, instance: newInstance, isNewStream: isNewStream };
}
github sw-yx / reactive-react / build / reactive-react.es.js View on Github external
var addToStream = function addToStream(_source) {
    // visit each source and merge with source
    if (_source) return source = merge(source, _source);
  };
  var markNewStream = function markNewStream() {
github sw-yx / reactive-react / build / reactive-react.es.js View on Github external
var subReducer = fn(obj);
        // there are two forms of return the subreducer can have
        // straight stream form
        // or object form where we need to scan it into string
        if (subReducer.source && subReducer.reducer) {
          // object form
          subReducer = scan(subReducer.source, subReducer.reducer || function (_, n) {
            return n;
          }, _this.initialState[k]);
        }
        return subReducer.map(function (x) {
          return _defineProperty({}, k, x);
        }); // map to its particular namespace
      });
      var source = merge.apply(undefined, _toConsumableArray(sources));
      var reducer = function reducer(acc, n) {
        return _extends({}, acc, n);
      };
      return { source: source, reducer: reducer };
    }
  }]);
github SamVerschueren / listr / test / utils.js View on Github external
test('isObservable', t => {
	t.false(isObservable(null));
	t.false(isObservable({}));
	t.false(isObservable(new Listr([])));
	t.false(isObservable(new Promise(() => {})));
	t.true(isObservable(new RxObservable(() => {})));
	t.true(isObservable(new ZenObservable(() => {})));
});
github kefirjs / kefir / test / specs / from-es-observable.js View on Github external
it('turns an ES7 observable into a stream', () => {
    expect(Kefir.fromESObservable(Observable.of(1, 2))).to.be.observable.stream()
  })
github kefirjs / kefir / test / specs / es-observable.js View on Github external
it('outputs a compatible Observable', done => {
    const a = stream()
    const values = []
    const observable = Observable.from(a)
    observable.subscribe({
      next(x) {
        values.push(x)
      },
      complete(x) {
        expect(values).toEqual([1, 2, 3])
        done()
      },
    })
    send(a, [1, 2, 3, ''])
  })
github laconalabs / elliptical / test / dynamic.jsx View on Github external
function Test ({props}) {
      return new Observable((observer) => {
        observer.next(props.input)
      })
    }

zen-observable

An Implementation of ES Observables

MIT
Latest version published 2 years ago

Package Health Score

70 / 100
Full package analysis

Similar packages