Created
August 3, 2015 14:50
-
-
Save cefn/bfd5506c4122e640ba8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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