How to use the baconjs.combineTemplate 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 / workers / session.js View on Github external
.update(
        ({
          str: '',
          strChanged: true,
          start: 0,
          limit: paginationLimit
        }),
        [this._filterBus], (prev, filter) => {
          var newFilter = R.merge(prev, filter)
          newFilter.strChanged = filter.str !== undefined && filter.str !== prev.str
          return newFilter
        }
      )
      .skipDuplicates(R.equals)

    this._sifterResultProp = Bacon
      .combineTemplate({
        sifter: this._sifterProp,
        sortField: this._sortFieldBus.toProperty(sortField),
        sortDirection: this._changeSortDirectionBus.scan(sortDirection, (a, b) => a === 'desc' ? 'asc' : 'desc'),
        searchStr: this._filterProp.map('.str')
      })
      .map(d => {
        // see https://github.com/brianreavis/sifter.js/#searchquery-options for available configuration options
        return d.sifter.search(d.searchStr, {
          fields: ['name', 'content'],
          sort: [
            {field: d.sortField, direction: d.sortDirection},
            {field: '$score', direction: d.sortDirection}
          ],
          conjunction: 'and'
        })
github viddo / atom-textual-velocity / lib / side-effects.js View on Github external
_previewSelectedPath (presenter: PresenterType) {
    const PREVIEW_SCHEMA_PREFIX = 'tv://'

    return new Disposables(
      atom.workspace.addOpener((uri) => {
        if (uri.startsWith(PREVIEW_SCHEMA_PREFIX)) {
          return this._preview
        }
      }),
      Bacon
        .combineTemplate({
          path: presenter.selectedPathP,
          content: presenter.selectedContentP,
          searchRegex: presenter.searchRegexP
        })
        .debounce(25) // ms
        .onValue((template: {path?: string, content?: string, searchRegex?: RegExp}) => {
          const {path, content, searchRegex} = template
          if (path && content === undefined) return // e.g. due to note rename, just skip

          if (path) {
            for (let textEditor of atom.workspace.getTextEditors()) {
              if (textEditor.getPath() === path) {
                // there is already a text-editor use that as preview instead
                this._closePreview()
                atom.workspace.open(path, {
github viddo / atom-textual-velocity / lib / workers / session.js View on Github external
sortDirection: this._changeSortDirectionBus.scan(sortDirection, (a, b) => a === 'desc' ? 'asc' : 'desc'),
        searchStr: this._filterProp.map('.str')
      })
      .map(d => {
        // see https://github.com/brianreavis/sifter.js/#searchquery-options for available configuration options
        return d.sifter.search(d.searchStr, {
          fields: ['name', 'content'],
          sort: [
            {field: d.sortField, direction: d.sortDirection},
            {field: '$score', direction: d.sortDirection}
          ],
          conjunction: 'and'
        })
      })

    this._filteredResultsStream = Bacon
      .combineTemplate({
        files: filesProp,
        filter: this._filterProp,
        sifterResult: this._sifterResultProp
      })
      .changes() // to avoid initial property value from trigger subscribers directly
  }
github rbelouin / fip.rbelouin.com / test / unit / models / storage.spec.js View on Github external
test("Storage.sync should return a sync object for the storage", function(done) {
  const storage = {};
  const s = sync(storage, "favorite");

  const p_initial = s.get();

  const p_storage = p_initial
    .flatMapLatest(() => s.set([1, 2]).map(() => storage))
    .toProperty();

  const p_final = p_storage.flatMapLatest(() => s.get()).toProperty();

  const property = Bacon.combineTemplate({
    p_initial,
    p_storage,
    p_final
  });

  property.subscribe(function(ev) {
    expect(ev.hasValue()).toBeTruthy();
    expect(ev.value()).toStrictEqual({
      p_initial: [],
      p_storage: { favorite: JSON.stringify([1, 2]) },
      p_final: [1, 2]
    });

    done();

    return Bacon.noMore;
github vokkim / tuktuk-chart-plotter / src / client / provider-signalk.js View on Github external
function parseAISData({selfStream, address, rawStream, settings}) {
  const hasSelf = selfStream
    .take(1)
    .map(true)
    .toProperty(false)
  const aisEnabled = settings.map(s => _.get(s, 'ais.enabled', false)).skipDuplicates()
  //TODO: Subscribe / unsubscribe for AIS vessels
  const aisStream = rawStream
    .filter(aisEnabled)
    .map(singleDeltaMessageToAisData)
    .bufferWithTimeOrCount(1000, 100)
    .map(deltas => _.reduce(deltas, _.merge, {}))
  const fullAisData = Bacon.combineTemplate({
    hasSelf,
    aisEnabled
  })
    .flatMapLatest(({hasSelf, aisEnabled}) => {
      return hasSelf && aisEnabled ? getInitialAISData(address).concat(aisStream) : Bacon.once()
    })
    .scan({delta: {}, full: {}}, (previous, data) => {
      const full = _.merge({}, previous.full, _.omitBy(data, (value, key) => isSelf(key)))
      const delta = _.pick(full, _.keys(data))
      return {delta, full}
    })

  const deltaAisData = fullAisData.map('.delta').filter(d => !_.isEmpty(d))

  function getVesselAisData(vesselId) {
    return fullAisData
github ayasin / frhttp / lib / frhttp.js View on Github external
function verbFindRouteAt(graph, path) {
	return Bacon.combineTemplate({
		graph: graph,
		path: path.pathname.split('/')
	}).take(1).map(
		function (source) {
			var root = source.graph;
			var walker = root;
			var start = source.path[0].length ? 0 : 1;
			for (var i=start; i < source.path.length; i++) {
				if (walker[source.path[i]]) {
					walker = walker[source.path[i]];
				}
				else if (walker[WILDCARD_TAG]) {
					walker = walker[WILDCARD_TAG];
					break;
				}
				else if (walker[VARIABLE_TAG]) {
github viddo / atom-textual-velocity / lib / side-effects.js View on Github external
_openTextEditorOnOpenEvent (presenter: PresenterType) {
    return Bacon
      .combineTemplate({
        selectedPath: presenter.selectedPathP,
        newPath: presenter.newPathP
      })
      .sampledBy(
        Bacon
          .fromEvent(this._preview, 'click')
          .merge(presenter.openPathS))
      .onValue(({selectedPath, newPath}) => {
        const path = selectedPath || newPath
        if (path) {
          atom.workspace
            .open(path)
            .then(() => {
              this._closePreview()
            })
github milankinen / ffux / lib / ffux-bacon.js View on Github external
function composeStateP(stateModelProps) {
  const template = zipObject(stateModelProps)
  return Bacon.combineTemplate(template)

}
github milankinen / livereactload / examples / 04-custom-state / site.js View on Github external
function initApp(model) {
  var modelStream = Bacon.combineTemplate({
    items: items._items(model.items || []),
    editedItem: items._editedItem()
  })

  modelStream.onValue(function(model) {
    lrapi.setState(model)
    React.render(, document.getElementById('app'))
  })
}