How to use the baconjs.fromArray 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
.flatMap((t: {file: FileType, fileReaders: Array}) => {
          const {filename, stats: fileStats} = t.file

          let fileReaders = t.fileReaders
          if (notes) {
            const note = notes[filename]
            if (note && note.stats.mtime.getTime() === fileStats.mtime.getTime()) {
              fileReaders = fileReaders.filter(fileReader => note[fileReader.notePropName] === undefined)
            }
            if (fileReaders.length === 0) return Bacon.never() // e.g. a cached note that have all read values already
          }

          return Bacon
            .fromArray(fileReaders)
            .flatMap((fileReader: FileReaderType) => {
              const readResult: FileReaderResultType = {
                filename: filename,
                notePropName: fileReader.notePropName,
                value: null
              }
              return Bacon
                .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
github sighjs / sigh / test / src / plugin / debounce.spec.js View on Github external
it('debounces two streams', () => {
    var streams = Bacon.fromArray([ 1, 2 ].map(idx => [ makeEvent(idx) ]))
    var compiler = new PipelineCompiler
    var opData = { compiler }

    return compiler.compile([
      op => streams,
      plugin(debounce, 100)
    ])
    .then(streams => streams.toPromise(Promise))
    .then(events => {
      events = events.sort()
      events[0].path.should.equal('file1.js')
      events.length.should.equal(2)
      events[1].path.should.equal('file2.js')
    })
  })
})
github rbelouin / fip.rbelouin.com / test / unit / models / fip.spec.js View on Github external
function connectForever(_url) {
    expect(_url).toStrictEqual(url);

    return Bacon.fromArray([
      {
        radio1: {
          type: "song",
          song: {
            id: "song1-1",
            startTime: 100
          }
        },
        radio2: {
          type: "song",
          song: {
            id: "song2-1",
            startTime: 110
          }
        },
        radio3: {
github mostjs / core / test / perf / scan.js View on Github external
.add('bacon', function(deferred) {
    runners.runBacon(deferred, bacon.fromArray(a).scan(0, sum).reduce(0, passthrough));
  }, options)
  .add('highland', function(deferred) {
github heikkipora / registry-sync / index.js View on Github external
if (binaryExists(distribution)) {
               return Bacon.once('Already downloaded ' + distribution.name + '@' + distribution.version)
             }
             return fetchBinary(distribution.dist)
                      .doAction(function(data) {
                        if (sha1(data) != distribution.dist.shasum) {
                          throw new Error('SHA checksum of ' + distribution.name + '@' + distribution.version + ' does not match')
                        }
                        fs.writeFileSync(packageBinaryFilePath(distribution.name, distribution.version), data)
                      })
                      .map('Downloaded ' + distribution.name + '@' + distribution.version)
           })
}

var dependencies = dependenciesToArray(require(rootPackage).dependencies)
var downloaded = Bacon.fromArray(dependencies)
     .flatMap(resolveVersionAndDependencies)
     .mapEnd(collectedPackagesAsArray)
     .flatMap(Bacon.fromArray)
     .flatMapWithConcurrencyLimit(5, downloadPackage)

downloaded.log()

downloaded.onError(function(err) {
  throw new Error(err)
})
github vokkim / tuktuk-chart-plotter / src / client / settings.js View on Github external
ais: {
    enabled: false
  },
  worldBaseChart: true,
  chartProviders: [],
  loadingChartProviders: true,
  data: [],
  instruments: _.keys(InstrumentConfig)
}

const fromLocalStorage = Store.get(LOCAL_STORAGE_KEY) || {}

const charts = _.get(window.INITIAL_SETTINGS, 'charts', [])
const settings = Atom(_.assign(defaultSettings, _.omit(window.INITIAL_SETTINGS, ['charts']) || {}, fromLocalStorage))

const chartProviders = Bacon.fromArray(charts)
  .flatMap(provider => {
    switch (provider.type) {
      case 'local':
        return fetchLocalCharts(provider, fromLocalStorage.hiddenChartProviders)
      case 'signalk':
        return fetchSignalKCharts(provider, fromLocalStorage.hiddenChartProviders)
      default:
        return Bacon.once(provider)
    }
  })
  .fold([], _.concat)

chartProviders.onValue(charts => {
  settings.view(L.prop('chartProviders')).set(charts)
  settings.view(L.prop('loadingChartProviders')).set(false)
})
github staltz / callbag-basics / perf / dataflow.js View on Github external
.add('bacon', function (deferred) {
    var source = bacon.fromArray(a);
    var inc = source.filter(isPositive).map(returnPlus1);
    var dec = source.filter(isNegative).map(returnMinus1);
    var count = inc.merge(dec).scan(0, addXY);
    var label = bacon.fromArray(['initial', 'Count is ']);
    var view = bacon.combineWith(renderWithArgs, label, count);
    runners.runBacon(deferred, view);
  }, options)
github vokkim / tuktuk-chart-plotter / src / client / settings.js View on Github external
.flatMap(charts => {
      return Bacon.fromArray(
        _.map(charts, chart => {
          const from = _.pick(chart, [
            'tilemapUrl',
            'index',
            'type',
            'name',
            'minzoom',
            'maxzoom',
            'center',
            'description',
            'format',
            'bounds'
          ])
          return _.merge(
            {
              id: chart.name,
github staltz / callbag-basics / perf / filter-map-fusion.js View on Github external
.add('bacon', function(deferred) {
    runners.runBacon(deferred, bacon.fromArray(a).map(add1).filter(odd).map(add1).map(add1).filter(even).reduce(0, sum));
  }, options)
  .add('highland', function(deferred) {
github heikkipora / registry-sync / index.js View on Github external
.flatMap(function(packageAndDependencies) {
           if (collectPackage(packageAndDependencies)) {
             return Bacon.fromArray(packageAndDependencies.dependencies)
                         .flatMapConcat(resolveVersionAndDependencies)
           }
           return Bacon.never()
         })
}