Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kefir

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kefir - npm Package Compare versions

Comparing version 0.1.10 to 0.1.11

src/buffer.js

10

bacon-api-impl-status.md

@@ -34,7 +34,7 @@ # Bacon.js API implementation status

| `Bacon.never()` | :rocket: | `Kefir.never()` |
| `Bacon.later(delay, value)` | :broken_heart: | |
| `Bacon.later(delay, value)` | :rocket: | `Kefir.later(delay, value)` |
| `new Bacon.EventStream(subscribe)` | :broken_heart: | |
| `property.changes()` | :rocket: | `property.changes()` |
| `property.toEventStream()` | :broken_heart: | |
| `new Bacon.Bus()` | :rocket: | `new Kefir.Bus()` / `Kefir.bus()` |
| `new Bacon.Bus()` | :rocket: | `Kefir.bus()` |
| `Bacon.fromBinder(subscribe)` | :rocket: | `Kefir.fromBinder(subscribe)` |

@@ -63,4 +63,4 @@

| `observable.skip(n)` | :rocket: | `observable.skip(n)` |
| `observable.delay(delay)` | :broken_heart: | |
| `observable.throttle(delay)` | :broken_heart: | |
| `observable.delay(delay)` | :rocket: | `observable.delay(delay)` |
| `observable.throttle(delay)` | :rocket: | `observable.throttle(delay)` |
| `observable.debounce(delay)` | :broken_heart: | |

@@ -147,3 +147,3 @@ | `observable.debounceImmediate(delay)` | :broken_heart: | |

| `Bacon.zipWith(f, stream1, stream1...)` | :broken_heart: | |
| `Bacon.onValues(a, b [, c...], f)` | :rocket: | Kefir.onValues(observables, f) |
| `Bacon.onValues(a, b [, c...], f)` | :rocket: | `Kefir.onValues(observables, f)` |

@@ -150,0 +150,0 @@

