How to use the baconjs.fromPromise 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 CleverCloud / clever-tools / src / models / log.js View on Github external
function getOldLogs (appId, beforeDate, afterDate, filter, deployment_id) {

  const limit = (beforeDate == null && afterDate == null) ? 300 : null;
  const before = (beforeDate != null) ? beforeDate.toISOString() : null;
  const after = (afterDate != null) ? afterDate.toISOString() : null;

  const logsProm = fetchOldLogs({ appId, limit, before, after, filter, deployment_id }).then(sendToApi);

  return Bacon.fromPromise(logsProm)
    .flatMapLatest((logs) => Bacon.fromArray(logs.reverse()));
};
github CleverCloud / clever-tools / src / models / log.js View on Github external
function getNewLogs (appId, before, after, filter, deploymentId) {
  Logger.println('Waiting for application logs…');
  Logger.debug('Opening a websocket in order to fetch logs…');
  return Bacon
    .fromPromise(getHostAndTokens())
    .flatMapLatest(({ apiHost, tokens }) => {
      return Bacon.fromBinder((sink) => {
        const logsStream = new LogsStream({ apiHost, tokens, appId, filter, deploymentId });
        return logsStream.openResilientStream({
          onMessage: sink,
          onError: (error) => sink(new Bacon.Error(error)),
          infinite: false,
          retryDelay: 2000,
          retryTimeout: 30000,
        });
      });
    })
    .filter((line) => {
      const lineDate = Date.parse(line._source['@timestamp']);
      const isBefore = !before || lineDate < before.getTime();
github rbelouin / fip.rbelouin.com / src / js / models / http.js View on Github external
export function send(fetch, { url, method, headers, body }) {
  const s_res = Bacon.fromPromise(
    fetch(url, {
      method,
      headers: Map.prototype.isPrototypeOf(headers)
        ? _.zipObject(Array.from(headers.entries()))
        : headers || {},
      body
    })
  );

  const s_body = s_res.flatMapLatest(parseResponse);

  return s_body.toProperty();
}
github CleverCloud / clever-tools / src / models / git.js View on Github external
function resolveFullCommitId (commitId) {
  if (commitId == null) {
    return Bacon.constant(null);
  }
  const fullCommitIdPromise = getRepo()
    .then((repo) => git.expandOid({ ...repo, oid: commitId }));
  return Bacon.fromPromise(fullCommitIdPromise)
    .flatMapError((e) => {
      if (e.code === 'ShortOidNotFound') {
        return new Bacon.Error(`Commit id ${commitId} is ambiguous`);
      }
      return e;
    });
}
github jamesmacaulay / kozu / lib / kozu / cells.js View on Github external
var streamWithResolvedPromises = rawValues.flatMap(function(x) {
      if (p.isThenable(x)) {
        return Bacon.fromPromise(x);
      } else {
        return x;
      }
    });
    var stream = this.stream = streamWithResolvedPromises.skipDuplicates().withHandler(function(event) {
github CleverCloud / clever-tools / src / models / organisation.js View on Github external
function getByName (api, name) {
  return Bacon.fromPromise(getByNameProm(name));
}
github lhahne / trains / stores / StationMetadataStore.js View on Github external
'use strict'

var Bacon = require('baconjs')
var _     = require('lodash')

require('es6-promise').polyfill()
require('isomorphic-fetch')

var LiveDataActions = require('../actions/LiveDataActions.js')

var METADATA_URL = 'http://rata.digitraffic.fi/api/v1/metadata/station'

var stations = Bacon.fromPromise(fetch(METADATA_URL))
  .flatMap(response => Bacon.fromPromise(response.json()))
  .toProperty()

var stationsByCode = stations.map(stations =>
  _(stations)
    .map(station => {
      station.stationName = station.stationName.replace(' asema', '')
      return station
    })
    .indexBy('stationShortCode')
    .value()
)

var metadataForStation =
  Bacon.zipAsArray(stationsByCode, LiveDataActions.station)
  .map(params => {
github CleverCloud / clever-tools / src / open-browser.js View on Github external
function openPage (url) {
  Logger.debug('Opening browser');
  return Bacon.fromPromise(open(url, { wait: false }));
}
github vokkim / tuktuk-chart-plotter / src / client / api.js View on Github external
function get({url}) {
  const request = fetch(url, {credentials: 'include'})
    .then(checkStatus)
    .then(parseJSON)
  return Bacon.fromPromise(request)
}
github staltz / flux-challenge / submissions / milankinen / app.js View on Github external
function httpGet(url) {
  const abortOnUnsubscribe = true
  return Bacon.fromPromise(http({url, method: "get", crossOrigin: true, type: "json"}), abortOnUnsubscribe)
}