Skip to content

Instantly share code, notes, and snippets.

@cefn
Created August 3, 2015 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cefn/bfd5506c4122e640ba8f to your computer and use it in GitHub Desktop.
Save cefn/bfd5506c4122e640ba8f to your computer and use it in GitHub Desktop.
"use strict";
var Kefir = require("kefir"),
events = require('events');
var empty = void(0);
var localEmitter = new events.EventEmitter(); //used to notify local updates to values against new or old topics
var remoteEmitter = new events.EventEmitter(); //used to notify local updates to values against new or old topics
var localProperty = Kefir.fromEvents(localEmitter, "Hello").toProperty();
var remoteProperty = Kefir.concat(Kefir.constant(empty), Kefir.fromEvents(remoteEmitter, "Hello")).toProperty();
var sampleProperty = remoteProperty.sampledBy(localProperty, function(remote, local){
return [remote, local];
});
localProperty.log("Local");
remoteProperty.log("Remote");
sampleProperty.log("Sampled");
localEmitter.emit("Hello", "World");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment