How to use the kefir.combine function in kefir

To help you get started, we’ve selected a few kefir 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 DefinitelyTyped / DefinitelyTyped / types / kefir / kefir-tests.ts View on Github external
type Second = 'second';
	let observable32: Stream = Kefir.sequentially(100, ['first', 'second']).filter((value): value is First => value === 'first');
}

// Combine observables
{
	{
		let a: Stream = Kefir.sequentially(100, [1, 3]);
		let b: Stream = Kefir.sequentially(100, [2, 4]).delay(40);
		let observable01: Observable = Kefir.combine([a, b], (a, b) => a + b);
	}
	{
		let a: Stream = Kefir.sequentially(100, [1, 3]);
		let b: Stream = Kefir.sequentially(100, [2, 4]).delay(40);
		let c: Stream = Kefir.sequentially(60, [5, 6, 7]);
		let observable02: Observable = Kefir.combine([a, b], [c], (a, b, c) => a + b + c);
	}
	{
		let a: Stream = Kefir.sequentially(100, [0, 1, 2, 3]);
		let b: Stream = Kefir.sequentially(160, [4, 5, 6]);
		let c: Property = Kefir.sequentially(100, [8, 9]).delay(260).toProperty(() => 7);
		let observable03: Observable = Kefir.zip([a, b, c]);
	}
	{
		let a: Stream = Kefir.sequentially(100, [0, 1, 2]);
		let b: Stream = Kefir.sequentially(100, [0, 1, 2]).delay(30);
		let c: Stream = Kefir.sequentially(100, [0, 1, 2]).delay(60);
		let abc: Observable = Kefir.merge([a, b, c]);
	}
	{
		let a: Stream = Kefir.sequentially(100, [0, 1, 2]);
		let b: Stream = Kefir.sequentially(100, [3, 4, 5]);
github irskep / summertunes / client / src / model / uiModel.js View on Github external
const [setMediumUIConfig, kMediumUIConfig] = createBusProperty(localStorageJSON("uiMediumUIConfig", 'A'));
const [setSmallUIConfig, kSmallUIConfig] = createBusProperty(localStorageJSON("uiSmallUIConfig", 'Artist'));

const kUIConfigSetter = K.combine([kIsLargeUI, kIsMediumUI], (isLargeUI, isMediumUI) => {
  if (isLargeUI) return setLargeUIConfig;
  if (isMediumUI) return setMediumUIConfig;
  return setSmallUIConfig;
}).toProperty(() => setLargeUIConfig);

const kUIConfigOptions = K.combine([kIsLargeUI, kIsMediumUI], (isLargeUI, isMediumUI) => {
  if (isLargeUI) return largeUIOptions;
  if (isMediumUI) return mediumUIOptions;
  return smallUIOptions;
}).toProperty(() => largeUIOptions);

const kUIConfig = K.combine([kIsLargeUI, kIsMediumUI])
  .flatMapLatest(([isLargeUI, isMediumUI]) => {
    if (isLargeUI) return kLargeUIConfig;
    if (isMediumUI) return kMediumUIConfig;
    return kSmallUIConfig;
  }).toProperty(() => largeUIOptions.B);

/* local storage sync */

kLargeUIConfig.onValue((v) => localStorage.uiLargeUIConfig = JSON.stringify(v));
kMediumUIConfig.onValue((v) => localStorage.uiMediumUIConfig = JSON.stringify(v));
kSmallUIConfig.onValue((v) => localStorage.uiSmallUIConfig = JSON.stringify(v));

export {
  kIsInfoModalOpen,
  kInfoModalTrack,
  openInfoModal,
github researchspace / researchspace / researchspace / web / src / main / components / search / facet / FacetStore.ts View on Github external
let selectedRelations = selected;
        // we need to remove old selected value if it is date-range or numeric-range
        // because there can be only one range selected for a given relation
        if (relationType === SearchModel.TemporalDisjunctKinds.DateRange
            || relationType === SearchModel.NumericRangeDisjunctKind
           ) {
          selectedRelations = selected.delete(value.relation);
        }
        let selectedValues = selectedRelations.get(value.relation) || List();
        selectedValues = selectedValues.push(value.value);
        this.selectedValues(selectedRelations.set(value.relation, selectedValues));
      }
    );

    // update list of selected facet values on the de-selection of some facet value
    Kefir.combine(
      {value: this.deselectValueAction.$property},
      {selected: this.selectedValues.$property}
    ).onValue(
      ({value, selected}) => {
        const selectedValues =
          selected.get(value.relation).filterNot(
            selectedValue => F.partialValueEquals(value.value, selectedValue)
          ) as List;
        this.selectedValues(selected.set(value.relation, selectedValues));
      }
    );

    // update facet AST when list of selected values changes
    this.selectedValues.$property.map(this.buldAst).onValue(this.ast);

    // update faceted query when AST changes
github irskep / summertunes / client / src / model / mpvPlayer.js View on Github external
.flatMapLatest((count) => {
        const missing = {};
        const numbers = [];
        for (let i = 0; i < count; i++) {
          numbers.push(i);
          missing[i] = true;
          this.getProperty(`playlist/${i}/filename`);
          const j = i;
          setTimeout(() => {
            if (missing[j]) {
              console.warn("Re-fetching missing playlist filename", j);
              this.getProperty(`playlist/${j}/filename`);
            }
          }, 500);
        }
        return K.combine(numbers.map((i) => {
          return this.kPropertyChanges
            .filter(({name}) => name === `playlist/${i}/filename`)
            .take(1)
            .map(({data}) => {
              delete missing[i];
              return data;
            })
        }));
      }).toProperty(() => []));
