Skip to content

Commit

Permalink
Merge 992e55a into 5753f0e
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgig committed Apr 4, 2016
2 parents 5753f0e + 992e55a commit ed66510
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 5 additions & 4 deletions module/sampleon/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var flyd = require('../../lib');
var R = require('ramda');

module.exports = flyd.curryN(2, function(s1, s2) {
return flyd.combine(function() {
return s2();
}, [s1]);
module.exports = flyd.curryN(2, function(trigger, source) {
return flyd.combine(function(trigger, source, self, changed) {
if (R.contains(trigger, changed)) return source();
}, [trigger, source]);
});
13 changes: 12 additions & 1 deletion module/sampleon/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('sample On', function() {
s1(5)(3);
assert.deepEqual(result, [1, 1, 1, 6, 6]);
});
it('has not value until value flows on trigger stream', function() {
it('has no value until value flows on trigger stream', function() {
var result = [];
var s1 = stream();
var s2 = stream(1);
Expand All @@ -33,4 +33,15 @@ describe('sample On', function() {
s1(5)(3);
assert.deepEqual(result, [1, 1, 1, 6, 6]);
});
it('does not update until both trigger stream and source stream have been updated', function() {
var result = [];
var trigger = stream();
var source = flyd.combine(function(s1) {return s1();}, [trigger]);
var sampled = sampleOn(trigger, source);
flyd.map(function(v) {
result.push(v);
}, sampled);
trigger(0);
assert.deepEqual(result, [0]);
});
});

0 comments on commit ed66510

Please sign in to comment.