How to use the baconjs.fromEvent 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 / 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 fiveNinePlusR / tabist / src / js / options.js View on Github external
});
}

// Bacon.fromEvent();

document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);

// tab backup and restore
document.getElementById("backup_tabs").onclick = function() {
  chrome.tabs.query({}, function(tabs) {
    download(JSON.stringify(tabs, null, " "));
  });
};

let restoreTab = Bacon.fromEvent(document.getElementById("restore_tabs_file"), "change");
let fileinput = document.getElementById("restore_tabs_file");

document.getElementById("restore_tabs").onclick = function() {
  fileinput.click();
};

restoreTab.onValue(() => {
  let filelist = fileinput.files;
  var reader = new FileReader();

  function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
  }

  reader.onload = (function() { return function(e) {
    let restoredata = e.target.result.replace(/^[^,]*,/g, "");
github vokkim / tuktuk-chart-plotter / src / client / map.js View on Github external
function handleDrawPath({map, settings, drawObject}) {
  const pathMarker = Leaf.icon({
    iconUrl: 'path-marker.png',
    iconSize: [20, 20],
    iconAnchor: [10, 10]
  })
  let path = []
  let lastMoveAt = undefined
  const del = drawObject.view(L.prop('del'))
  const pathPolyline = Leaf.polyline([], {color: '#3e3e86', weight: 5})
  pathPolyline.addTo(map)

  Bacon.fromEvent(map, 'click')
    .filter(settings.map('.drawMode'))
    .filter(e => _.every(path, marker => e.latlng.distanceTo(marker._latlng) > 30))
    .filter(() => lastMoveAt === undefined || Date.now() - lastMoveAt > 50) // Do not add new marker if one was just dragged
    .map(e => {
      const {latlng} = e
      return Leaf.marker(latlng, {icon: pathMarker, draggable: true, zIndexOffset: 900})
    })
    .onValue(marker => {
      marker.addTo(map)
      path.push(marker)
      marker.on('move', redrawPathAndChangeDistance)
      redrawPathAndChangeDistance()
    })

  function redrawPathAndChangeDistance() {
    lastMoveAt = Date.now()
github viddo / atom-textual-velocity / lib / project.js View on Github external
_newChokidarEventStream (w, pathFilter, event) {
    const rootPath = w.options.cwd
    return Bacon
      .fromEvent(w, event, (relPath, stat) => {
        const path = Path.join(rootPath, relPath)
        if (pathFilter.isFileAccepted(path)) {
          return {
            path: path,
            rootPath: rootPath,
            relPath: relPath,
            stat: stat
          }
        }
      })
      .filter(R.is(Object))
  }
github miciek / web-snake-react-bacon / src / SnakeGame.js View on Github external
inputStreams() {
    const ticks = Bacon.interval(100);
    const keys = Bacon.fromEvent(document.body, "keyup").map(".keyCode");
    const lefts = keys.filter(key => key === 37);
    const rights = keys.filter(key => key === 39);
    return { ticks, lefts, rights };
  }
github viddo / atom-textual-velocity / lib / projects.js View on Github external
[removedItemsStream], (items, path) => items.filter(item => item.path !== path),
      [closeStream], (items, path) => items.filter(item => !item.path.startsWith(path))
    )

    this._queryTask = new Task(require.resolve('./query-task.js'))
    this._queryTask.start()
    this._unsubscribes.push(newItemsStream.onValue(item => this._queryTask.send({type: 'add', item: item})))
    this._unsubscribes.push(removedItemsStream.onValue(path => this._queryTask.send({tyquerpe: 'rm', path: path})))

    const queryStream = this.queryBus.map(R.trim).skipDuplicates()
    const emptyQueryStream = queryStream.filter(R.isEmpty)
    const queryProp = queryStream.toProperty('')
    this._unsubscribes.push(queryProp
      .filter(q => q !== '')
      .onValue(q => this._queryTask.send({type: 'query', query: q})))
    const queryResultsStream = Bacon.fromEvent(this._queryTask, 'results')

    this.itemsProp = Bacon.update(
      [],
      [queryResultsStream, allItemsProp], (_, results, allItems) => results.items.map(({id}) => allItems[id]),
      [emptyQueryStream, allItemsProp], R.nthArg(-1),
      [allItemsProp.changes(), queryProp], (items, allItems, q) => R.isEmpty(q) ? allItems : items
    )
  }
github viddo / atom-textual-velocity / lib / projects.js View on Github external
    const removedItemsStream = watchedPathTaskStream.flatMap(task => Bacon.fromEvent(task, 'unlink'))