github irskep / summertunes / client / src / model / playerModel.js View on Github external
}).toProperty(() => null);
};


const kVolume = forwardPlayerProperty('kVolume');
const kIsPlaying = forwardPlayerProperty('kIsPlaying');
const kPlaybackSeconds = forwardPlayerProperty('kPlaybackSeconds');
const kPath = forwardPlayerProperty('kPath');
const kPlaylistCount = forwardPlayerProperty('kPlaylistCount');
const kPlaylistIndex = forwardPlayerProperty('kPlaylistIndex');
const kPlaylistPaths = forwardPlayerProperty('kPlaylistPaths');

const kPlayingTrack = createKPathToTrack(kPath);

const kPlaylistTracks = keepAlive(
  K.combine([kBeetsWebURL, kPlaylistPaths])
    .flatMapLatest(([url, paths]) => {
      if (!paths) return K.once([]);
      return K.combine(paths.map(createURLToKTrack.bind(this, url)));
    })
    .toProperty(() => []));


const kLastFM = K.combine([kPlayingTrack, kLastFMAPIKey])
  .flatMapLatest(([track, lastFMAPIKey]) => {
    if (!track || !lastFMAPIKey) return K.constant(null);
    return K.fromPromise(window.fetch(
          `http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=${
            lastFMAPIKey
          }&artist=${
            track.artist
          }&album=${
github irskep / summertunes / client / src / model / browsingModel.js View on Github external
.merge(kURLDataChanges.map(keyMapper('album')))
  .skipDuplicates()
  .toProperty(() => getURLData()['album'])
keepAlive(kAlbum);

function getTrackList(beetsWebURL, album_id, albumartist) {
  if (!album_id && !albumartist) return new Promise((resolve, reject) => {
    resolve([]);
  });
  const url = `${beetsWebURL}/item/query/${albumQueryString({albumartist, album_id})}`;
  return window.fetch(url)
    .then((response) => response.json())
    .then(({results}) => results)
}

const kTrackList = K.combine([kBeetsWebURL, kArtist, kAlbum])
  .flatMapLatest(([beetsWebURL, artist, album]) => {
    return K.fromPromise(getTrackList(beetsWebURL, album, artist));
  })
  .toProperty(() => []);

const [setTrackIndex, bTrackIndex] = createBus()
const kTrackIndex = bTrackIndex
  .merge(kTrackList.changes().map(() => null))
  .toProperty(() => null);
keepAlive(kTrackIndex);

const kTrack = K.combine([kTrackList, kTrackIndex], (trackList, trackIndex) => {
  if (trackIndex === null) return null;
  if (trackList.length < 1) return null;
  if (trackIndex >= trackList.length) return null;
  return trackList[trackIndex];
github calmm-js / karet.util / dist / karet.util.cjs.js View on Github external
function show(_) {
  var n = arguments.length - 1;
  var xs = Array(n);
  for (var i = 0; i < n; ++i) {
    xs[i] = arguments[i];
  }var iso = F.combine(xs, showIso);
  var s = arguments[n];
  return isStream(s) ? isProperty(iso) ? K.combine([iso, s], L.get) : mapValue(L.get(iso), s) : view(iso, s);
}
github researchspace / researchspace / researchspace / web / src / main / components / arguments / AssertionsStore.ts View on Github external
return (assertion: Assertion) => {
    const assertionIri = assertion.iri.getOrElse(
      Rdf.iri(`${assertion.field.iri}/assertion/${uuid.v4()}`)
    );
    return Kefir.combine(
      _.map(assertion.beliefs, getBeliefGraphs)
    ).map<[Rdf.PointedGraph, Array]>(
      beliefGraphs => {
        const allBeliefs = _.flatten(beliefGraphs);
        return [
          evaluateAssertion(context, assertionIri)(assertion, allBeliefs),
          _.map(allBeliefs, b => b.pointer)
        ];
      }
    ).flatMap(
      ([assertionPg, bs]) => {
        const service = new LdpService(rso.AssertionsContainer.value);
        if (assertion.iri.isJust) {
          return service.update(assertion.iri.get(), assertionPg.graph).map(
            _ => ({assertion: assertion.iri.get(), beliefs: bs})
          );
github researchspace / researchspace / metaphacts-platform / web / src / main / components / admin / namespace-manager / NamespaceManager.tsx View on Github external
componentDidMount() {
    this.cancellation.map(
      Kefir.combine({
        data: NamespaceService.getNamespaceRecords(),
        appStatus: ConfigService.getStorageStatus(),
      })
    ).observe({
      value: ({data, appStatus}) => {
        const selectedAppId = chooseDefaultTargetApp(appStatus);
        this.setState({isLoading: false, data, appStatus, selectedAppId});
      },
      error: loadingError => this.setState({isLoading: false, loadingError}),
    });
  }
github researchspace / researchspace / researchspace / web / src / main / components / arguments / ArgumentsStore.ts View on Github external
Inference: inference =>
      Kefir.combine(
        inference.premises.map(getBeliefGraphs)
      ).map(x => _.flatten(x)).toProperty(),
    BeliefAdoption: beliefAdoption => getBeliefGraphs(beliefAdoption.belief),

kefir

Reactive Programming library for JavaScript inspired by Bacon.js and RxJS with focus on high performance and low memory usage

MIT
Latest version published 4 years ago

Package Health Score

57 / 100
Full package analysis