How to use the baconjs.mergeAll function in baconjs

To help you get started, we’ve selected a few baconjs 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 viddo / atom-textual-velocity / lib / path-watcher-factory.js View on Github external
.fromNodeCallback(fileReader.read.bind(fileReader), notesPath.fullPath(filename), fileStats)
                .map(value => {
                  readResult.value = value === undefined ? null : value // make sure value cannot be undefined
                  return readResult
                })
                .mapError(err => {
                  console.warn('failed to read file:', err)
                  return readResult
                })
            })
        })
    }

    const newFileS = createFileStream('add')

    const fileReaderResultS = Bacon
      .mergeAll(
        createFileReaderResultsStream(newFileS, notesCache),
        createFileReaderResultsStream(createFileStream('change'))
      )

    const updateNoteProps = (note: Object, fields: Array, filename: string) => {
      note.id = process.hrtime().toString()
      fields.forEach(field => {
        if (field.value) {
          note[field.notePropName] = field.value(note, filename)
        }
      })
    }

    const sifterP = Bacon
      .update(
github viddo / atom-textual-velocity / lib / side-effects.js View on Github external
_saveRowHeightOnWinResize (rowsS: Bacon.Stream) {
    return Bacon
      .mergeAll(
        rowsS.take(1),
        Bacon.fromEvent(window, 'resize'))
      .debounceImmediate(50) // ms
      .onValue(() => {
        const td = this._queryDOM('td')
        if (td && td.clientHeight > 0) {
          atom.config.set('textual-velocity.rowHeight', td.clientHeight)
        }
      })
  }
github viddo / atom-textual-velocity / lib / interactor.js View on Github external
})

    this.listHeightP = Bacon
      .update(0,
        [viewCtrl.listHeightS], R.nthArg(-1),
        [viewCtrl.sessionStartS.map('.listHeight')], R.nthArg(-1))
      .skipDuplicates()

    this.rowHeightP = Bacon
      .update(0,
        [viewCtrl.rowHeightS], R.nthArg(-1),
        [viewCtrl.sessionStartS.map('.rowHeight')], R.nthArg(-1))
      .skipDuplicates()

    const itemsP = this.sifterResultP.map('.items')
    const lastSelectionChangeTimeP = Bacon
      .mergeAll(
        viewCtrl.keyUpS.map(Date.now),
        viewCtrl.keyDownS.map(Date.now),
        viewCtrl.clickedCellS.map(Date.now),
        this.searchStrS.map(Date.now),
      )
      .toProperty(Date.now())

    this.selectedFilenameS = Bacon
      .update(undefined,
        [viewCtrl.activePathS, this.notesPathP, this.notesP, lastSelectionChangeTimeP], (old, path, notesPath, notes, lastSelectionChangeTime) => {
          if (Date.now() - lastSelectionChangeTime < 100) return old // make sure selection by user (e.g. keyup) has precedence over path change, since the delay of the trigger otherwise cause jumpy behavior
          if (!path) return
          const filename = notesPath.filename(path)
          if (notes[filename]) return filename
        },
github kefirjs / kefir / test / perf / memory.js View on Github external
createNObservable('Bacon', 500, function(){
  return Bacon.mergeAll(baseBacon(), baseBacon(), baseBacon(), baseBacon());
})
github rbelouin / fip.rbelouin.com / test / unit / controllers / route.spec.js View on Github external
switch (path) {
          case "/a":
            routes.a.push();
            break;
          case "/b":
            routes.b.push();
            break;
          default:
            routes.errors.push();
            break;
        }
      }
    }
  };

  const p_route = Bacon.mergeAll([
    routes.a.map("a"),
    routes.b.map("b"),
    routes.errors.map("errors")
  ]);

  p_route
    .fold([], (acc, elem) => acc.concat([elem]))
    .subscribe(function(ev) {
      expect(ev.hasValue()).toBeTruthy();

      expect(ev.value()).toStrictEqual(["a", "b", "errors"]);

      done();

      return Bacon.noMore;
    });
github viddo / atom-textual-velocity / lib / side-effects.js View on Github external
_renderResultsOnDataChanges (presenter: PresenterType, view: ViewType) {
    return Bacon
      .combineTemplate({
        columns: presenter.columnHeadersP,
        forcedScrollTop: presenter.forcedScrollTopP,
        itemsCount: presenter.itemsCountP,
        listHeight: presenter.listHeightP,
        loadingProgress: presenter.loadingProgressP,
        paginationStart: presenter.paginationP.map('.start'),
        rowHeight: presenter.rowHeightP,
        rows: presenter.rowsS,
        searchStr: presenter.searchStrP,
        sort: presenter.sortP
      })
      .sampledBy(
        Bacon.mergeAll(
          presenter.listHeightP.changes(),
          presenter.forcedScrollTopP.changes(),
          presenter.rowsS))
      .onValue((params: ResultsViewParamsType) => {
        view.renderResults(params)
      })
  }
github staltz / callbag-basics / perf / merge.js View on Github external
.add('bacon', function(deferred) {
    var streams = a.map(bacon.fromArray);
    runners.runBacon(deferred, bacon.mergeAll(streams).reduce(0, sum));
  }, options)
  .add('lodash', function() {
github viddo / atom-textual-velocity / lib / view-ctrl.js View on Github external
this.keyEscS = newKeyS(27)
    this.keyUpS = newKeyS(38)

    this.listHeightS = Bacon
      .mergeAll(
        this._listHeightBus,
        atoms.createConfigStream('textual-velocity.listHeight'))
      .skipDuplicates()

    this.sortDirectionS = Bacon
      .mergeAll(
        this._sortDirectionBus,
        atoms.createConfigStream('textual-velocity.sortDirection'))
      .skipDuplicates()

    this.sortFieldS = Bacon
      .mergeAll(
        this._sortFieldBus,
        atoms.createConfigStream('textual-velocity.sortField'))
      .skipDuplicates()
  }
github rbelouin / fip.rbelouin.com / src / fip / radio-metadata / index.ts View on Github external
function repeat(
  interval: number,
  f: () => Bacon.Property
): Bacon.Property {
  return ignoreNonRecurringErrors(
    6 * interval,
    5,
    Bacon.mergeAll(
      f().toEventStream(),
      Bacon.repeat(() => Bacon.later(interval, true).flatMap(f))
    )
  ).toProperty();
}
github rbelouin / fip.rbelouin.com / src / fip / radio-metadata / index.ts View on Github external
export function ignoreNonRecurringErrors(
  interval: number,
  threshold: number,
  stream: Bacon.EventStream
): Bacon.EventStream {
  return Bacon.mergeAll(
    stream.skipErrors() as Bacon.EventStream,
    stream
      .errors()
      .mapError(e => e)
      .bufferWithTime(interval)
      .filter(errors => errors.length >= threshold)
      .flatMap(
        errors => new Bacon.Error(errors[errors.length - 1])
      ) as Bacon.EventStream
  );
}