How to use the kefir.fromEvents function in kefir

To help you get started, we’ve selected a few kefir 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 ivan-kleshnin / unredux / examples / 7.crud / client / root / index.js View on Github external
// Internal link
          if (urlObj.pathname == document.location.pathname && urlObj.hash) {
            // Anchor link
            // do nothing, rely on default browser behavior
          } else {
            // Page link or Reset-Anchor link (foo#hash -> foo)
            ee.event.preventDefault() // take control of browser
            window.scrollTo(0, 0)     //
          }
          window.history.pushState({}, "", urlObj.relHref)
          return K.constant(urlObj.relHref)
        }
      }),

    navigateHistory$: D.isBrowser
      ? K.fromEvents(window, "popstate")
          .map(data => U.relHref(document.location.href)) // TODO scroll to hash (how?!)
      : K.never()
  }

  // STATE
  let state$ = D.run(
    () => D.makeStore({}),
    // D.withLog({key}),
  )(
    // Init
    D.init(seed),
    D.initAsync(sources.state$),

    // Navigation
    intents.navigateTo$.map(url => R.fn("navigateTo", R.set2("url", url))),
    intents.navigateHistory$.map(url => R.fn("navigateHistory", R.set2("url", url))),
github tungv / jerni / packages / heq-server / src / adapters / in-memory.js View on Github external
const subscribe = () => {
    // console.log('subscribe', { id });
    const events$ = kefir.fromEvents(emitter, 'data');

    return { events$ };
  };
github ivan-kleshnin / unredux / examples / 7.crud / client / blueprints.js View on Github external
// Internal link
            if (urlObj.pathname == document.location.pathname && urlObj.hash) {
              // Anchor link
              // do nothing, rely on default browser behavior
            } else {
              // Page link or Reset-Anchor link (foo#hash -> foo)
              ee.event.preventDefault() // take control on browser
              window.scrollTo(0, 0)     //
            }
            window.history.pushState({}, "", urlObj.relHref)
            return K.constant(urlObj.relHref)
          }
        }),

      navigateHistory$: D.isBrowser
        ? K.fromEvents(window, "popstate")
          .map(data => U.relHref(document.location.href)) // TODO scroll to hash (how?!)
        : K.never(),
    }
  }
github StreakYC / react-menu-list / src / SubMenuItem.js View on Github external
// pixels per second the user must be moving the mouse toward the menu for
    // the menu to stay open.
    const MIN_SPEED = 60;

    // ms before the menu will close if the user hasn't reached it yet, no
    // matter how they're moving the cursor toward it.
    const MAX_TIME = 750;

    // ms to offset start time, to set maxDistance back a little so it's not so
    // unforgiving at the very start.
    const LEAD_TIME = 50;

    // Listen to mouse moves, find the first event not going towards the menu,
    // and end it there. Or end after a timer.
    Kefir.fromEvents(window, 'mousemove')
      .bufferBy(Kefir.interval(60, null))
      .map(events => {
        if (events.length) {
          const last = events[events.length-1];
          lastCoords = {pageX: last.pageX, pageY: last.pageY};
        }
        return lastCoords;
      })
      .filter(({pageX, pageY}) => {
        const distance = getDistance(pageX, pageY);
        const maxDistance = startDistance - (Date.now()-startTime-LEAD_TIME)/1000 * MIN_SPEED;
        return distance > maxDistance;
      })
      .merge(Kefir.later(MAX_TIME*1000))
      .take(1)
      .takeUntilBy(this._resetMouseLeaveWatcher)
github irskep / summertunes / client / src / model / browsingModel.js View on Github external
const keyMapper = (k) => (obj) => obj[k] || null;

/* URL data */

let latestURLData = null;
const getURLData = () => {
  if (!window.location.search) return {artist: null, album: null};
  latestURLData = {
    artist: null,
    album: null,
    ...parseURLQuery(window.location.search.slice(1)),
  };
  return latestURLData;
}
const [sendStatePushed, statePushes] = createBus();
const kURLDataChanges = K.fromEvents(window, 'popstate')
  .merge(statePushes)
  .merge(K.constant(null))
  .map(getURLData);

const urlUpdater = (k) => (arg) => {
  const newURLData = {
    ...latestURLData,
    [k]: arg,
  }
  latestURLData = newURLData;
  history.pushState(null, "", makeURLQuery(newURLData));
  sendStatePushed();
}

/* data */
github StreakYC / react-menu-list / src / MenuList.js View on Github external
componentDidMount() {
    const isEnterOrArrowKey = e =>
      (e.which === 13) || (37 <= e.which && e.which <= 40);
    const el = this._elRef.current;
    /*:: if (!el) throw new Error(); */

    // The only things that should receive keydown/keypress events before us
    // are our children. This allows a MenuItem to contain a text input
    // which selectively stops propagation on key events for example.
    Kefir.merge([
      Kefir.fromEvents(window, 'keydown').filter(isEnterOrArrowKey)
        .filter(e => el.contains(e.target)),
      fromEventsCapture(window, 'keydown').filter(isEnterOrArrowKey)
        .filter(e => !el.contains(e.target))
    ])
      .takeUntilBy(this._stopper)
      .onValue(event => this._key(event));

    const parentCtx = this._parentCtx();
    if (parentCtx) {
      parentCtx.registerMenuList(this);
    }
  }
github StreakYC / react-float-anchor / src / index.js View on Github external
const portalEl = this._portalEl;
    /*:: if (!portalEl) throw new Error(); */
    if (portalEl.parentElement) {
      throw new Error('Should not happen: portalEl already in page');
    }

    const anchorRef = this._getAnchorRef();
    if (!anchorRef) throw new Error('ReactFloatAnchor missing anchorRef element');
    (portalEl: any).rfaAnchor = anchorRef;

    const target = this.props.parentElement || document.body || document.documentElement;
    /*:: if (!target) throw new Error(); */
    target.appendChild(portalEl);

    Kefir.merge([
      Kefir.fromEvents(window, 'resize'),
      fromEventsWithOptions(window, 'scroll', {
        capture: true,
        passive: true
      }).filter(event => {
        const anchorRef = this._getAnchorRef();
        return anchorRef && event.target.contains(anchorRef);
      })
    ])
      .takeUntilBy(this._portalRemoval)
      .onValue(() => {
        this.repositionAsync();
      })
      .onEnd(() => {
        (portalEl: any).rfaAnchor = undefined;
        /*:: if (!portalEl.parentElement) throw new Error(); */
        portalEl.parentElement.removeChild(portalEl);
github seedofjoy / bazooka / examples / gifflix / star.js View on Github external
function starBazFunc(node) {
  Kefir.fromEvents(node, 'click')
    .map(function(e) {
      return {
        tell: 'singleFavUpdate',
        id: getAttrs(e.target).id,
        active: !getAttrs(e.target).active,
      };
    })
    .onValue(function(msg) {
      window.appBus.push(msg);
    });

  window.appBus
    .filter(function(msg) {
      return msg.tell == 'favsUpdate';
    })
    .map(function(msg) {
github brainbang / mindwave / example.js View on Github external
function asProp (ev) {
  return kefir.fromEvents(mw, ev).map(prop(ev))
}
github codefresh-io / zenkube / web_server / src / server.js View on Github external
        .takeUntilBy(kefir.merge(["end", "close"].map((name)=> kefir.fromEvents(req, name))).take(1))
        .onValue((data)=> {

kefir

Reactive Programming library for JavaScript inspired by Bacon.js and RxJS with focus on high performance and low memory usage

MIT
Latest version published 4 years ago

Package Health Score

57 / 100
Full package analysis