{
"name": "kefir",
"version": "0.1.10",
"version": "0.1.11",
"homepage": "https://github.com/pozadi/kefir",

@@ -5,0 +5,0 @@ "authors": [

@@ -1,2 +0,2 @@

/*! kefir - 0.1.10
/*! kefir - 0.1.11
* https://github.com/pozadi/kefir

@@ -80,2 +80,15 @@ */

function getFn(fn, context) {
if (isFn(fn)) {
return fn;
} else {
/*jshint eqnull:true */
if (context == null || !isFn(context[fn])) {
throw new Error('not a function: ' + fn + ' in ' + context);
} else {
return context[fn];
}
}
}
function callFn(fnMeta, moreArgs){

@@ -95,9 +108,5 @@ // fnMeta = [

} else {
fn = fnMeta[0];
context = fnMeta[1];
fn = getFn(fnMeta[0], context);
args = restArgs(fnMeta, 2, true);
/*jshint eqnull:true */
if (!isFn(fn) && context != null) {
fn = context[fn];
}
}

@@ -111,7 +120,3 @@ if (moreArgs){

}
if (isFn(fn)) {
return args ? fn.apply(context, args) : fn.call(context);
} else {
throw new Error('not a function ' + fn);
}
return args ? fn.apply(context, args) : fn.call(context);
}

@@ -173,3 +178,13 @@

var now = Date.now ?
function() { return Date.now() } :
function() { return new Date().getTime() };
function get(map, key, notFound){
if (map && key in map) {
return map[key];
} else {
return notFound;
}
}

@@ -442,6 +457,7 @@ var Kefir = {};

// Kefir.fromArray(values)
// Kefir.fromCallback(fn)
// Never
// Kefir.never()

@@ -458,3 +474,3 @@ var neverObj = new Stream();

// Once
// Kefir.once(x)

@@ -489,7 +505,7 @@ Kefir.OnceStream = function OnceStream(value){

// fromBinder
// Kefir.fromBinder(fn)
Kefir.FromBinderStream = function FromBinderStream(subscribe){
Kefir.FromBinderStream = function FromBinderStream(subscribeFnMeta){
Stream.call(this);
this.__subscribe = subscribe;
this.__subscribeFnMeta = normFnMeta(subscribeFnMeta);
}

@@ -502,5 +518,5 @@

var _this = this;
this.__usubscriber = this.__subscribe(function(x){
this.__usubscriber = callFn(this.__subscribeFnMeta, [function(x){
_this.__sendAny(x);
});
}]);
},

@@ -515,3 +531,3 @@ __onLastOut: function(){

Stream.prototype.__clear.call(this);
this.__subscribe = null;
this.__subscribeFnMeta = null;
}

@@ -521,4 +537,4 @@

Kefir.fromBinder = function(subscribe){
return new Kefir.FromBinderStream(subscribe);
Kefir.fromBinder = function(/*subscribe[, context[, arg1, arg2...]]*/){
return new Kefir.FromBinderStream(arguments);
}

@@ -823,3 +839,3 @@

// .skipWhile(f)
// .skipWhile(fn)

@@ -839,8 +855,2 @@ var skipWhileMapFn = function(x){

// TODO

@@ -851,2 +861,5 @@ //

// observable.skipWhile(property)
//
// observable.awaiting(otherObservable)
// stream.skipUntil(stream2)

@@ -865,6 +878,9 @@

}
WithSourceStreamMixin.__Constructor.call(this, sampler);
this.__lastValue = NOTHING;
this.__fnMeta = normFnMeta(fnMeta);
this.__mainStream = main;
this.__lastValue = NOTHING;
if (main instanceof Property && main.hasValue()) {
this.__lastValue = main.getValue();
}
WithSourceStreamMixin.__Constructor.call(this, sampler);
},

@@ -1018,3 +1034,3 @@ __handle: function(y){

// Bus
// Kefir.bus()

@@ -1066,3 +1082,3 @@ Kefir.Bus = function Bus(){

// FlatMap
// .flatMap()

@@ -1121,3 +1137,3 @@ Kefir.FlatMappedStream = function FlatMappedStream(sourceStream, mapFnMeta){

// FlatMapLatest
// .flatMapLatest()

@@ -1148,3 +1164,3 @@ Kefir.FlatMapLatestStream = function FlatMapLatestStream(){

// Merge
// .merge()

@@ -1193,3 +1209,3 @@ Kefir.MergedStream = function MergedStream(){

// Combine
// .combine()

@@ -1266,4 +1282,235 @@ Kefir.CombinedStream = function CombinedStream(sources, mapFnMeta){

// FromPoll
// TODO
//
// observable.debounce(wait, immediate)
// http://underscorejs.org/#defer
// Kefir.later()
Kefir.LaterStream = function LaterStream(wait, value) {
Stream.call(this);
this.__value = value;
this.__wait = wait;
}
inherit(Kefir.LaterStream, Stream, {
__ClassName: 'LaterStream',
__onFirstIn: function(){
var _this = this;
setTimeout(function(){
_this.__sendAny(_this.__value);
_this.__sendEnd();
}, this.__wait);
},
__clear: function(){
Stream.prototype.__clear.call(this);
this.__value = null;
this.__wait = null;
}
});
Kefir.later = function(wait, value) {
return new Kefir.LaterStream(wait, value);
}
// .delay()
var DelayedMixin = {
__Constructor: function(source, wait) {
this.__source = source;
this.__wait = wait;
source.onEnd(this.__sendEndLater, this);
},
__sendLater: function(x){
var _this = this;
setTimeout(function(){ _this.__sendValue(x) }, this.__wait);
},
__sendEndLater: function(){
var _this = this;
setTimeout(function(){ _this.__sendEnd() }, this.__wait);
},
__onFirstIn: function(){
this.__source.onNewValue('__sendLater', this);
this.__source.onError('__sendError', this);
},
__onLastOut: function(){
this.__source.offValue('__sendLater', this);
this.__source.offError('__sendError', this);
},
__clear: function(){
Observable.prototype.__clear.call(this);
this.__source = null;
this.__wait = null;
}
}
Kefir.DelayedStream = function DelayedStream(source, wait) {
Stream.call(this);
DelayedMixin.__Constructor.call(this, source, wait);
}
inherit(Kefir.DelayedStream, Stream, DelayedMixin, {
__ClassName: 'DelayedStream'
});
Stream.prototype.delay = function(wait) {
return new Kefir.DelayedStream(this, wait);
}
Kefir.DelayedProperty = function DelayedProperty(source, wait) {
Property.call(this);
DelayedMixin.__Constructor.call(this, source, wait);
if (source.hasValue()) {
this.__sendValue(source.getValue());
}
}
inherit(Kefir.DelayedProperty, Property, DelayedMixin, {
__ClassName: 'DelayedProperty'
});
Property.prototype.delay = function(wait) {
return new Kefir.DelayedProperty(this, wait);
}
// .throttle(wait, {leading, trailing})
var ThrottledMixin = {
__Constructor: function(source, wait, options){
this.__source = source;
this.__wait = wait;
this.__trailingCallValue = null;
this.__trailingCallTimeoutId = null;
this.__endAfterTrailingCall = false;
this.__lastCallTime = 0;
this.__leading = get(options, 'leading', true);
this.__trailing = get(options, 'trailing', true);
var _this = this;
this.__makeTrailingCallBinded = function(){ _this.__makeTrailingCall() };
source.onEnd(this.__sendEndLater, this);
},
__sendEndLater: function(){
if (this.__trailingCallTimeoutId) {
this.__endAfterTrailingCall = true;
} else {
this.__sendEnd();
}
},
__scheduleTralingCall: function(value, wait){
if (this.__trailingCallTimeoutId) {
this.__cancelTralingCall();
}
this.__trailingCallValue = value;
this.__trailingCallTimeoutId = setTimeout(this.__makeTrailingCallBinded, wait);
},
__cancelTralingCall: function(){
if (this.__trailingCallTimeoutId !== null) {
clearTimeout(this.__trailingCallTimeoutId);
this.__trailingCallTimeoutId = null;
}
},
__makeTrailingCall: function(){
this.__sendValue(this.__trailingCallValue);
this.__trailingCallTimeoutId = null;
this.__trailingCallValue = null;
this.__lastCallTime = !this.__leading ? 0 : now();
if (this.__endAfterTrailingCall) {
this.__sendEnd();
}
},
__handleValueFromSource: function(x){
var curTime = now();
if (this.__lastCallTime === 0 && !this.__leading) {
this.__lastCallTime = curTime;
}
var remaining = this.__wait - (curTime - this.__lastCallTime);
if (remaining <= 0) {
this.__cancelTralingCall();
this.__lastCallTime = curTime;
this.__sendValue(x);
} else if (this.__trailing) {
this.__scheduleTralingCall(x, remaining);
}
},
__onFirstIn: function(){
this.__source.onNewValue('__handleValueFromSource', this);
this.__source.onError('__sendError', this);
},
__onLastOut: function(){
this.__source.offValue('__handleValueFromSource', this);
this.__source.offError('__sendError', this);
},
__clear: function(){
Observable.prototype.__clear.call(this);
this.__source = null;
this.__wait = null;
this.__trailingCallValue = null;
this.__trailingCallTimeoutId = null;
this.__makeTrailingCallBinded = null;
}
};
Kefir.ThrottledStream = function ThrottledStream() {
Stream.call(this);
ThrottledMixin.__Constructor.apply(this, arguments);
}
inherit(Kefir.ThrottledStream, Stream, ThrottledMixin, {
__ClassName: 'ThrottledStream'
});
Stream.prototype.throttle = function(wait, options) {
return new Kefir.ThrottledStream(this, wait, options);
}
Kefir.ThrottledProperty = function ThrottledProperty(source) {
Property.call(this);
ThrottledMixin.__Constructor.apply(this, arguments);
if (source.hasValue()) {
this.__sendValue(source.getValue());
}
}
inherit(Kefir.ThrottledProperty, Property, ThrottledMixin, {
__ClassName: 'ThrottledProperty'
});
Property.prototype.throttle = function(wait, options) {
return new Kefir.ThrottledProperty(this, wait, options);
}
// Kefir.fromPoll()
var FromPollStream = Kefir.FromPollStream = function FromPollStream(interval, sourceFnMeta){

@@ -1303,3 +1550,3 @@ Stream.call(this);

// Interval
// Kefir.interval()

@@ -1312,3 +1559,3 @@ Kefir.interval = function(interval, x){

// Sequentially
// Kefir.sequentially()

@@ -1331,3 +1578,3 @@ var sequentiallyHelperFn = function(){

// Repeatedly
// Kefir.repeatedly()

@@ -1345,11 +1592,28 @@ var repeatedlyHelperFn = function(){

//
// // more underscore-style maybe?
// observable.delay(delay)
// observable.throttle(delay)
// observable.debounce(delay)
// observable.debounceImmediate(delay)
// stream.bufferWithTime(delay)
// stream.bufferWithTime(f)
// stream.bufferWithCount(count)
// stream.bufferWithTimeOrCount(delay, count)
// TODO
//
// Kefir.later(delay, value)
// observable.mapError(f)
// observable.errors()
// observable.skipErrors()
// observable.endOnError(f)
// TODO
//
// observable.not()
// property.and(other)
// property.or(other)
//
// http://underscorejs.org/#pluck
// http://underscorejs.org/#invoke
// TODO
//
// Model = Bus + Property + lenses
if (typeof define === 'function' && define.amd) {

@@ -1356,0 +1620,0 @@ define([], function() {

@@ -1,4 +0,4 @@

/*! kefir - 0.1.10
/*! kefir - 0.1.11
* https://github.com/pozadi/kefir
*/
!function(a){"use strict";function b(){}function c(a){return a}function d(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function e(a){return p(a)?a:Array.prototype.slice.call(a)}function f(a){var b=function(){};return b.prototype=a,new b}function g(){if(1===arguments.length)return arguments[0];for(var a=arguments[0],b=1;b<arguments.length;b++)for(var c in arguments[b])d(arguments[b],c)&&(a[c]=arguments[b][c]);return a}function h(a,b){a.prototype=f(b.prototype),a.prototype.constructor=a;for(var c=2;c<arguments.length;c++)g(a.prototype,arguments[c]);return a}function i(a,b){for(var c in b)!d(b,c)||c in a||(a[c]=b[c]);return a}function j(a){return p(a[0])?a[0]:e(a)}function k(a,b,c){return a.length>b?Array.prototype.slice.call(a,b):c?null:[]}function l(a,b){var c,d,f;if(n(a)?(c=a,d=null,f=null):(c=a[0],d=a[1],f=k(a,2,!0),n(c)||null==d||(c=d[c])),b&&(f=f?f.concat(e(b)):b),n(c))return f?c.apply(d,f):c.call(d);throw new Error("not a function "+c)}function m(a){if(p(a)||r(a)){if(1===a.length)return a[0];if(0===a.length)return null}return a}function n(a){return"function"==typeof a}function o(a){return"undefined"==typeof a}function p(a){return"[object Array]"===Object.prototype.toString.call(a)}function q(a,b){if(null==a&&null==b)return!0;if(null==a||null==b)return!1;if(a.length!==b.length)return!1;for(var c=0;c<a.length;c++)if(a[c]!==b[c])return!1;return!0}var r=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};r(arguments)||(r=function(a){return!(!a||!d(a,"callee"))});var s={},t=s.NOTHING=["<nothing>"],u=s.END=["<end>"],v=s.NO_MORE=["<no more>"];s.BunchOfValues=function(a){this.values=a},s.bunch=function(){return new s.BunchOfValues(j(arguments))},s.Error=function(a){this.error=a},s.error=function(a){return new s.Error(a)};var w=s.Observable=function(a,b){n(a)&&(this.__onFirstIn=a),n(b)&&(this.__onLastOut=b),this.__subscribers=[]};h(w,Object,{__ClassName:"Observable",toString:function(){return"["+this.__ClassName+(this.__objName?" | "+this.__objName:"")+"]"},__onFirstIn:b,__onLastOut:b,__on:function(a){if(this.isEnded())"end"===a&&l(k(arguments,1));else{var b=("value"===a||"error"===a)&&!(this.__hasSubscribers("value")||this.__hasSubscribers("error"));this.__subscribers.push(arguments),b&&this.__onFirstIn()}},__off:function(a){if(!this.isEnded()){for(var b=0;b<this.__subscribers.length;b++)q(this.__subscribers[b],arguments)&&(this.__subscribers[b]=null);"value"!==a&&"error"!==a||this.__hasSubscribers("value")||this.__hasSubscribers("error")||this.__onLastOut()}},__send:function(a){if(!this.isEnded()){for(var b=0;b<this.__subscribers.length;b++){var c=this.__subscribers[b];if(c&&c[0]===a){var d=l(k(c,1),k(arguments,1));d===v&&this.__off.apply(this,c)}}"end"===a&&this.__clear()}},__hasSubscribers:function(a){if(this.isEnded())return!1;for(var b=0;b<this.__subscribers.length;b++)if(this.__subscribers[b]&&this.__subscribers[b][0]===a)return!0;return!1},__clear:function(){this.__onLastOut(),d(this,"__onFirstIn")&&(this.__onFirstIn=null),d(this,"__onLastOut")&&(this.__onLastOut=null),this.__subscribers=null},__sendValue:function(a){return this.__send("value",a),this},__sendError:function(a){return this.__send("error",a),this},__sendEnd:function(){return this.__send("end"),this},__sendAny:function(a){if(a===u)this.__sendEnd();else if(a instanceof s.BunchOfValues)for(var b=0;b<a.values.length;b++)this.__sendAny(a.values[b]);else a instanceof s.Error?this.__sendError(a.error):a!==t&&this.__sendValue(a);return this},onValue:function(){return this.__on.apply(this,["value"].concat(e(arguments))),this},offValue:function(){return this.__off.apply(this,["value"].concat(e(arguments))),this},onError:function(){return this.__on.apply(this,["error"].concat(e(arguments))),this},offError:function(){return this.__off.apply(this,["error"].concat(e(arguments))),this},onEnd:function(){return this.__on.apply(this,["end"].concat(e(arguments))),this},offEnd:function(){return this.__off.apply(this,["end"].concat(e(arguments))),this},onNewValue:function(){return this.onValue.apply(this,arguments)},isEnded:function(){return!this.__subscribers}});var x=s.Stream=function(){w.apply(this,arguments)};h(x,w,{__ClassName:"Stream"});var y=s.Property=function(a,b,c){w.call(this,a,b),this.__cached=o(c)?t:c};h(y,w,{__ClassName:"Property",hasValue:function(){return this.__cached!==t},getValue:function(){return this.__cached},__sendValue:function(a){this.isEnded()||(this.__cached=a),w.prototype.__sendValue.call(this,a)},onNewValue:function(){return this.__on.apply(this,["value"].concat(e(arguments))),this},onValue:function(){return this.hasValue()&&l(arguments,[this.__cached]),this.onNewValue.apply(this,arguments)}});var z=function(a,b,c){console.log(a,b,c)};w.prototype.log=function(a){return a||(a=this.toString()),this.onValue(z,null,a,"<value>"),this.onError(z,null,a,"<error>"),this.onEnd(z,null,a,"<end>"),this};var A=new x;A.__sendEnd(),A.__objName="Kefir.never()",s.never=function(){return A},s.OnceStream=function(a){x.call(this),this.__value=a},h(s.OnceStream,x,{__ClassName:"OnceStream",onValue:function(){return this.isEnded()||(l(arguments,[this.__value]),this.__value=null,this.__sendEnd()),this},onError:b}),s.once=function(a){return new s.OnceStream(a)},s.FromBinderStream=function(a){x.call(this),this.__subscribe=a},h(s.FromBinderStream,x,{__ClassName:"FromBinderStream",__onFirstIn:function(){var a=this;this.__usubscriber=this.__subscribe(function(b){a.__sendAny(b)})},__onLastOut:function(){n(this.__usubscriber)&&this.__usubscriber(),this.__usubscriber=null},__clear:function(){x.prototype.__clear.call(this),this.__subscribe=null}}),s.fromBinder=function(a){return new s.FromBinderStream(a)};var B={__Constructor:function(a){this.__source=a,a.onEnd(this.__sendEnd,this),a instanceof y&&this instanceof y&&a.hasValue()&&this.__handle(a.getValue())},__handle:function(a){this.__sendAny(a)},__onFirstIn:function(){this.__source.onNewValue("__handle",this),this.__source.onError("__sendError",this)},__onLastOut:function(){this.__source.offValue("__handle",this),this.__source.offError("__sendError",this)},__clear:function(){w.prototype.__clear.call(this),this.__source=null}};s.PropertyFromStream=function(a,b){y.call(this,null,null,b),this.__Constructor(a)},h(s.PropertyFromStream,y,B,{__ClassName:"PropertyFromStream"}),x.prototype.toProperty=function(a){return new s.PropertyFromStream(this,a)},y.prototype.toProperty=function(a){if(o(a))return this;var b=new s.PropertyFromStream(this);return b.__sendValue(a),b},s.ScanProperty=function(a,b,c){y.call(this,null,null,b),this.__fnMeta=m(c),this.__Constructor(a)},h(s.ScanProperty,y,B,{__ClassName:"ScanProperty",__handle:function(a){this.__sendValue(l(this.__fnMeta,[this.getValue(),a]))},__clear:function(){B.__clear.call(this),this.__fnMeta=null}}),w.prototype.scan=function(a){return new s.ScanProperty(this,a,k(arguments,1))},s.ReducedProperty=function(a,b,c){y.call(this),this.__fnMeta=m(c),this.__result=b,a.onEnd("__sendResult",this),this.__Constructor(a)},h(s.ReducedProperty,y,B,{__ClassName:"ReducedProperty",__handle:function(a){this.__result=l(this.__fnMeta,[this.__result,a])},__sendResult:function(){this.__sendValue(this.__result)},__clear:function(){B.__clear.call(this),this.__fnMeta=null,this.__result=null}}),w.prototype.reduce=function(a){return new s.ReducedProperty(this,a,k(arguments,1))};var C={__Constructor:function(a,b){this instanceof y?y.call(this):x.call(this),this.__mapFnMeta=m(b),B.__Constructor.call(this,a)},__handle:function(a){this.__sendAny(this.__mapFnMeta?l(this.__mapFnMeta,[a]):a)},__clear:function(){B.__clear.call(this),this.__mapFnMeta=null}};i(C,B),s.MappedStream=function(){this.__Constructor.apply(this,arguments)},h(s.MappedStream,x,C,{__ClassName:"MappedStream"}),s.MappedProperty=function(){this.__Constructor.apply(this,arguments)},h(s.MappedProperty,y,C,{__ClassName:"MappedProperty"}),x.prototype.map=function(){return new s.MappedStream(this,arguments)},y.prototype.map=function(){return new s.MappedProperty(this,arguments)},y.prototype.changes=function(){return new s.MappedStream(this)};var D=function(a){var b=l(this.fnMeta,[this.prev,a]);return this.prev=a,b};w.prototype.diff=function(a){return this.map(D,{prev:a,fnMeta:m(k(arguments,1))})};var E=function(a,b){return l(a,[b])?b:t};w.prototype.filter=function(){return this.map(E,null,m(arguments))};var F=function(a,b){return l(a,[b])?b:u};w.prototype.takeWhile=function(){return this.map(F,null,m(arguments))};var G=function(a){return this.n<=0?u:1===this.n?s.bunch(a,u):(this.n--,a)};w.prototype.take=function(a){return this.map(G,{n:a})};var H=function(a){return this.n<=0?a:(this.n--,t)};w.prototype.skip=function(a){return this.map(H,{n:a})};var I=function(a){var b;return b=this.prev!==t&&(this.fn?this.fn(this.prev,a):this.prev===a)?t:a,this.hasPrev=!0,this.prev=a,b};w.prototype.skipDuplicates=function(a){return this.map(I,{fn:a,prev:t})};var J=function(a){return this.skip&&l(this.fnMeta,[a])?t:(this.skip=!1,a)};w.prototype.skipWhile=function(){return this.map(J,{skip:!0,fnMeta:m(arguments)})};var K={__Constructor:function(a,b,c){this instanceof y?y.call(this):x.call(this),B.__Constructor.call(this,b),this.__lastValue=t,this.__fnMeta=m(c),this.__mainStream=a},__handle:function(a){if(this.__lastValue!==t){var b=this.__lastValue;this.__fnMeta&&(b=l(this.__fnMeta,[b,a])),this.__sendValue(b)}},__onFirstIn:function(){B.__onFirstIn.call(this),this.__mainStream.onValue("__saveValue",this),this.__mainStream.onError("__sendError",this)},__onLastOut:function(){B.__onLastOut.call(this),this.__mainStream.offValue("__saveValue",this),this.__mainStream.offError("__sendError",this)},__saveValue:function(a){this.__lastValue=a},__clear:function(){B.__clear.call(this),this.__lastValue=null,this.__fn=null,this.__mainStream=null}};i(K,B),s.SampledByStream=function(){this.__Constructor.apply(this,arguments)},h(s.SampledByStream,x,K,{__ClassName:"SampledByStream"}),s.SampledByProperty=function(){this.__Constructor.apply(this,arguments)},h(s.SampledByProperty,y,K,{__ClassName:"SampledByProperty"}),w.prototype.sampledBy=function(a){return a instanceof x?new s.SampledByStream(this,a,k(arguments,1)):new s.SampledByProperty(this,a,k(arguments,1))};var L={__initPluggable:function(){this.__plugged=[]},__clearPluggable:function(){this.__plugged=null},__handlePlugged:function(a,b){this.__sendAny(b)},__plug:function(a){if(!this.isEnded()){this.__plugged.push(a);var b=this.__plugged.length-1;this.__hasSubscribers("value")&&(a.onValue("__handlePlugged",this,b),a.onError("__sendError",this)),a.onEnd("__unplugById",this,b)}},__unplugById:function(a){if(!this.isEnded()){var b=this.__plugged[a];b&&(this.__plugged[a]=null,b.offValue("__handlePlugged",this,a),b.offError("__sendError",this),b.offEnd("__unplugById",this,a))}},__unplug:function(a){if(!this.isEnded())for(var b=0;b<this.__plugged.length;b++)this.__plugged[b]===a&&this.__unplugById(b)},__onFirstIn:function(){for(var a=0;a<this.__plugged.length;a++){var b=this.__plugged[a];b&&(b.onValue("__handlePlugged",this,a),b.onError("__sendError",this))}},__onLastOut:function(){for(var a=0;a<this.__plugged.length;a++){var b=this.__plugged[a];b&&(b.offValue("__handlePlugged",this,a),b.offError("__sendError",this))}},__hasNoPlugged:function(){if(this.isEnded())return!0;for(var a=0;a<this.__plugged.length;a++)if(this.__plugged[a])return!1;return!0}};s.Bus=function(){x.call(this),this.__initPluggable()},h(s.Bus,x,L,{__ClassName:"Bus",push:function(a){return this.__sendAny(a),this},error:function(a){return this.__sendError(a),this},plug:function(a){return this.__plug(a),this},unplug:function(a){return this.__unplug(a),this},end:function(){return this.__sendEnd(),this},__clear:function(){x.prototype.__clear.call(this),this.__clearPluggable(),this.push=b}}),s.bus=function(){return new s.Bus},s.FlatMappedStream=function(a,b){x.call(this),this.__initPluggable(),this.__sourceStream=a,this.__mapFnMeta=m(b),a.onEnd(this.__onSourceEnds,this)},h(s.FlatMappedStream,x,L,{__ClassName:"FlatMappedStream",__onSourceEnds:function(){this.__hasNoPlugged()&&this.__sendEnd()},__plugResult:function(a){this.__plug(l(this.__mapFnMeta,[a]))},__onFirstIn:function(){this.__sourceStream.onValue("__plugResult",this),this.__sourceStream.onError("__sendError",this),L.__onFirstIn.call(this)},__onLastOut:function(){this.__sourceStream.offValue("__plugResult",this),this.__sourceStream.offError("__sendError",this),L.__onLastOut.call(this)},__unplugById:function(a){L.__unplugById.call(this,a),!this.isEnded()&&this.__hasNoPlugged()&&this.__sourceStream.isEnded()&&this.__sendEnd()},__clear:function(){x.prototype.__clear.call(this),this.__clearPluggable(),this.__sourceStream=null,this.__mapFnMeta=null}}),w.prototype.flatMap=function(){return new s.FlatMappedStream(this,arguments)},s.FlatMapLatestStream=function(){s.FlatMappedStream.apply(this,arguments)},h(s.FlatMapLatestStream,s.FlatMappedStream,{__ClassName:"FlatMapLatestStream",__plugResult:function(a){for(var b=0;b<this.__plugged.length;b++)this.__unplugById(b);s.FlatMappedStream.prototype.__plugResult.call(this,a)}}),w.prototype.flatMapLatest=function(){return new s.FlatMapLatestStream(this,arguments)},s.MergedStream=function(){x.call(this),this.__initPluggable();for(var a=j(arguments),b=0;b<a.length;b++)this.__plug(a[b])},h(s.MergedStream,x,L,{__ClassName:"MergedStream",__clear:function(){x.prototype.__clear.call(this),this.__clearPluggable()},__unplugById:function(a){L.__unplugById.call(this,a),this.__hasNoPlugged()&&this.__sendEnd()}}),s.merge=function(){return new s.MergedStream(j(arguments))},w.prototype.merge=function(){return s.merge([this].concat(j(arguments)))},s.CombinedStream=function(a,b){x.call(this),this.__initPluggable();for(var c=0;c<a.length;c++)this.__plug(a[c]);this.__cachedValues=new Array(a.length),this.__hasValue=new Array(a.length),this.__mapFnMeta=m(b)},h(s.CombinedStream,x,L,{__ClassName:"CombinedStream",__unplugById:function(a){L.__unplugById.call(this,a),this.__hasNoPlugged()&&this.__sendEnd()},__handlePlugged:function(a,b){this.__hasValue[a]=!0,this.__cachedValues[a]=b,this.__allCached()&&(this.__mapFnMeta?this.__sendAny(l(this.__mapFnMeta,this.__cachedValues)):this.__sendValue(this.__cachedValues.slice(0)))},__allCached:function(){for(var a=0;a<this.__hasValue.length;a++)if(!this.__hasValue[a])return!1;return!0},__clear:function(){x.prototype.__clear.call(this),this.__clearPluggable(),this.__cachedValues=null,this.__hasValue=null,this.__mapFnMeta=null}}),s.combine=function(a){return new s.CombinedStream(a,k(arguments,1))},w.prototype.combine=function(a){return new s.CombinedStream([this].concat(a),k(arguments,1))},s.onValues=function(a){var b=m(k(arguments,1));return s.combine(a).onValue(l,null,b)};var M=s.FromPollStream=function(a,b){x.call(this),this.__interval=a,this.__intervalId=null;var c=this;b=m(b),this.__bindedSend=function(){c.__sendAny(l(b))}};h(M,x,{__ClassName:"FromPollStream",__onFirstIn:function(){this.__intervalId=setInterval(this.__bindedSend,this.__interval)},__onLastOut:function(){null!==this.__intervalId&&(clearInterval(this.__intervalId),this.__intervalId=null)},__clear:function(){x.prototype.__clear.call(this),this.__bindedSend=null}}),s.fromPoll=function(a){return new M(a,k(arguments,1))},s.interval=function(a,b){return new M(a,[c,null,b])};var N=function(){return 0===this.xs.length?u:1===this.xs.length?s.bunch(this.xs[0],u):this.xs.shift()};s.sequentially=function(a,b){return new M(a,[N,{xs:b.slice(0)}])};var O=function(){return this.i=(this.i+1)%this.xs.length,this.xs[this.i]};s.repeatedly=function(a,b){return new M(a,[O,{i:-1,xs:b}])},"function"==typeof define&&define.amd?(define([],function(){return s}),a.Kefir=s):"object"==typeof module&&"object"==typeof exports?(module.exports=s,s.Kefir=s):a.Kefir=s}(this);
!function(a){"use strict";function b(){}function c(a){return a}function d(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function e(a){return q(a)?a:Array.prototype.slice.call(a)}function f(a){var b=function(){};return b.prototype=a,new b}function g(){if(1===arguments.length)return arguments[0];for(var a=arguments[0],b=1;b<arguments.length;b++)for(var c in arguments[b])d(arguments[b],c)&&(a[c]=arguments[b][c]);return a}function h(a,b){a.prototype=f(b.prototype),a.prototype.constructor=a;for(var c=2;c<arguments.length;c++)g(a.prototype,arguments[c]);return a}function i(a,b){for(var c in b)!d(b,c)||c in a||(a[c]=b[c]);return a}function j(a){return q(a[0])?a[0]:e(a)}function k(a,b,c){return a.length>b?Array.prototype.slice.call(a,b):c?null:[]}function l(a,b){if(o(a))return a;if(null!=b&&o(b[a]))return b[a];throw new Error("not a function: "+a+" in "+b)}function m(a,b){var c,d,f;return o(a)?(c=a,d=null,f=null):(d=a[1],c=l(a[0],d),f=k(a,2,!0)),b&&(f=f?f.concat(e(b)):b),f?c.apply(d,f):c.call(d)}function n(a){if(q(a)||t(a)){if(1===a.length)return a[0];if(0===a.length)return null}return a}function o(a){return"function"==typeof a}function p(a){return"undefined"==typeof a}function q(a){return"[object Array]"===Object.prototype.toString.call(a)}function r(a,b){if(null==a&&null==b)return!0;if(null==a||null==b)return!1;if(a.length!==b.length)return!1;for(var c=0;c<a.length;c++)if(a[c]!==b[c])return!1;return!0}function s(a,b,c){return a&&b in a?a[b]:c}var t=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};t(arguments)||(t=function(a){return!(!a||!d(a,"callee"))});var u=Date.now?function(){return Date.now()}:function(){return(new Date).getTime()},v={},w=v.NOTHING=["<nothing>"],x=v.END=["<end>"],y=v.NO_MORE=["<no more>"];v.BunchOfValues=function(a){this.values=a},v.bunch=function(){return new v.BunchOfValues(j(arguments))},v.Error=function(a){this.error=a},v.error=function(a){return new v.Error(a)};var z=v.Observable=function(a,b){o(a)&&(this.__onFirstIn=a),o(b)&&(this.__onLastOut=b),this.__subscribers=[]};h(z,Object,{__ClassName:"Observable",toString:function(){return"["+this.__ClassName+(this.__objName?" | "+this.__objName:"")+"]"},__onFirstIn:b,__onLastOut:b,__on:function(a){if(this.isEnded())"end"===a&&m(k(arguments,1));else{var b=("value"===a||"error"===a)&&!(this.__hasSubscribers("value")||this.__hasSubscribers("error"));this.__subscribers.push(arguments),b&&this.__onFirstIn()}},__off:function(a){if(!this.isEnded()){for(var b=0;b<this.__subscribers.length;b++)r(this.__subscribers[b],arguments)&&(this.__subscribers[b]=null);"value"!==a&&"error"!==a||this.__hasSubscribers("value")||this.__hasSubscribers("error")||this.__onLastOut()}},__send:function(a){if(!this.isEnded()){for(var b=0;b<this.__subscribers.length;b++){var c=this.__subscribers[b];if(c&&c[0]===a){var d=m(k(c,1),k(arguments,1));d===y&&this.__off.apply(this,c)}}"end"===a&&this.__clear()}},__hasSubscribers:function(a){if(this.isEnded())return!1;for(var b=0;b<this.__subscribers.length;b++)if(this.__subscribers[b]&&this.__subscribers[b][0]===a)return!0;return!1},__clear:function(){this.__onLastOut(),d(this,"__onFirstIn")&&(this.__onFirstIn=null),d(this,"__onLastOut")&&(this.__onLastOut=null),this.__subscribers=null},__sendValue:function(a){return this.__send("value",a),this},__sendError:function(a){return this.__send("error",a),this},__sendEnd:function(){return this.__send("end"),this},__sendAny:function(a){if(a===x)this.__sendEnd();else if(a instanceof v.BunchOfValues)for(var b=0;b<a.values.length;b++)this.__sendAny(a.values[b]);else a instanceof v.Error?this.__sendError(a.error):a!==w&&this.__sendValue(a);return this},onValue:function(){return this.__on.apply(this,["value"].concat(e(arguments))),this},offValue:function(){return this.__off.apply(this,["value"].concat(e(arguments))),this},onError:function(){return this.__on.apply(this,["error"].concat(e(arguments))),this},offError:function(){return this.__off.apply(this,["error"].concat(e(arguments))),this},onEnd:function(){return this.__on.apply(this,["end"].concat(e(arguments))),this},offEnd:function(){return this.__off.apply(this,["end"].concat(e(arguments))),this},onNewValue:function(){return this.onValue.apply(this,arguments)},isEnded:function(){return!this.__subscribers}});var A=v.Stream=function(){z.apply(this,arguments)};h(A,z,{__ClassName:"Stream"});var B=v.Property=function(a,b,c){z.call(this,a,b),this.__cached=p(c)?w:c};h(B,z,{__ClassName:"Property",hasValue:function(){return this.__cached!==w},getValue:function(){return this.__cached},__sendValue:function(a){this.isEnded()||(this.__cached=a),z.prototype.__sendValue.call(this,a)},onNewValue:function(){return this.__on.apply(this,["value"].concat(e(arguments))),this},onValue:function(){return this.hasValue()&&m(arguments,[this.__cached]),this.onNewValue.apply(this,arguments)}});var C=function(a,b,c){console.log(a,b,c)};z.prototype.log=function(a){return a||(a=this.toString()),this.onValue(C,null,a,"<value>"),this.onError(C,null,a,"<error>"),this.onEnd(C,null,a,"<end>"),this};var D=new A;D.__sendEnd(),D.__objName="Kefir.never()",v.never=function(){return D},v.OnceStream=function(a){A.call(this),this.__value=a},h(v.OnceStream,A,{__ClassName:"OnceStream",onValue:function(){return this.isEnded()||(m(arguments,[this.__value]),this.__value=null,this.__sendEnd()),this},onError:b}),v.once=function(a){return new v.OnceStream(a)},v.FromBinderStream=function(a){A.call(this),this.__subscribeFnMeta=n(a)},h(v.FromBinderStream,A,{__ClassName:"FromBinderStream",__onFirstIn:function(){var a=this;this.__usubscriber=m(this.__subscribeFnMeta,[function(b){a.__sendAny(b)}])},__onLastOut:function(){o(this.__usubscriber)&&this.__usubscriber(),this.__usubscriber=null},__clear:function(){A.prototype.__clear.call(this),this.__subscribeFnMeta=null}}),v.fromBinder=function(){return new v.FromBinderStream(arguments)};var E={__Constructor:function(a){this.__source=a,a.onEnd(this.__sendEnd,this),a instanceof B&&this instanceof B&&a.hasValue()&&this.__handle(a.getValue())},__handle:function(a){this.__sendAny(a)},__onFirstIn:function(){this.__source.onNewValue("__handle",this),this.__source.onError("__sendError",this)},__onLastOut:function(){this.__source.offValue("__handle",this),this.__source.offError("__sendError",this)},__clear:function(){z.prototype.__clear.call(this),this.__source=null}};v.PropertyFromStream=function(a,b){B.call(this,null,null,b),this.__Constructor(a)},h(v.PropertyFromStream,B,E,{__ClassName:"PropertyFromStream"}),A.prototype.toProperty=function(a){return new v.PropertyFromStream(this,a)},B.prototype.toProperty=function(a){if(p(a))return this;var b=new v.PropertyFromStream(this);return b.__sendValue(a),b},v.ScanProperty=function(a,b,c){B.call(this,null,null,b),this.__fnMeta=n(c),this.__Constructor(a)},h(v.ScanProperty,B,E,{__ClassName:"ScanProperty",__handle:function(a){this.__sendValue(m(this.__fnMeta,[this.getValue(),a]))},__clear:function(){E.__clear.call(this),this.__fnMeta=null}}),z.prototype.scan=function(a){return new v.ScanProperty(this,a,k(arguments,1))},v.ReducedProperty=function(a,b,c){B.call(this),this.__fnMeta=n(c),this.__result=b,a.onEnd("__sendResult",this),this.__Constructor(a)},h(v.ReducedProperty,B,E,{__ClassName:"ReducedProperty",__handle:function(a){this.__result=m(this.__fnMeta,[this.__result,a])},__sendResult:function(){this.__sendValue(this.__result)},__clear:function(){E.__clear.call(this),this.__fnMeta=null,this.__result=null}}),z.prototype.reduce=function(a){return new v.ReducedProperty(this,a,k(arguments,1))};var F={__Constructor:function(a,b){this instanceof B?B.call(this):A.call(this),this.__mapFnMeta=n(b),E.__Constructor.call(this,a)},__handle:function(a){this.__sendAny(this.__mapFnMeta?m(this.__mapFnMeta,[a]):a)},__clear:function(){E.__clear.call(this),this.__mapFnMeta=null}};i(F,E),v.MappedStream=function(){this.__Constructor.apply(this,arguments)},h(v.MappedStream,A,F,{__ClassName:"MappedStream"}),v.MappedProperty=function(){this.__Constructor.apply(this,arguments)},h(v.MappedProperty,B,F,{__ClassName:"MappedProperty"}),A.prototype.map=function(){return new v.MappedStream(this,arguments)},B.prototype.map=function(){return new v.MappedProperty(this,arguments)},B.prototype.changes=function(){return new v.MappedStream(this)};var G=function(a){var b=m(this.fnMeta,[this.prev,a]);return this.prev=a,b};z.prototype.diff=function(a){return this.map(G,{prev:a,fnMeta:n(k(arguments,1))})};var H=function(a,b){return m(a,[b])?b:w};z.prototype.filter=function(){return this.map(H,null,n(arguments))};var I=function(a,b){return m(a,[b])?b:x};z.prototype.takeWhile=function(){return this.map(I,null,n(arguments))};var J=function(a){return this.n<=0?x:1===this.n?v.bunch(a,x):(this.n--,a)};z.prototype.take=function(a){return this.map(J,{n:a})};var K=function(a){return this.n<=0?a:(this.n--,w)};z.prototype.skip=function(a){return this.map(K,{n:a})};var L=function(a){var b;return b=this.prev!==w&&(this.fn?this.fn(this.prev,a):this.prev===a)?w:a,this.hasPrev=!0,this.prev=a,b};z.prototype.skipDuplicates=function(a){return this.map(L,{fn:a,prev:w})};var M=function(a){return this.skip&&m(this.fnMeta,[a])?w:(this.skip=!1,a)};z.prototype.skipWhile=function(){return this.map(M,{skip:!0,fnMeta:n(arguments)})};var N={__Constructor:function(a,b,c){this instanceof B?B.call(this):A.call(this),this.__fnMeta=n(c),this.__mainStream=a,this.__lastValue=w,a instanceof B&&a.hasValue()&&(this.__lastValue=a.getValue()),E.__Constructor.call(this,b)},__handle:function(a){if(this.__lastValue!==w){var b=this.__lastValue;this.__fnMeta&&(b=m(this.__fnMeta,[b,a])),this.__sendValue(b)}},__onFirstIn:function(){E.__onFirstIn.call(this),this.__mainStream.onValue("__saveValue",this),this.__mainStream.onError("__sendError",this)},__onLastOut:function(){E.__onLastOut.call(this),this.__mainStream.offValue("__saveValue",this),this.__mainStream.offError("__sendError",this)},__saveValue:function(a){this.__lastValue=a},__clear:function(){E.__clear.call(this),this.__lastValue=null,this.__fn=null,this.__mainStream=null}};i(N,E),v.SampledByStream=function(){this.__Constructor.apply(this,arguments)},h(v.SampledByStream,A,N,{__ClassName:"SampledByStream"}),v.SampledByProperty=function(){this.__Constructor.apply(this,arguments)},h(v.SampledByProperty,B,N,{__ClassName:"SampledByProperty"}),z.prototype.sampledBy=function(a){return a instanceof A?new v.SampledByStream(this,a,k(arguments,1)):new v.SampledByProperty(this,a,k(arguments,1))};var O={__initPluggable:function(){this.__plugged=[]},__clearPluggable:function(){this.__plugged=null},__handlePlugged:function(a,b){this.__sendAny(b)},__plug:function(a){if(!this.isEnded()){this.__plugged.push(a);var b=this.__plugged.length-1;this.__hasSubscribers("value")&&(a.onValue("__handlePlugged",this,b),a.onError("__sendError",this)),a.onEnd("__unplugById",this,b)}},__unplugById:function(a){if(!this.isEnded()){var b=this.__plugged[a];b&&(this.__plugged[a]=null,b.offValue("__handlePlugged",this,a),b.offError("__sendError",this),b.offEnd("__unplugById",this,a))}},__unplug:function(a){if(!this.isEnded())for(var b=0;b<this.__plugged.length;b++)this.__plugged[b]===a&&this.__unplugById(b)},__onFirstIn:function(){for(var a=0;a<this.__plugged.length;a++){var b=this.__plugged[a];b&&(b.onValue("__handlePlugged",this,a),b.onError("__sendError",this))}},__onLastOut:function(){for(var a=0;a<this.__plugged.length;a++){var b=this.__plugged[a];b&&(b.offValue("__handlePlugged",this,a),b.offError("__sendError",this))}},__hasNoPlugged:function(){if(this.isEnded())return!0;for(var a=0;a<this.__plugged.length;a++)if(this.__plugged[a])return!1;return!0}};v.Bus=function(){A.call(this),this.__initPluggable()},h(v.Bus,A,O,{__ClassName:"Bus",push:function(a){return this.__sendAny(a),this},error:function(a){return this.__sendError(a),this},plug:function(a){return this.__plug(a),this},unplug:function(a){return this.__unplug(a),this},end:function(){return this.__sendEnd(),this},__clear:function(){A.prototype.__clear.call(this),this.__clearPluggable(),this.push=b}}),v.bus=function(){return new v.Bus},v.FlatMappedStream=function(a,b){A.call(this),this.__initPluggable(),this.__sourceStream=a,this.__mapFnMeta=n(b),a.onEnd(this.__onSourceEnds,this)},h(v.FlatMappedStream,A,O,{__ClassName:"FlatMappedStream",__onSourceEnds:function(){this.__hasNoPlugged()&&this.__sendEnd()},__plugResult:function(a){this.__plug(m(this.__mapFnMeta,[a]))},__onFirstIn:function(){this.__sourceStream.onValue("__plugResult",this),this.__sourceStream.onError("__sendError",this),O.__onFirstIn.call(this)},__onLastOut:function(){this.__sourceStream.offValue("__plugResult",this),this.__sourceStream.offError("__sendError",this),O.__onLastOut.call(this)},__unplugById:function(a){O.__unplugById.call(this,a),!this.isEnded()&&this.__hasNoPlugged()&&this.__sourceStream.isEnded()&&this.__sendEnd()},__clear:function(){A.prototype.__clear.call(this),this.__clearPluggable(),this.__sourceStream=null,this.__mapFnMeta=null}}),z.prototype.flatMap=function(){return new v.FlatMappedStream(this,arguments)},v.FlatMapLatestStream=function(){v.FlatMappedStream.apply(this,arguments)},h(v.FlatMapLatestStream,v.FlatMappedStream,{__ClassName:"FlatMapLatestStream",__plugResult:function(a){for(var b=0;b<this.__plugged.length;b++)this.__unplugById(b);v.FlatMappedStream.prototype.__plugResult.call(this,a)}}),z.prototype.flatMapLatest=function(){return new v.FlatMapLatestStream(this,arguments)},v.MergedStream=function(){A.call(this),this.__initPluggable();for(var a=j(arguments),b=0;b<a.length;b++)this.__plug(a[b])},h(v.MergedStream,A,O,{__ClassName:"MergedStream",__clear:function(){A.prototype.__clear.call(this),this.__clearPluggable()},__unplugById:function(a){O.__unplugById.call(this,a),this.__hasNoPlugged()&&this.__sendEnd()}}),v.merge=function(){return new v.MergedStream(j(arguments))},z.prototype.merge=function(){return v.merge([this].concat(j(arguments)))},v.CombinedStream=function(a,b){A.call(this),this.__initPluggable();for(var c=0;c<a.length;c++)this.__plug(a[c]);this.__cachedValues=new Array(a.length),this.__hasValue=new Array(a.length),this.__mapFnMeta=n(b)},h(v.CombinedStream,A,O,{__ClassName:"CombinedStream",__unplugById:function(a){O.__unplugById.call(this,a),this.__hasNoPlugged()&&this.__sendEnd()},__handlePlugged:function(a,b){this.__hasValue[a]=!0,this.__cachedValues[a]=b,this.__allCached()&&(this.__mapFnMeta?this.__sendAny(m(this.__mapFnMeta,this.__cachedValues)):this.__sendValue(this.__cachedValues.slice(0)))},__allCached:function(){for(var a=0;a<this.__hasValue.length;a++)if(!this.__hasValue[a])return!1;return!0},__clear:function(){A.prototype.__clear.call(this),this.__clearPluggable(),this.__cachedValues=null,this.__hasValue=null,this.__mapFnMeta=null}}),v.combine=function(a){return new v.CombinedStream(a,k(arguments,1))},z.prototype.combine=function(a){return new v.CombinedStream([this].concat(a),k(arguments,1))},v.onValues=function(a){var b=n(k(arguments,1));return v.combine(a).onValue(m,null,b)},v.LaterStream=function(a,b){A.call(this),this.__value=b,this.__wait=a},h(v.LaterStream,A,{__ClassName:"LaterStream",__onFirstIn:function(){var a=this;setTimeout(function(){a.__sendAny(a.__value),a.__sendEnd()},this.__wait)},__clear:function(){A.prototype.__clear.call(this),this.__value=null,this.__wait=null}}),v.later=function(a,b){return new v.LaterStream(a,b)};var P={__Constructor:function(a,b){this.__source=a,this.__wait=b,a.onEnd(this.__sendEndLater,this)},__sendLater:function(a){var b=this;setTimeout(function(){b.__sendValue(a)},this.__wait)},__sendEndLater:function(){var a=this;setTimeout(function(){a.__sendEnd()},this.__wait)},__onFirstIn:function(){this.__source.onNewValue("__sendLater",this),this.__source.onError("__sendError",this)},__onLastOut:function(){this.__source.offValue("__sendLater",this),this.__source.offError("__sendError",this)},__clear:function(){z.prototype.__clear.call(this),this.__source=null,this.__wait=null}};v.DelayedStream=function(a,b){A.call(this),P.__Constructor.call(this,a,b)},h(v.DelayedStream,A,P,{__ClassName:"DelayedStream"}),A.prototype.delay=function(a){return new v.DelayedStream(this,a)},v.DelayedProperty=function(a,b){B.call(this),P.__Constructor.call(this,a,b),a.hasValue()&&this.__sendValue(a.getValue())},h(v.DelayedProperty,B,P,{__ClassName:"DelayedProperty"}),B.prototype.delay=function(a){return new v.DelayedProperty(this,a)};var Q={__Constructor:function(a,b,c){this.__source=a,this.__wait=b,this.__trailingCallValue=null,this.__trailingCallTimeoutId=null,this.__endAfterTrailingCall=!1,this.__lastCallTime=0,this.__leading=s(c,"leading",!0),this.__trailing=s(c,"trailing",!0);var d=this;this.__makeTrailingCallBinded=function(){d.__makeTrailingCall()},a.onEnd(this.__sendEndLater,this)},__sendEndLater:function(){this.__trailingCallTimeoutId?this.__endAfterTrailingCall=!0:this.__sendEnd()},__scheduleTralingCall:function(a,b){this.__trailingCallTimeoutId&&this.__cancelTralingCall(),this.__trailingCallValue=a,this.__trailingCallTimeoutId=setTimeout(this.__makeTrailingCallBinded,b)},__cancelTralingCall:function(){null!==this.__trailingCallTimeoutId&&(clearTimeout(this.__trailingCallTimeoutId),this.__trailingCallTimeoutId=null)},__makeTrailingCall:function(){this.__sendValue(this.__trailingCallValue),this.__trailingCallTimeoutId=null,this.__trailingCallValue=null,this.__lastCallTime=this.__leading?u():0,this.__endAfterTrailingCall&&this.__sendEnd()},__handleValueFromSource:function(a){var b=u();0!==this.__lastCallTime||this.__leading||(this.__lastCallTime=b);var c=this.__wait-(b-this.__lastCallTime);0>=c?(this.__cancelTralingCall(),this.__lastCallTime=b,this.__sendValue(a)):this.__trailing&&this.__scheduleTralingCall(a,c)},__onFirstIn:function(){this.__source.onNewValue("__handleValueFromSource",this),this.__source.onError("__sendError",this)},__onLastOut:function(){this.__source.offValue("__handleValueFromSource",this),this.__source.offError("__sendError",this)},__clear:function(){z.prototype.__clear.call(this),this.__source=null,this.__wait=null,this.__trailingCallValue=null,this.__trailingCallTimeoutId=null,this.__makeTrailingCallBinded=null}};v.ThrottledStream=function(){A.call(this),Q.__Constructor.apply(this,arguments)},h(v.ThrottledStream,A,Q,{__ClassName:"ThrottledStream"}),A.prototype.throttle=function(a,b){return new v.ThrottledStream(this,a,b)},v.ThrottledProperty=function(a){B.call(this),Q.__Constructor.apply(this,arguments),a.hasValue()&&this.__sendValue(a.getValue())},h(v.ThrottledProperty,B,Q,{__ClassName:"ThrottledProperty"}),B.prototype.throttle=function(a,b){return new v.ThrottledProperty(this,a,b)};var R=v.FromPollStream=function(a,b){A.call(this),this.__interval=a,this.__intervalId=null;var c=this;b=n(b),this.__bindedSend=function(){c.__sendAny(m(b))}};h(R,A,{__ClassName:"FromPollStream",__onFirstIn:function(){this.__intervalId=setInterval(this.__bindedSend,this.__interval)},__onLastOut:function(){null!==this.__intervalId&&(clearInterval(this.__intervalId),this.__intervalId=null)},__clear:function(){A.prototype.__clear.call(this),this.__bindedSend=null}}),v.fromPoll=function(a){return new R(a,k(arguments,1))},v.interval=function(a,b){return new R(a,[c,null,b])};var S=function(){return 0===this.xs.length?x:1===this.xs.length?v.bunch(this.xs[0],x):this.xs.shift()};v.sequentially=function(a,b){return new R(a,[S,{xs:b.slice(0)}])};var T=function(){return this.i=(this.i+1)%this.xs.length,this.xs[this.i]};v.repeatedly=function(a,b){return new R(a,[T,{i:-1,xs:b}])},"function"==typeof define&&define.amd?(define([],function(){return v}),a.Kefir=v):"object"==typeof module&&"object"==typeof exports?(module.exports=v,v.Kefir=v):a.Kefir=v}(this);

@@ -10,3 +10,3 @@ Generated by run: node --expose-gc test-memory-usage.js > memory-usage-results.txt

Rx: w/o subscr. 0.25 KiB, w/ subscr. +0.43 KiB
Bacon: w/o subscr. 3.04 KiB, w/ subscr. +0.92 KiB
Bacon: w/o subscr. 3.04 KiB, w/ subscr. +0.91 KiB

@@ -24,64 +24,82 @@ new Bus()

Rx: w/o subscr. 0.23 KiB, w/ subscr. -0.00 KiB
Bacon: w/o subscr. 4.03 KiB, w/ subscr. +0.89 KiB
Bacon: w/o subscr. 4.04 KiB, w/ subscr. +0.89 KiB
.toProperty(1)
Kefir: w/o subscr. 0.97 KiB, w/ subscr. +0.36 KiB
Rx: w/o subscr. 1.22 KiB, w/ subscr. +1.18 KiB
Bacon: w/o subscr. 7.88 KiB, w/ subscr. +1.92 KiB
Kefir: w/o subscr. 0.18 KiB, w/ subscr. +0.39 KiB
Rx: w/o subscr. 0.99 KiB, w/ subscr. +1.16 KiB
Bacon: w/o subscr. 4.98 KiB, w/ subscr. +1.56 KiB
.toProperty(1).changes()
Kefir: w/o subscr. 1.27 KiB, w/ subscr. +0.52 KiB
Bacon: w/o subscr. 10.80 KiB, w/ subscr. +2.44 KiB
Kefir: w/o subscr. 0.19 KiB, w/ subscr. +0.37 KiB
Bacon: w/o subscr. 3.00 KiB, w/ subscr. +1.10 KiB
.map(noop)
Kefir: w/o subscr. 0.96 KiB, w/ subscr. +0.35 KiB
Rx: w/o subscr. 0.52 KiB, w/ subscr. +1.52 KiB
Bacon: w/o subscr. 8.29 KiB, w/ subscr. +1.71 KiB
Kefir: w/o subscr. 0.18 KiB, w/ subscr. +0.37 KiB
Rx: w/o subscr. 0.30 KiB, w/ subscr. +1.50 KiB
Bacon: w/o subscr. 5.39 KiB, w/ subscr. +1.35 KiB
.filter(noop)
Kefir: w/o subscr. 1.03 KiB, w/ subscr. +0.35 KiB
Rx: w/o subscr. 0.52 KiB, w/ subscr. +1.47 KiB
Bacon: w/o subscr. 8.27 KiB, w/ subscr. +1.71 KiB
Kefir: w/o subscr. 0.24 KiB, w/ subscr. +0.38 KiB
Rx: w/o subscr. 0.30 KiB, w/ subscr. +1.47 KiB
Bacon: w/o subscr. 5.38 KiB, w/ subscr. +1.35 KiB
.skipDuplicates(noop)
Kefir: w/o subscr. 1.06 KiB, w/ subscr. +0.41 KiB
Rx: w/o subscr. 0.53 KiB, w/ subscr. +1.48 KiB
Bacon: w/o subscr. 9.11 KiB, w/ subscr. +1.71 KiB
Kefir: w/o subscr. 0.27 KiB, w/ subscr. +0.38 KiB
Rx: w/o subscr. 0.30 KiB, w/ subscr. +1.50 KiB
Bacon: w/o subscr. 6.15 KiB, w/ subscr. +1.35 KiB
.scan(0, noop)
Kefir: w/o subscr. 0.97 KiB, w/ subscr. +0.35 KiB
Rx: w/o subscr. 0.54 KiB, w/ subscr. +1.17 KiB
Bacon: w/o subscr. 6.80 KiB, w/ subscr. +1.90 KiB
Kefir: w/o subscr. 0.18 KiB, w/ subscr. +0.37 KiB
Rx: w/o subscr. 0.31 KiB, w/ subscr. +1.17 KiB
Bacon: w/o subscr. 3.90 KiB, w/ subscr. +1.54 KiB
.sequentially(0, [1, 2])
Kefir: w/o subscr. 0.38 KiB, w/ subscr. +0.55 KiB
Bacon: w/o subscr. 5.02 KiB, w/ subscr. +1.31 KiB
Kefir: w/o subscr. 0.39 KiB, w/ subscr. +0.56 KiB
Bacon: w/o subscr. 5.01 KiB, w/ subscr. +1.32 KiB
.later(0, 1)
Kefir: w/o subscr. 0.08 KiB, w/ subscr. +0.44 KiB
Bacon: w/o subscr. 4.85 KiB, w/ subscr. +1.32 KiB
.take(5)
Kefir: w/o subscr. 1.05 KiB, w/ subscr. +0.35 KiB
Rx: w/o subscr. 0.52 KiB, w/ subscr. +1.55 KiB
Bacon: w/o subscr. 8.20 KiB, w/ subscr. +1.71 KiB
Kefir: w/o subscr. 0.26 KiB, w/ subscr. +0.37 KiB
Rx: w/o subscr. 0.29 KiB, w/ subscr. +1.47 KiB
Bacon: w/o subscr. 5.30 KiB, w/ subscr. +1.35 KiB
.delay(1)
Kefir: w/o subscr. 0.18 KiB, w/ subscr. +0.38 KiB
Rx: w/o subscr. 0.33 KiB, w/ subscr. +3.12 KiB
Bacon: w/o subscr. 4.22 KiB, w/ subscr. +2.34 KiB
.throttle(1)
Kefir: w/o subscr. 0.37 KiB, w/ subscr. +0.38 KiB
Rx: w/o subscr. 0.43 KiB, w/ subscr. +1.02 KiB
Bacon: w/o subscr. 12.51 KiB, w/ subscr. +2.18 KiB
.flatMap(noop)
Kefir: w/o subscr. 1.00 KiB, w/ subscr. +0.36 KiB
Rx: w/o subscr. 0.94 KiB, w/ subscr. +2.51 KiB
Bacon: w/o subscr. 5.91 KiB, w/ subscr. +2.70 KiB
Kefir: w/o subscr. 0.21 KiB, w/ subscr. +0.39 KiB
Rx: w/o subscr. 0.71 KiB, w/ subscr. +2.51 KiB
Bacon: w/o subscr. 3.00 KiB, w/ subscr. +2.31 KiB
.combine(stream, noop)
Kefir: w/o subscr. 2.18 KiB, w/ subscr. +0.51 KiB
Rx: w/o subscr. 0.82 KiB, w/ subscr. +2.93 KiB
Bacon: w/o subscr. 20.99 KiB, w/ subscr. +5.01 KiB
Kefir: w/o subscr. 1.39 KiB, w/ subscr. +0.53 KiB
Rx: w/o subscr. 0.59 KiB, w/ subscr. +2.99 KiB
Bacon: w/o subscr. 18.10 KiB, w/ subscr. +4.65 KiB
.toProperty(1).sampledBy(stream, noop)
Kefir: w/o subscr. 1.91 KiB, w/ subscr. +0.92 KiB
Bacon: w/o subscr. 15.19 KiB, w/ subscr. +5.03 KiB
Kefir: w/o subscr. 1.12 KiB, w/ subscr. +0.81 KiB
Bacon: w/o subscr. 12.45 KiB, w/ subscr. +4.66 KiB
.combineAsArray(stream1, stream2, stream3, stream4)
Kefir: w/o subscr. 3.97 KiB, w/ subscr. +0.79 KiB
Rx: w/o subscr. 1.26 KiB, w/ subscr. +3.70 KiB
Bacon: w/o subscr. 21.45 KiB, w/ subscr. +6.72 KiB
Kefir: w/o subscr. 3.98 KiB, w/ subscr. +0.80 KiB
Rx: w/o subscr. 1.25 KiB, w/ subscr. +3.82 KiB
Bacon: w/o subscr. 21.46 KiB, w/ subscr. +6.71 KiB
.mergeAll(stream1, stream2, stream3, stream4)
Kefir: w/o subscr. 3.75 KiB, w/ subscr. +0.80 KiB
Rx: w/o subscr. 1.56 KiB, w/ subscr. +5.67 KiB
Rx: w/o subscr. 1.56 KiB, w/ subscr. +5.58 KiB
Bacon: w/o subscr. 14.62 KiB, w/ subscr. +4.59 KiB
.fromBinder(noop)
Kefir: w/o subscr. 0.06 KiB, w/ subscr. +0.25 KiB
Bacon: w/o subscr. 2.96 KiB, w/ subscr. +0.75 KiB
{
"name": "kefir",
"version": "0.1.10",
"version": "0.1.11",
"description": "Bacon.js inspired FRP library with less memory consumption",

@@ -48,3 +48,4 @@ "main": "dist/kefir.js",

"semver": "^2.3.0",
"shelljs": "^0.3.0"
"shelljs": "^0.3.0",
"sinon": "^1.10.1"
},

@@ -51,0 +52,0 @@ "testling": {

# Kefir
http://pozadi.github.io/kefir
Kefir — is an FRP (functional reactive programming) library for JavaScript
inspired by [Bacon.js](https://github.com/baconjs/bacon.js)
and [RxJS](https://github.com/Reactive-Extensions/RxJS)
with focus on high perfomance and low memory usage.
It has nice Bacon.js like API
and RxJS's performance / memory usage characteristics (see [memory test results](https://github.com/pozadi/kefir/blob/master/memory-usage-results.txt)).
Bacon.js inspired FRP library with [less memory consumption](https://github.com/pozadi/kefir/blob/master/memory-usage-results.txt)
For docs visit [pozadi.github.io/kefir](http://pozadi.github.io/kefir).
:construction: It still in alpha developnet stage. See [Bacon.js API implementation status](https://github.com/pozadi/kefir/blob/master/bacon-api-impl-status.md).
# Tests
[![Build Status](https://travis-ci.org/pozadi/kefir.svg?branch=master)](https://travis-ci.org/pozadi/kefir)

@@ -11,16 +22,15 @@

# Development stage
[Run tests in your browser](http://pozadi.github.io/kefir/test/in-browser/SpecRunner.html) (`gh-pages` branch)
Early alpha
[Bacon.js API implementation status](https://github.com/pozadi/kefir/blob/master/bacon-api-impl-status.md)
# Install
# Development
### NPM
To build `/dist` from `/src` and run tests on Node.js type this in console:
npm install kefir
grunt
### Bower
To run memory tests:
bower install kefir
node --expose-gc test-memory-usage.js
// TODO
//
// .fromEventTarget(target, eventName [, eventTransformer])

@@ -1,36 +0,4 @@

// $::eventStream()
// var jQuery = global.jQuery || global.Zepto || (
// typeof window !== 'undefined' && (window.jQuery || window.Zepto)
// );
// if (jQuery) {
// jQuery.fn.eventStream = function(events, selector, eventTransformer){
// if (arguments.length === 2 && isFn(selector)) {
// eventTransformer = selector;
// selector = null;
// }
// if (!isFn(eventTransformer)) {
// eventTransformer = id;
// }
// var $this = this;
// function handler(){
// result._send( eventTransformer.apply(this, arguments) );
// }
// function sub(){
// $this.onValue(events, selector, handler);
// }
// function unsub(){
// $this.offValue(events, selector, handler);
// }
// var result = new Stream(sub, unsub);
// return result;
// }
// }
// TODO
//
// $.fn.asStream(eventName, [selector], [eventTransformer])
// $.fn.asProperty(eventName, [selector], getter)

@@ -92,3 +92,3 @@ // TODO

// Bus
// Kefir.bus()

@@ -140,3 +140,3 @@ Kefir.Bus = function Bus(){

// FlatMap
// .flatMap()

@@ -195,3 +195,3 @@ Kefir.FlatMappedStream = function FlatMappedStream(sourceStream, mapFnMeta){

// FlatMapLatest
// .flatMapLatest()

@@ -222,3 +222,3 @@ Kefir.FlatMapLatestStream = function FlatMapLatestStream(){

// Merge
// .merge()

@@ -267,3 +267,3 @@ Kefir.MergedStream = function MergedStream(){

// Combine
// .combine()

@@ -270,0 +270,0 @@ Kefir.CombinedStream = function CombinedStream(sources, mapFnMeta){

@@ -298,3 +298,3 @@ var WithSourceStreamMixin = {

// .skipWhile(f)
// .skipWhile(fn)

@@ -313,7 +313,1 @@ var skipWhileMapFn = function(x){

}

@@ -5,6 +5,7 @@ // TODO

// Kefir.fromArray(values)
// Kefir.fromCallback(fn)
// Never
// Kefir.never()

@@ -21,3 +22,3 @@ var neverObj = new Stream();

// Once
// Kefir.once(x)

@@ -52,7 +53,7 @@ Kefir.OnceStream = function OnceStream(value){

// fromBinder
// Kefir.fromBinder(fn)
Kefir.FromBinderStream = function FromBinderStream(subscribe){
Kefir.FromBinderStream = function FromBinderStream(subscribeFnMeta){
Stream.call(this);
this.__subscribe = subscribe;
this.__subscribeFnMeta = normFnMeta(subscribeFnMeta);
}

@@ -65,5 +66,5 @@

var _this = this;
this.__usubscriber = this.__subscribe(function(x){
this.__usubscriber = callFn(this.__subscribeFnMeta, [function(x){
_this.__sendAny(x);
});
}]);
},

@@ -78,3 +79,3 @@ __onLastOut: function(){

Stream.prototype.__clear.call(this);
this.__subscribe = null;
this.__subscribeFnMeta = null;
}

@@ -84,4 +85,4 @@

Kefir.fromBinder = function(subscribe){
return new Kefir.FromBinderStream(subscribe);
Kefir.fromBinder = function(/*subscribe[, context[, arg1, arg2...]]*/){
return new Kefir.FromBinderStream(arguments);
}
// TODO
//
// observable.not()

@@ -4,0 +4,0 @@ // property.and(other)

// TODO
//
// // more underscore-style maybe?
// observable.delay(delay)
// observable.throttle(delay)
// observable.debounce(delay)
// observable.debounceImmediate(delay)
//
// Kefir.later(delay, value)
// observable.debounce(wait, immediate)
// http://underscorejs.org/#defer
// Kefir.later()
Kefir.LaterStream = function LaterStream(wait, value) {
Stream.call(this);
this.__value = value;
this.__wait = wait;
}
inherit(Kefir.LaterStream, Stream, {
__ClassName: 'LaterStream',
__onFirstIn: function(){
var _this = this;
setTimeout(function(){
_this.__sendAny(_this.__value);
_this.__sendEnd();
}, this.__wait);
},
__clear: function(){
Stream.prototype.__clear.call(this);
this.__value = null;
this.__wait = null;
}
});
Kefir.later = function(wait, value) {
return new Kefir.LaterStream(wait, value);
}
// .delay()
var DelayedMixin = {
__Constructor: function(source, wait) {
this.__source = source;
this.__wait = wait;
source.onEnd(this.__sendEndLater, this);
},
__sendLater: function(x){
var _this = this;
setTimeout(function(){ _this.__sendValue(x) }, this.__wait);
},
__sendEndLater: function(){
var _this = this;
setTimeout(function(){ _this.__sendEnd() }, this.__wait);
},
__onFirstIn: function(){
this.__source.onNewValue('__sendLater', this);
this.__source.onError('__sendError', this);
},
__onLastOut: function(){
this.__source.offValue('__sendLater', this);
this.__source.offError('__sendError', this);
},
__clear: function(){
Observable.prototype.__clear.call(this);
this.__source = null;
this.__wait = null;
}
}
Kefir.DelayedStream = function DelayedStream(source, wait) {
Stream.call(this);
DelayedMixin.__Constructor.call(this, source, wait);
}
inherit(Kefir.DelayedStream, Stream, DelayedMixin, {
__ClassName: 'DelayedStream'
});
Stream.prototype.delay = function(wait) {
return new Kefir.DelayedStream(this, wait);
}
Kefir.DelayedProperty = function DelayedProperty(source, wait) {
Property.call(this);
DelayedMixin.__Constructor.call(this, source, wait);
if (source.hasValue()) {
this.__sendValue(source.getValue());
}
}
inherit(Kefir.DelayedProperty, Property, DelayedMixin, {
__ClassName: 'DelayedProperty'
});
Property.prototype.delay = function(wait) {
return new Kefir.DelayedProperty(this, wait);
}
// .throttle(wait, {leading, trailing})
var ThrottledMixin = {
__Constructor: function(source, wait, options){
this.__source = source;
this.__wait = wait;
this.__trailingCallValue = null;
this.__trailingCallTimeoutId = null;
this.__endAfterTrailingCall = false;
this.__lastCallTime = 0;
this.__leading = get(options, 'leading', true);
this.__trailing = get(options, 'trailing', true);
var _this = this;
this.__makeTrailingCallBinded = function(){ _this.__makeTrailingCall() };
source.onEnd(this.__sendEndLater, this);
},
__sendEndLater: function(){
if (this.__trailingCallTimeoutId) {
this.__endAfterTrailingCall = true;
} else {
this.__sendEnd();
}
},
__scheduleTralingCall: function(value, wait){
if (this.__trailingCallTimeoutId) {
this.__cancelTralingCall();
}
this.__trailingCallValue = value;
this.__trailingCallTimeoutId = setTimeout(this.__makeTrailingCallBinded, wait);
},
__cancelTralingCall: function(){
if (this.__trailingCallTimeoutId !== null) {
clearTimeout(this.__trailingCallTimeoutId);
this.__trailingCallTimeoutId = null;
}
},
__makeTrailingCall: function(){
this.__sendValue(this.__trailingCallValue);
this.__trailingCallTimeoutId = null;
this.__trailingCallValue = null;
this.__lastCallTime = !this.__leading ? 0 : now();
if (this.__endAfterTrailingCall) {
this.__sendEnd();
}
},
__handleValueFromSource: function(x){
var curTime = now();
if (this.__lastCallTime === 0 && !this.__leading) {
this.__lastCallTime = curTime;
}
var remaining = this.__wait - (curTime - this.__lastCallTime);
if (remaining <= 0) {
this.__cancelTralingCall();
this.__lastCallTime = curTime;
this.__sendValue(x);
} else if (this.__trailing) {
this.__scheduleTralingCall(x, remaining);
}
},
__onFirstIn: function(){
this.__source.onNewValue('__handleValueFromSource', this);
this.__source.onError('__sendError', this);
},
__onLastOut: function(){
this.__source.offValue('__handleValueFromSource', this);
this.__source.offError('__sendError', this);
},
__clear: function(){
Observable.prototype.__clear.call(this);
this.__source = null;
this.__wait = null;
this.__trailingCallValue = null;
this.__trailingCallTimeoutId = null;
this.__makeTrailingCallBinded = null;
}
};
Kefir.ThrottledStream = function ThrottledStream() {
Stream.call(this);
ThrottledMixin.__Constructor.apply(this, arguments);
}
inherit(Kefir.ThrottledStream, Stream, ThrottledMixin, {
__ClassName: 'ThrottledStream'
});
Stream.prototype.throttle = function(wait, options) {
return new Kefir.ThrottledStream(this, wait, options);
}
Kefir.ThrottledProperty = function ThrottledProperty(source) {
Property.call(this);
ThrottledMixin.__Constructor.apply(this, arguments);
if (source.hasValue()) {
this.__sendValue(source.getValue());
}
}
inherit(Kefir.ThrottledProperty, Property, ThrottledMixin, {
__ClassName: 'ThrottledProperty'
});
Property.prototype.throttle = function(wait, options) {
return new Kefir.ThrottledProperty(this, wait, options);
}
// Kefir.fromPoll()
var FromPollStream = Kefir.FromPollStream = function FromPollStream(interval, sourceFnMeta){
Stream.call(this);
this.__interval = interval;
this.__intervalId = null;
var _this = this;
sourceFnMeta = normFnMeta(sourceFnMeta);
this.__bindedSend = function(){ _this.__sendAny(callFn(sourceFnMeta)) }
}
inherit(FromPollStream, Stream, {
__ClassName: 'FromPollStream',
__onFirstIn: function(){
this.__intervalId = setInterval(this.__bindedSend, this.__interval);
},
__onLastOut: function(){
if (this.__intervalId !== null){
clearInterval(this.__intervalId);
this.__intervalId = null;
}
},
__clear: function(){
Stream.prototype.__clear.call(this);
this.__bindedSend = null;
}
});
Kefir.fromPoll = function(interval/*, fn[, context[, arg1, arg2, ...]]*/){
return new FromPollStream(interval, restArgs(arguments, 1));
}
// Kefir.interval()
Kefir.interval = function(interval, x){
return new FromPollStream(interval, [id, null, x]);
}
// Kefir.sequentially()
var sequentiallyHelperFn = function(){
if (this.xs.length === 0) {
return END;
}
if (this.xs.length === 1){
return Kefir.bunch(this.xs[0], END);
}
return this.xs.shift();
}
Kefir.sequentially = function(interval, xs){
return new FromPollStream(interval, [sequentiallyHelperFn, {xs: xs.slice(0)}]);
}
// Kefir.repeatedly()
var repeatedlyHelperFn = function(){
this.i = (this.i + 1) % this.xs.length;
return this.xs[this.i];
}
Kefir.repeatedly = function(interval, xs){
return new FromPollStream(interval, [repeatedlyHelperFn, {i: -1, xs: xs}]);
}

@@ -74,2 +74,15 @@ function noop(){}

function getFn(fn, context) {
if (isFn(fn)) {
return fn;
} else {
/*jshint eqnull:true */
if (context == null || !isFn(context[fn])) {
throw new Error('not a function: ' + fn + ' in ' + context);
} else {
return context[fn];
}
}
}
function callFn(fnMeta, moreArgs){

@@ -89,9 +102,5 @@ // fnMeta = [

} else {
fn = fnMeta[0];
context = fnMeta[1];
fn = getFn(fnMeta[0], context);
args = restArgs(fnMeta, 2, true);
/*jshint eqnull:true */
if (!isFn(fn) && context != null) {
fn = context[fn];
}
}

@@ -105,7 +114,3 @@ if (moreArgs){

}
if (isFn(fn)) {
return args ? fn.apply(context, args) : fn.call(context);
} else {
throw new Error('not a function ' + fn);
}
return args ? fn.apply(context, args) : fn.call(context);
}

@@ -167,2 +172,12 @@

var now = Date.now ?
function() { return Date.now() } :
function() { return new Date().getTime() };
function get(map, key, notFound){
if (map && key in map) {
return map[key];
} else {
return notFound;
}
}

@@ -184,12 +184,15 @@ // node --expose-gc test-memory-usage.js

var tmpSingleBase = baseKefir();
createNObservable('Kefir', 700, function(){
return baseKefir().toProperty(1);
return tmpSingleBase.toProperty(1);
})
var tmpSingleBase = baseRx();
createNObservable('Rx', 700, function(){
return baseRx().publishValue(1).refCount()
return tmpSingleBase.publishValue(1).refCount()
})
var tmpSingleBase = baseBacon();
createNObservable('Bacon', 700, function(){
return baseBacon().toProperty(1);
return tmpSingleBase.toProperty(1);
})

@@ -202,8 +205,10 @@

var tmpSingleBase = baseKefir().toProperty(1);
createNObservable('Kefir', 700, function(){
return baseKefir().toProperty(1).changes();
return tmpSingleBase.changes();
})
var tmpSingleBase = baseBacon().toProperty(1);
createNObservable('Bacon', 700, function(){
return baseBacon().toProperty(1).changes();
return tmpSingleBase.changes();
})

@@ -216,12 +221,15 @@

var tmpSingleBase = baseKefir();
createNObservable('Kefir', 700, function(){
return baseKefir().map(noop);
return tmpSingleBase.map(noop);
})
var tmpSingleBase = baseRx();
createNObservable('Rx', 700, function(){
return baseRx().map(noop);
return tmpSingleBase.map(noop);
})
var tmpSingleBase = baseBacon();
createNObservable('Bacon', 700, function(){
return baseBacon().map(noop);
return tmpSingleBase.map(noop);
})

@@ -234,12 +242,15 @@

var tmpSingleBase = baseKefir();
createNObservable('Kefir', 700, function(){
return baseKefir().filter(noop);
return tmpSingleBase.filter(noop);
})
var tmpSingleBase = baseRx();
createNObservable('Rx', 700, function(){
return baseRx().filter(noop);
return tmpSingleBase.filter(noop);
})
var tmpSingleBase = baseBacon();
createNObservable('Bacon', 700, function(){
return baseBacon().filter(noop);
return tmpSingleBase.filter(noop);
})

@@ -252,12 +263,15 @@

var tmpSingleBase = baseKefir();
createNObservable('Kefir', 700, function(){
return baseKefir().skipDuplicates(noop);
return tmpSingleBase.skipDuplicates(noop);
})
var tmpSingleBase = baseRx();
createNObservable('Rx', 700, function(){
return baseRx().distinctUntilChanged(noop);
return tmpSingleBase.distinctUntilChanged(noop);
})
var tmpSingleBase = baseBacon();
createNObservable('Bacon', 700, function(){
return baseBacon().skipDuplicates(noop);
return tmpSingleBase.skipDuplicates(noop);
})

@@ -270,12 +284,15 @@

var tmpSingleBase = baseKefir();
createNObservable('Kefir', 700, function(){
return baseKefir().scan(0, noop);
return tmpSingleBase.scan(0, noop);
})
var tmpSingleBase = baseRx();
createNObservable('Rx', 700, function(){
return baseRx().scan(0, noop);
return tmpSingleBase.scan(0, noop);
})
var tmpSingleBase = baseBacon();
createNObservable('Bacon', 700, function(){
return baseBacon().scan(0, noop);
return tmpSingleBase.scan(0, noop);
})

@@ -298,16 +315,31 @@

title('.later(0, 1)')
createNObservable('Kefir', 700, function(){
return Kefir.later(0, 1);
})
createNObservable('Bacon', 700, function(){
return Bacon.later(0, 1);
})
title('.take(5)')
var tmpSingleBase = baseKefir();
createNObservable('Kefir', 700, function(){
return baseKefir().take(5);
return tmpSingleBase.take(5);
})
var tmpSingleBase = baseRx();
createNObservable('Rx', 700, function(){
return baseRx().take(5);
return tmpSingleBase.take(5);
})
var tmpSingleBase = baseBacon();
createNObservable('Bacon', 700, function(){
return baseBacon().take(5);
return tmpSingleBase.take(5);
})

@@ -318,14 +350,56 @@

title('.delay(1)')
var tmpSingleBase = baseKefir();
createNObservable('Kefir', 700, function(){
return tmpSingleBase.delay(1);
})
var tmpSingleBase = baseRx();
createNObservable('Rx', 700, function(){
return tmpSingleBase.delay(1);
})
var tmpSingleBase = baseBacon();
createNObservable('Bacon', 700, function(){
return tmpSingleBase.delay(1);
})
title('.throttle(1)')
var tmpSingleBase = baseKefir();
createNObservable('Kefir', 700, function(){
return tmpSingleBase.throttle(1);
})
var tmpSingleBase = baseRx();
createNObservable('Rx', 700, function(){
return tmpSingleBase.throttle(1);
})
var tmpSingleBase = baseBacon();
createNObservable('Bacon', 700, function(){
return tmpSingleBase.throttle(1);
})
title('.flatMap(noop)')
var tmpSingleBase = baseKefir();
createNObservable('Kefir', 700, function(){
return baseKefir().flatMap(noop);
return tmpSingleBase.flatMap(noop);
})
var tmpSingleBase = baseRx();
createNObservable('Rx', 700, function(){
return baseRx().flatMap(noop);
return tmpSingleBase.flatMap(noop);
})
var tmpSingleBase = baseBacon();
createNObservable('Bacon', 700, function(){
return baseBacon().flatMap(noop);
return tmpSingleBase.flatMap(noop);
})

@@ -338,12 +412,15 @@

var tmpSingleBase = baseKefir();
createNObservable('Kefir', 700, function(){
return baseKefir().combine(baseKefir(), noop);
return tmpSingleBase.combine(baseKefir(), noop);
})
var tmpSingleBase = baseRx();
createNObservable('Rx', 700, function(){
return baseRx().combineLatest(baseRx(), noop);
return tmpSingleBase.combineLatest(baseRx(), noop);
})
var tmpSingleBase = baseBacon();
createNObservable('Bacon', 700, function(){
return baseBacon().combine(baseBacon(), noop);
return tmpSingleBase.combine(baseBacon(), noop);
})

@@ -357,8 +434,10 @@

var tmpSingleBase = baseKefir();
createNObservable('Kefir', 700, function(){
return baseKefir().toProperty(1).sampledBy(baseKefir(), noop);
return tmpSingleBase.toProperty(1).sampledBy(baseKefir(), noop);
})
var tmpSingleBase = baseBacon();
createNObservable('Bacon', 700, function(){
return baseBacon().toProperty(1).sampledBy(baseBacon(), noop);
return tmpSingleBase.toProperty(1).sampledBy(baseBacon(), noop);
})

@@ -400,1 +479,13 @@

title('.fromBinder(noop)')
createNObservable('Kefir', 700, function(){
return Kefir.fromBinder(noop);
})
createNObservable('Bacon', 700, function(){
return Bacon.fromBinder(noop);
})

@@ -74,4 +74,35 @@ var Kefir = require('../../dist/kefir.js');

it("with context and args", function() {
var context = {
send: null
}
var obs = Kefir.fromBinder(function(a, b, send){
context.send = send;
context.a = a;
context.b = b;
}, context, 'a', 'b');
var result = helpers.getOutputAndErrors(obs);
expect(context.send).toEqual(jasmine.any(Function))
expect(context.a).toBe('a')
expect(context.b).toBe('b')
context.send(1);
expect(result).toEqual({
ended: false,
xs: [1],
errors: []
});
});
});
var Kefir = require('../../dist/kefir.js');
var helpers = require('../test-helpers');
var sinon = require('sinon');

@@ -8,6 +9,12 @@

var clock;
beforeEach(function() {
jasmine.Clock.useMock();
clock = sinon.useFakeTimers();
});
afterEach(function() {
clock.restore();
});
function pollArray(values, interval){

@@ -34,15 +41,15 @@ return Kefir.fromPoll(interval, function(){

jasmine.Clock.tick(10);
clock.tick(10);
expect(log).toEqual([]);
jasmine.Clock.tick(21);
clock.tick(21);
expect(log).toEqual([1]);
jasmine.Clock.tick(30);
clock.tick(30);
expect(log).toEqual([1, 2]);
jasmine.Clock.tick(30);
clock.tick(30);
expect(log).toEqual([1, 2, 3]);
jasmine.Clock.tick(30);
clock.tick(30);
expect(stream.isEnded()).toBe(true);

@@ -49,0 +56,0 @@ expect(log).toEqual([1, 2, 3]);

var Kefir = require('../../dist/kefir.js');
var helpers = require('../test-helpers');
var sinon = require('sinon');

@@ -8,6 +9,12 @@

var clock;
beforeEach(function() {
jasmine.Clock.useMock();
clock = sinon.useFakeTimers();
});
afterEach(function() {
clock.restore();
});
it("ok", function(){

@@ -21,15 +28,15 @@

jasmine.Clock.tick(10);
clock.tick(10);
expect(result.xs).toEqual([]);
jasmine.Clock.tick(21);
clock.tick(21);
expect(result.xs).toEqual([2]);
jasmine.Clock.tick(30);
clock.tick(30);
expect(result.xs).toEqual([2, 2]);
jasmine.Clock.tick(15);
clock.tick(15);
expect(result.xs).toEqual([2, 2]);
jasmine.Clock.tick(15);
clock.tick(15);
expect(result.xs).toEqual([2, 2, 2]);

@@ -36,0 +43,0 @@

var Kefir = require('../../dist/kefir.js');
var helpers = require('../test-helpers');
var sinon = require('sinon');

@@ -8,6 +9,12 @@

var clock;
beforeEach(function() {
jasmine.Clock.useMock();
clock = sinon.useFakeTimers();
});
afterEach(function() {
clock.restore();
});
it("ok", function(){

@@ -21,18 +28,18 @@

jasmine.Clock.tick(10);
clock.tick(10);
expect(result.xs).toEqual([]);
jasmine.Clock.tick(21);
clock.tick(21);
expect(result.xs).toEqual([2]);
jasmine.Clock.tick(30);
clock.tick(30);
expect(result.xs).toEqual([2, 4]);
jasmine.Clock.tick(15);
clock.tick(15);
expect(result.xs).toEqual([2, 4]);
jasmine.Clock.tick(15);
clock.tick(15);
expect(result.xs).toEqual([2, 4, 2]);
jasmine.Clock.tick(90);
clock.tick(90);
expect(result.xs).toEqual([2, 4, 2, 4, 2, 4]);

@@ -39,0 +46,0 @@

var Kefir = require('../../dist/kefir.js');
var helpers = require('../test-helpers');
var sinon = require('sinon');
describe("Kefir.sequentially()", function(){
var clock;
beforeEach(function() {
jasmine.Clock.useMock();
clock = sinon.useFakeTimers();
});
afterEach(function() {
clock.restore();
});
it("ok", function(){

@@ -20,9 +28,9 @@

jasmine.Clock.tick(10);
clock.tick(10);
expect(result.xs).toEqual([]);
jasmine.Clock.tick(21);
clock.tick(21);
expect(result.xs).toEqual([2]);
jasmine.Clock.tick(30);
clock.tick(30);
expect(result.xs).toEqual([2, 4]);

@@ -29,0 +37,0 @@ expect(result.ended).toEqual(true);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc