Comparing version 0.2.5 to 0.2.6
{ | ||
"name": "kefir", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"homepage": "https://github.com/pozadi/kefir", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -1,2 +0,2 @@ | ||
/*! kefir addon - 0.2.5 | ||
/*! An addon for Kefir.js v0.2.6 | ||
* https://github.com/pozadi/kefir | ||
@@ -36,3 +36,12 @@ */ | ||
// $.fn.asKefirProperty = function(event, selector, getter) { ... } | ||
$.fn.asKefirProperty = function(eventName, selector, getter) { | ||
if (getter == null) { | ||
getter = selector; | ||
selector = null; | ||
} | ||
getter = Kefir.Fn(getter); | ||
return this.asKefirStream(eventName, selector, getter) | ||
.toProperty(getter.invoke()) | ||
.setName('asKefirProperty'); | ||
} | ||
@@ -39,0 +48,0 @@ |
@@ -1,6 +0,6 @@ | ||
/*! kefir addon - 0.2.5 | ||
/*! An addon for Kefir.js v0.2.6 | ||
* https://github.com/pozadi/kefir | ||
*/ | ||
!function(a){"use strict";function b(a,b){b.fn.asKefirStream=function(b,c,d){var e=this;return null==d&&null!=c&&"string"!=typeof c&&(d=c,c=null),d=d&&a.Fn(d),a.fromBinder(function(a){var f;return f=d?function(){a.emit(d.applyWithContext(this,arguments))}:a.emit,e.on(b,c,f),["off",e,b,c,f]}).setName("asKefirStream")}}if("function"==typeof define&&define.amd)define(["kefir","jquery"],b);else if("object"==typeof module&&"object"==typeof exports){var c=require("kefir"),d=require("jquery");b(c,d)}else b(a.Kefir,a.jQuery)}(this); | ||
!function(a){"use strict";function b(a,b){b.fn.asKefirStream=function(b,c,d){var e=this;return null==d&&null!=c&&"string"!=typeof c&&(d=c,c=null),d=d&&a.Fn(d),a.fromBinder(function(a){var f;return f=d?function(){a.emit(d.applyWithContext(this,arguments))}:a.emit,e.on(b,c,f),["off",e,b,c,f]}).setName("asKefirStream")},b.fn.asKefirProperty=function(b,c,d){return null==d&&(d=c,c=null),d=a.Fn(d),this.asKefirStream(b,c,d).toProperty(d.invoke()).setName("asKefirProperty")}}if("function"==typeof define&&define.amd)define(["kefir","jquery"],b);else if("object"==typeof module&&"object"==typeof exports){var c=require("kefir"),d=require("jquery");b(c,d)}else b(a.Kefir,a.jQuery)}(this); | ||
//# sourceMappingURL=kefir-jquery.min.js.map |
@@ -1,2 +0,2 @@ | ||
/*! kefir - 0.2.5 | ||
/*! Kefir.js v0.2.6 | ||
* https://github.com/pozadi/kefir | ||
@@ -61,3 +61,3 @@ */ | ||
if (context == null || !isFn(context[fn])) { | ||
throw new Error('not a function: ' + fn + ' in ' + context); | ||
throw new Error('Not a function: ' + fn + ' in context: ' + context); | ||
} else { | ||
@@ -178,2 +178,4 @@ return context[fn]; | ||
, length, i; | ||
if (a.length === 0) { return b } | ||
if (b.length === 0) { return a } | ||
length = a.length; | ||
@@ -190,2 +192,20 @@ for (i = 0; i < length; i++, j++) { | ||
function find(arr, value) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
if (arr[i] === value) { return i } | ||
} | ||
return -1; | ||
} | ||
function findByPred(arr, pred) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
if (pred(arr[i])) { return i } | ||
} | ||
return -1; | ||
} | ||
function cloneArray(input) { | ||
@@ -201,2 +221,27 @@ var length = input.length | ||
function remove(input, index) { | ||
var length = input.length | ||
, result, i, j; | ||
if (index >= 0 && index < length) { | ||
if (length === 1) { | ||
return []; | ||
} else { | ||
result = new Array(length - 1); | ||
for (i = 0, j = 0; i < length; i++) { | ||
if (i !== index) { | ||
result[j] = input[i]; | ||
j++; | ||
} | ||
} | ||
return result; | ||
} | ||
} else { | ||
return input; | ||
} | ||
} | ||
function removeByPred(input, pred) { | ||
return remove(input, findByPred(input, pred)); | ||
} | ||
function map(input, fn) { | ||
@@ -212,2 +257,8 @@ var length = input.length | ||
function forEach(arr, fn) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { fn(arr[i]) } | ||
} | ||
function fillArray(arr, value) { | ||
@@ -222,10 +273,3 @@ var length = arr.length | ||
function contains(arr, value) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
if (arr[i] === value) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
return find(arr, value) !== -1; | ||
} | ||
@@ -436,6 +480,35 @@ | ||
function normFnMeta(fnMeta) { | ||
if (fnMeta instanceof _Fn) { | ||
return fnMeta; | ||
} else { | ||
if (isFn(fnMeta)) { | ||
return { | ||
fn: fnMeta, | ||
context: null, | ||
args: [] | ||
}; | ||
} else { | ||
if (isArrayLike(fnMeta)) { | ||
return { | ||
fn: getFn(fnMeta[0], fnMeta[1]), | ||
context: (fnMeta[1] == null ? null : fnMeta[1]), | ||
args: rest(fnMeta, 2, []) | ||
}; | ||
} else { | ||
throw new Error('Object isn\'t a function, and can\'t be converted to it: ' + fnMeta); | ||
} | ||
} | ||
} | ||
} | ||
function applyFnMeta(fnMeta, args) { | ||
fnMeta = normFnMeta(fnMeta); | ||
return apply(fnMeta.fn, fnMeta.context, concat(fnMeta.args, args)); | ||
} | ||
function _Fn(fnMeta, length) { | ||
this.context = (fnMeta[1] == null) ? null : fnMeta[1]; | ||
this.fn = getFn(fnMeta[0], this.context); | ||
this.args = rest(fnMeta, 2, []); | ||
this.context = fnMeta.context; | ||
this.fn = fnMeta.fn; | ||
this.args = fnMeta.args; | ||
this.invoke = bind(this.fn, this.context, this.args, length); | ||
@@ -450,7 +523,3 @@ } | ||
if (this.context === null) { | ||
if (this.args.length === 0) { | ||
return apply(this.fn, context, args); | ||
} else { | ||
return apply(this.fn, context, concat(this.args, args)); | ||
} | ||
return apply(this.fn, context, concat(this.args, args)); | ||
} else { | ||
@@ -465,14 +534,3 @@ return this.apply(args); | ||
} else { | ||
if (length == null) { | ||
length = 100; | ||
} | ||
if (isFn(fnMeta)) { | ||
return new _Fn([fnMeta], length); | ||
} else { | ||
if (isArrayLike(fnMeta)) { | ||
return new _Fn(fnMeta, length); | ||
} else { | ||
throw new Error('can\'t convert to Fn ' + fnMeta); | ||
} | ||
} | ||
return new _Fn(normFnMeta(fnMeta), length == null ? 100 : length); | ||
} | ||
@@ -501,52 +559,50 @@ } | ||
function Subscribers() { | ||
this.value = []; | ||
this.end = []; | ||
this.any = []; | ||
this.total = 0; | ||
this._fns = []; | ||
} | ||
extend(Subscribers, { | ||
callOne: function(fn, event) { | ||
if (fn.type === 'any') { | ||
fn.invoke(event); | ||
} else if (fn.type === event.type) { | ||
if (fn.type === 'value') { | ||
fn.invoke(event.value); | ||
} else { | ||
fn.invoke(); | ||
} | ||
} | ||
}, | ||
callOnce: function(type, fnMeta, event) { | ||
if (type === 'any') { | ||
applyFnMeta(fnMeta, [event]); | ||
} else if (type === event.type) { | ||
if (type === 'value') { | ||
applyFnMeta(fnMeta, [event.value]); | ||
} else { | ||
applyFnMeta(fnMeta, []); | ||
} | ||
} | ||
} | ||
}); | ||
extend(Subscribers.prototype, { | ||
add: function(type, fn) { | ||
var length = (type === 'end' ? 0 : 1); | ||
this[type].push(Fn(fn, length, true)); | ||
this.total++; | ||
fn = Fn(fn, type === 'end' ? 0 : 1); | ||
fn.type = type; | ||
this._fns = concat(this._fns, [fn]); | ||
}, | ||
remove: function(type, fn) { | ||
var subs = this[type] | ||
, length = subs.length | ||
, i; | ||
fn = Fn(fn); | ||
for (i = 0; i < length; i++) { | ||
if (Fn.isEqual(subs[i], fn)) { | ||
subs.splice(i, 1); | ||
this.total--; | ||
return; | ||
} | ||
} | ||
this._fns = removeByPred(this._fns, function(x) { | ||
return x.type === type && Fn.isEqual(x, fn); | ||
}); | ||
}, | ||
call: function(type, x) { | ||
var subs = this[type] | ||
, length = subs.length | ||
, i; | ||
if (length !== 0) { | ||
if (length === 1) { | ||
if (type === 'end') { | ||
subs[0].invoke(); | ||
} else { | ||
subs[0].invoke(x); | ||
} | ||
} else { | ||
subs = cloneArray(subs); | ||
for (i = 0; i < length; i++) { | ||
if (type === 'end') { | ||
subs[i].invoke(); | ||
} else { | ||
subs[i].invoke(x); | ||
} | ||
} | ||
} | ||
callAll: function(event) { | ||
var fns = this._fns; | ||
for (var i = 0; i < fns.length; i++) { | ||
Subscribers.callOne(fns[i], event); | ||
} | ||
}, | ||
isEmpty: function() { | ||
return this.total === 0; | ||
return this._fns.length === 0; | ||
} | ||
@@ -559,2 +615,14 @@ }); | ||
// Events | ||
function Event(type, value, current) { | ||
return {type: type, value: value, current: !!current}; | ||
} | ||
var CURRENT_END = Event('end', undefined, true); | ||
// Observable | ||
@@ -595,4 +663,3 @@ | ||
if (this._alive) { | ||
this._subscribers.call(type, x); | ||
this._subscribers.call('any', {type: type, value: x, current: !!isCurrent}); | ||
this._subscribers.callAll(Event(type, x, isCurrent)); | ||
if (type === 'end') { this._clear() } | ||
@@ -602,15 +669,2 @@ } | ||
_callWithCurrent: function(fnType, fn, valueType, value) { | ||
fn = Fn(fn); | ||
if (fnType === valueType) { | ||
if (fnType === 'value') { | ||
fn.invoke(value); | ||
} else { | ||
fn.invoke(); | ||
} | ||
} else if (fnType === 'any') { | ||
fn.invoke({type: valueType, value: value, current: true}); | ||
} | ||
}, | ||
on: function(type, fn) { | ||
@@ -621,3 +675,3 @@ if (this._alive) { | ||
} else { | ||
this._callWithCurrent(type, fn, 'end'); | ||
Subscribers.callOnce(type, fn, CURRENT_END); | ||
} | ||
@@ -637,9 +691,9 @@ return this; | ||
onValue: function(fn) { this.on('value', fn) }, | ||
onEnd: function(fn) { this.on('end', fn) }, | ||
onAny: function(fn) { this.on('any', fn) }, | ||
onValue: function(fn) { return this.on('value', fn) }, | ||
onEnd: function(fn) { return this.on('end', fn) }, | ||
onAny: function(fn) { return this.on('any', fn) }, | ||
offValue: function(fn) { this.off('value', fn) }, | ||
offEnd: function(fn) { this.off('end', fn) }, | ||
offAny: function(fn) { this.off('any', fn) } | ||
offValue: function(fn) { return this.off('value', fn) }, | ||
offEnd: function(fn) { return this.off('end', fn) }, | ||
offAny: function(fn) { return this.off('any', fn) } | ||
@@ -694,4 +748,3 @@ }); | ||
if (!isCurrent) { | ||
this._subscribers.call(type, x); | ||
this._subscribers.call('any', {type: type, value: x, current: false}); | ||
this._subscribers.callAll(Event(type, x)); | ||
} | ||
@@ -709,6 +762,6 @@ if (type === 'value') { this._current = x } | ||
if (this._current !== NOTHING) { | ||
this._callWithCurrent(type, fn, 'value', this._current); | ||
Subscribers.callOnce(type, fn, Event('value', this._current, true)); | ||
} | ||
if (!this._alive) { | ||
this._callWithCurrent(type, fn, 'end'); | ||
Subscribers.callOnce(type, fn, CURRENT_END); | ||
} | ||
@@ -868,49 +921,113 @@ return this; | ||
// .merge() | ||
function _AbstractPool(options) { | ||
Stream.call(this); | ||
function Merge(sources) { | ||
Stream.call(this); | ||
if (sources.length === 0) { | ||
this._send('end'); | ||
} else { | ||
this._sources = sources; | ||
this._aliveCount = 0; | ||
this._queueLim = get(options, 'queueLim', 0); // -1...∞ | ||
this._concurLim = get(options, 'concurLim', -1); // -1, 1...∞ | ||
this._drop = get(options, 'drop', 'new'); // old, new | ||
if (this._concurLim === 0) { | ||
throw new Error('options.concurLim can\'t be 0'); | ||
} | ||
this._queue = []; | ||
this._curSources = []; | ||
this._activating = false; | ||
} | ||
inherit(Merge, Stream, { | ||
inherit(_AbstractPool, Stream, { | ||
_name: 'merge', | ||
_name: 'abstractPool', | ||
_onActivation: function() { | ||
var length = this._sources.length, | ||
i; | ||
this._aliveCount = length; | ||
for (i = 0; i < length; i++) { | ||
this._sources[i].onAny([this._handleAny, this]); | ||
_add: function(obs) { | ||
if (this._concurLim === -1 || this._curSources.length < this._concurLim) { | ||
this._addToCur(obs); | ||
} else { | ||
if (this._queueLim === -1 || this._queue.length < this._queueLim) { | ||
this._addToQueue(obs); | ||
} else if (this._drop === 'old') { | ||
this._removeOldest(); | ||
this._add(obs); | ||
} | ||
} | ||
}, | ||
_addAll: function(obss) { | ||
var $ = this; | ||
forEach(obss, function(obs) { $._add(obs) }); | ||
}, | ||
_remove: function(obs) { | ||
if (this._removeCur(obs) === -1) { | ||
this._removeQueue(obs); | ||
} | ||
}, | ||
_onDeactivation: function() { | ||
var length = this._sources.length, | ||
i; | ||
for (i = 0; i < length; i++) { | ||
this._sources[i].offAny([this._handleAny, this]); | ||
_addToQueue: function(obs) { | ||
this._queue = concat(this._queue, [obs]); | ||
}, | ||
_addToCur: function(obs) { | ||
this._curSources = concat(this._curSources, [obs]); | ||
if (this._active) { this._sub(obs) } | ||
}, | ||
_sub: function(obs) { | ||
obs.onAny([this._handleSubAny, this]); | ||
obs.onEnd([this._removeCur, this, obs]); | ||
}, | ||
_unsub: function(obs) { | ||
obs.offAny([this._handleSubAny, this]); | ||
obs.offEnd([this._removeCur, this, obs]); | ||
}, | ||
_handleSubAny: function(event) { | ||
if (event.type === 'value') { | ||
this._send('value', event.value, event.current && this._activating); | ||
} | ||
}, | ||
_handleAny: function(event) { | ||
if (event.type === 'value') { | ||
this._send('value', event.value, event.current); | ||
} else { | ||
this._aliveCount--; | ||
if (this._aliveCount === 0) { | ||
this._send('end', null, event.current); | ||
_removeQueue: function(obs) { | ||
var index = find(this._queue, obs); | ||
this._queue = remove(this._queue, index); | ||
return index; | ||
}, | ||
_removeCur: function(obs) { | ||
if (this._active) { this._unsub(obs) } | ||
var index = find(this._curSources, obs); | ||
this._curSources = remove(this._curSources, index); | ||
if (index !== -1) { | ||
if (this._queue.length !== 0) { | ||
this._pullQueue(); | ||
} else if (this._curSources.length === 0) { | ||
this._onEmpty(); | ||
} | ||
} | ||
return index; | ||
}, | ||
_removeOldest: function() { | ||
this._removeCur(this._curSources[0]); | ||
}, | ||
_pullQueue: function() { | ||
if (this._queue.length !== 0) { | ||
this._queue = cloneArray(this._queue); | ||
this._addToCur(this._queue.shift()); | ||
} | ||
}, | ||
_onActivation: function() { | ||
var sources = this._curSources | ||
, i; | ||
this._activating = true; | ||
for (i = 0; i < sources.length; i++) { this._sub(sources[i]) } | ||
this._activating = false; | ||
}, | ||
_onDeactivation: function() { | ||
var sources = this._curSources | ||
, i; | ||
for (i = 0; i < sources.length; i++) { this._unsub(sources[i]) } | ||
}, | ||
_isEmpty: function() { return this._curSources.length === 0 }, | ||
_onEmpty: function() {}, | ||
_clear: function() { | ||
Stream.prototype._clear.call(this); | ||
this._sources = null; | ||
this._queue = null; | ||
this._curSources = null; | ||
} | ||
@@ -920,2 +1037,22 @@ | ||
// .merge() | ||
var MergeLike = { | ||
_onEmpty: function() { | ||
if (this._initialised) { this._send('end', null, this._activating) } | ||
} | ||
}; | ||
function Merge(sources) { | ||
_AbstractPool.call(this); | ||
if (sources.length === 0) { this._send('end') } else { this._addAll(sources) } | ||
this._initialised = true; | ||
} | ||
inherit(Merge, _AbstractPool, extend({_name: 'merge'}, MergeLike)); | ||
Kefir.merge = function() { | ||
@@ -932,4 +1069,139 @@ return new Merge(agrsToArray(arguments)); | ||
// .concat() | ||
function Concat(sources) { | ||
_AbstractPool.call(this, {concurLim: 1, queueLim: -1}); | ||
if (sources.length === 0) { this._send('end') } else { this._addAll(sources) } | ||
this._initialised = true; | ||
} | ||
inherit(Concat, _AbstractPool, extend({_name: 'concat'}, MergeLike)); | ||
Kefir.concat = function() { | ||
return new Concat(agrsToArray(arguments)); | ||
} | ||
Observable.prototype.concat = function(other) { | ||
return Kefir.concat([this, other]); | ||
} | ||
// .pool() | ||
function Pool() { | ||
_AbstractPool.call(this); | ||
} | ||
inherit(Pool, _AbstractPool, { | ||
_name: 'pool', | ||
add: function(obs) { | ||
this._add(obs); | ||
return this; | ||
}, | ||
remove: function(obs) { | ||
this._remove(obs); | ||
return this; | ||
} | ||
}); | ||
Kefir.pool = function() { | ||
return new Pool(); | ||
} | ||
// .flatMap() | ||
function FlatMap(source, fn, options) { | ||
_AbstractPool.call(this, options); | ||
this._source = source; | ||
this._fn = fn ? Fn(fn, 1) : null; | ||
this._mainEnded = false; | ||
this._lastCurrent = null; | ||
} | ||
inherit(FlatMap, _AbstractPool, { | ||
_onActivation: function() { | ||
_AbstractPool.prototype._onActivation.call(this); | ||
this._activating = true; | ||
this._source.onAny([this._handleMainSource, this]); | ||
this._activating = false; | ||
}, | ||
_onDeactivation: function() { | ||
_AbstractPool.prototype._onDeactivation.call(this); | ||
this._source.offAny([this._handleMainSource, this]); | ||
}, | ||
_handleMainSource: function(event) { | ||
if (event.type === 'value') { | ||
if (!event.current || this._lastCurrent !== event.value) { | ||
this._add(this._fn ? this._fn.invoke(event.value) : event.value); | ||
} | ||
this._lastCurrent = event.value; | ||
} else { | ||
if (this._isEmpty()) { | ||
this._send('end', null, event.current); | ||
} else { | ||
this._mainEnded = true; | ||
} | ||
} | ||
}, | ||
_onEmpty: function() { | ||
if (this._mainEnded) { this._send('end') } | ||
}, | ||
_clear: function() { | ||
_AbstractPool.prototype._clear.call(this); | ||
this._source = null; | ||
this._lastCurrent = null; | ||
} | ||
}); | ||
Observable.prototype.flatMap = function(fn) { | ||
return new FlatMap(this, fn) | ||
.setName(this, 'flatMap'); | ||
} | ||
Observable.prototype.flatMapLatest = function(fn) { | ||
return new FlatMap(this, fn, {concurLim: 1, drop: 'old'}) | ||
.setName(this, 'flatMapLatest'); | ||
} | ||
Observable.prototype.flatMapFirst = function(fn) { | ||
return new FlatMap(this, fn, {concurLim: 1}) | ||
.setName(this, 'flatMapFirst'); | ||
} | ||
Observable.prototype.flatMapConcat = function(fn) { | ||
return new FlatMap(this, fn, {queueLim: -1, concurLim: 1}) | ||
.setName(this, 'flatMapConcat'); | ||
} | ||
Observable.prototype.flatMapWithConcurrencyLimit = function(fn, limit) { | ||
var result; | ||
if (limit === 0) { | ||
result = Kefir.never(); | ||
} else { | ||
if (limit < 0) { limit = -1 } | ||
result = new FlatMap(this, fn, {queueLim: -1, concurLim: limit}); | ||
} | ||
return result.setName(this, 'flatMapWithConcurrencyLimit'); | ||
} | ||
// .sampledBy() | ||
@@ -1037,4 +1309,2 @@ | ||
// .combine() | ||
@@ -1052,160 +1322,2 @@ | ||
// .pool() | ||
function _AbstractPool() { | ||
Stream.call(this); | ||
this._sources = []; | ||
} | ||
inherit(_AbstractPool, Stream, { | ||
_name: 'abstractPool', | ||
_sub: function(obs) { | ||
obs.onAny([this._handleSubAny, this]); | ||
obs.onEnd([this._remove, this, obs]); | ||
}, | ||
_unsub: function(obs) { | ||
obs.offAny([this._handleSubAny, this]); | ||
obs.offEnd([this._remove, this, obs]); | ||
}, | ||
_handleSubAny: function(event) { | ||
if (event.type === 'value') { | ||
this._send('value', event.value, event.current); | ||
} | ||
}, | ||
_add: function(obs) { | ||
this._sources.push(obs); | ||
if (this._active) { | ||
this._sub(obs); | ||
} | ||
}, | ||
_remove: function(obs) { | ||
if (this._active) { | ||
this._unsub(obs); | ||
} | ||
for (var i = 0; i < this._sources.length; i++) { | ||
if (this._sources[i] === obs) { | ||
this._sources.splice(i, 1); | ||
return; | ||
} | ||
} | ||
}, | ||
_onActivation: function() { | ||
var sources = cloneArray(this._sources); | ||
for (var i = 0; i < sources.length; i++) { | ||
this._sub(sources[i]); | ||
} | ||
}, | ||
_onDeactivation: function() { | ||
for (var i = 0; i < this._sources.length; i++) { | ||
this._unsub(this._sources[i]); | ||
} | ||
} | ||
}); | ||
function Pool() { | ||
_AbstractPool.call(this); | ||
} | ||
inherit(Pool, _AbstractPool, { | ||
_name: 'pool', | ||
add: function(obs) { | ||
this._add(obs); | ||
return this; | ||
}, | ||
remove: function(obs) { | ||
this._remove(obs); | ||
return this; | ||
} | ||
}); | ||
Kefir.pool = function() { | ||
return new Pool(); | ||
} | ||
// .flatMap() | ||
function FlatMap(source, fn) { | ||
_AbstractPool.call(this); | ||
this._source = source; | ||
this._name = source._name + '.flatMap'; | ||
this._fn = fn ? Fn(fn, 1) : null; | ||
this._mainEnded = false; | ||
this._lastValue = null; | ||
} | ||
inherit(FlatMap, _AbstractPool, { | ||
_onActivation: function() { | ||
_AbstractPool.prototype._onActivation.call(this); | ||
this._source.onAny([this._handleMainSource, this]); | ||
}, | ||
_onDeactivation: function() { | ||
_AbstractPool.prototype._onDeactivation.call(this); | ||
this._source.offAny([this._handleMainSource, this]); | ||
}, | ||
_handleMainSource: function(event) { | ||
if (event.type === 'value') { | ||
if (!event.current || this._lastValue !== event.value) { | ||
this._add(this._fn ? this._fn.invoke(event.value) : event.value); | ||
} | ||
this._lastValue = event.value; | ||
} else { | ||
if (this._sources.length === 0) { | ||
this._send('end', null, event.current); | ||
} else { | ||
this._mainEnded = true; | ||
} | ||
} | ||
}, | ||
_remove: function(obs) { | ||
_AbstractPool.prototype._remove.call(this, obs); | ||
if (this._mainEnded && this._sources.length === 0) { | ||
this._send('end'); | ||
} | ||
}, | ||
_clear: function() { | ||
_AbstractPool.prototype._clear.call(this); | ||
this._source = null; | ||
this._lastValue = null; | ||
} | ||
}); | ||
Observable.prototype.flatMap = function(fn) { | ||
return new FlatMap(this, fn); | ||
} | ||
// .flatMapLatest() | ||
// TODO | ||
function produceStream(StreamClass, PropertyClass) { | ||
@@ -1219,2 +1331,3 @@ return function() { return new StreamClass(this, arguments) } | ||
// .toProperty() | ||
@@ -1477,2 +1590,67 @@ | ||
// .debounce(wait, {immediate}) | ||
withOneSource('debounce', { | ||
_init: function(args) { | ||
this._wait = Math.max(0, args[0]); | ||
this._immediate = get(args[1], 'immediate', false); | ||
this._lastAttempt = 0; | ||
this._timeoutId = null; | ||
this._laterValue = null; | ||
this._endLater = false; | ||
var $ = this; | ||
this._$later = function() { $._later() }; | ||
}, | ||
_free: function() { | ||
this._laterValue = null; | ||
this._$later = null; | ||
}, | ||
_handleValue: function(x, isCurrent) { | ||
if (isCurrent) { | ||
this._send('value', x, isCurrent); | ||
} else { | ||
this._lastAttempt = now(); | ||
if (this._immediate && !this._timeoutId) { | ||
this._send('value', x); | ||
} | ||
if (!this._timeoutId) { | ||
this._timeoutId = setTimeout(this._$later, this._wait); | ||
} | ||
if (!this._immediate) { | ||
this._laterValue = x; | ||
} | ||
} | ||
}, | ||
_handleEnd: function(__, isCurrent) { | ||
if (isCurrent) { | ||
this._send('end', null, isCurrent); | ||
} else { | ||
if (this._timeoutId && !this._immediate) { | ||
this._endLater = true; | ||
} else { | ||
this._send('end'); | ||
} | ||
} | ||
}, | ||
_later: function() { | ||
var last = now() - this._lastAttempt; | ||
if (last < this._wait && last >= 0) { | ||
this._timeoutId = setTimeout(this._$later, this._wait - last); | ||
} else { | ||
this._timeoutId = null; | ||
if (!this._immediate) { | ||
this._send('value', this._laterValue); | ||
this._laterValue = null; | ||
} | ||
if (this._endLater) { | ||
this._send('end'); | ||
} | ||
} | ||
} | ||
}); | ||
// .throttle(wait, {leading, trailing}) | ||
@@ -1482,15 +1660,15 @@ | ||
_init: function(args) { | ||
this._wait = args[0]; | ||
this._wait = Math.max(0, args[0]); | ||
this._leading = get(args[1], 'leading', true); | ||
this._trailing = get(args[1], 'trailing', true); | ||
this._trailingCallValue = null; | ||
this._trailingCallTimeoutId = null; | ||
this._endAfterTrailingCall = false; | ||
this._trailingValue = null; | ||
this._timeoutId = null; | ||
this._endLater = false; | ||
this._lastCallTime = 0; | ||
var $ = this; | ||
this._$makeTrailingCall = function() { $._makeTrailingCall() }; | ||
this._$trailingCall = function() { $._trailingCall() }; | ||
}, | ||
_free: function() { | ||
this._trailingCallValue = null; | ||
this._$makeTrailingCall = null; | ||
this._trailingValue = null; | ||
this._$trailingCall = null; | ||
}, | ||
@@ -1507,7 +1685,9 @@ _handleValue: function(x, isCurrent) { | ||
if (remaining <= 0) { | ||
this._cancelTralingCall(); | ||
this._cancelTraling(); | ||
this._lastCallTime = curTime; | ||
this._send('value', x); | ||
} else if (this._trailing) { | ||
this._scheduleTralingCall(x, remaining); | ||
this._cancelTraling(); | ||
this._trailingValue = x; | ||
this._timeoutId = setTimeout(this._$trailingCall, remaining); | ||
} | ||
@@ -1520,4 +1700,4 @@ } | ||
} else { | ||
if (this._trailingCallTimeoutId) { | ||
this._endAfterTrailingCall = true; | ||
if (this._timeoutId) { | ||
this._endLater = true; | ||
} else { | ||
@@ -1528,21 +1708,14 @@ this._send('end'); | ||
}, | ||
_scheduleTralingCall: function(value, wait) { | ||
if (this._trailingCallTimeoutId) { | ||
this._cancelTralingCall(); | ||
_cancelTraling: function() { | ||
if (this._timeoutId !== null) { | ||
clearTimeout(this._timeoutId); | ||
this._timeoutId = null; | ||
} | ||
this._trailingCallValue = value; | ||
this._trailingCallTimeoutId = setTimeout(this._$makeTrailingCall, wait); | ||
}, | ||
_cancelTralingCall: function() { | ||
if (this._trailingCallTimeoutId !== null) { | ||
clearTimeout(this._trailingCallTimeoutId); | ||
this._trailingCallTimeoutId = null; | ||
} | ||
}, | ||
_makeTrailingCall: function() { | ||
this._send('value', this._trailingCallValue); | ||
this._trailingCallTimeoutId = null; | ||
this._trailingCallValue = null; | ||
_trailingCall: function() { | ||
this._send('value', this._trailingValue); | ||
this._timeoutId = null; | ||
this._trailingValue = null; | ||
this._lastCallTime = !this._leading ? 0 : now(); | ||
if (this._endAfterTrailingCall) { | ||
if (this._endLater) { | ||
this._send('end'); | ||
@@ -1557,3 +1730,2 @@ } | ||
// .delay() | ||
@@ -1563,12 +1735,10 @@ | ||
_init: function(args) { | ||
this._wait = args[0]; | ||
this._wait = Math.max(0, args[0]); | ||
this._buff = []; | ||
var $ = this; | ||
this._shiftBuff = function() { | ||
$._send('value', $._buff.shift()); | ||
} | ||
this._$shiftBuff = function() { $._send('value', $._buff.shift()) } | ||
}, | ||
_free: function() { | ||
this._buff = null; | ||
this._shiftBuff = null; | ||
this._$shiftBuff = null; | ||
}, | ||
@@ -1580,3 +1750,3 @@ _handleValue: function(x, isCurrent) { | ||
this._buff.push(x); | ||
setTimeout(this._shiftBuff, this._wait); | ||
setTimeout(this._$shiftBuff, this._wait); | ||
} | ||
@@ -1693,22 +1863,2 @@ }, | ||
// Kefir.once(x) | ||
function Once(x) { | ||
Stream.call(this); | ||
this._value = x; | ||
} | ||
inherit(Once, Stream, { | ||
_name: 'once', | ||
_onActivation: function() { | ||
this._send('value', this._value); | ||
this._send('end'); | ||
} | ||
}); | ||
Kefir.once = function(x) { | ||
return new Once(x); | ||
} | ||
// .setName | ||
@@ -1765,10 +1915,2 @@ | ||
// .defer | ||
Observable.prototype.defer = function() { | ||
return this.delay(0).setName(this, 'defer'); | ||
} | ||
// .and | ||
@@ -1834,2 +1976,20 @@ | ||
// .fromCallback | ||
Kefir.fromCallback = function(callbackConsumer) { | ||
callbackConsumer = Fn(callbackConsumer, 1); | ||
var called = false; | ||
return Kefir.fromBinder(function(emitter) { | ||
if (!called) { | ||
callbackConsumer.invoke(function(x) { | ||
emitter.emit(x); | ||
emitter.end(); | ||
}); | ||
called = true; | ||
} | ||
}).setName('fromCallback'); | ||
} | ||
if (typeof define === 'function' && define.amd) { | ||
@@ -1836,0 +1996,0 @@ define([], function() { |
@@ -1,6 +0,6 @@ | ||
/*! kefir - 0.2.5 | ||
/*! Kefir.js v0.2.6 | ||
* https://github.com/pozadi/kefir | ||
*/ | ||
!function(a){"use strict";function b(a,b,c){return a&&b in a?a[b]:c}function c(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function d(a){var b=function(){};return b.prototype=a,new b}function e(a){var b,c,d=arguments.length;for(b=1;d>b;b++)for(c in arguments[b])a[c]=arguments[b][c];return a}function f(a,b){var c,f=arguments.length;for(a.prototype=d(b.prototype),a.prototype.constructor=a,c=2;f>c;c++)e(a.prototype,arguments[c]);return a}function g(a){return 1===a.length&&S(a[0])?a[0]:n(a)}function h(a,b){if(r(a))return a;if(null!=b&&r(b[a]))return b[a];throw new Error("not a function: "+a+" in "+b)}function i(a,b,c){var d=c?c.length:0;if(null==b)switch(d){case 0:return a();case 1:return a(c[0]);case 2:return a(c[0],c[1]);case 3:return a(c[0],c[1],c[2]);case 4:return a(c[0],c[1],c[2],c[3]);default:return a.apply(null,c)}else switch(d){case 0:return a.call(b);default:return a.apply(b,c)}}function j(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3];switch(c){case 0:switch(b.length){case 0:return a;case 1:return function(){return a(d)};case 2:return function(){return a(d,e)};case 3:return function(){return a(d,e,f)};case 4:return function(){return a(d,e,f,g)};default:return function(){return a.apply(null,b)}}break;case 1:switch(b.length){case 0:return a;case 1:return function(b){return a(d,b)};case 2:return function(b){return a(d,e,b)};case 3:return function(b){return a(d,e,f,b)};case 4:return function(b){return a(d,e,f,g,b)};default:return function(c){return a.apply(null,m(b,[c]))}}break;case 2:switch(b.length){case 0:return a;case 1:return function(b,c){return a(d,b,c)};case 2:return function(b,c){return a(d,e,b,c)};case 3:return function(b,c){return a(d,e,f,b,c)};case 4:return function(b,c){return a(d,e,f,g,b,c)};default:return function(c,d){return a.apply(null,m(b,[c,d]))}}break;default:switch(b.length){case 0:return a;default:return function(){return i(a,null,m(b,arguments))}}}}function k(a,b,c,d){var e=c[0],f=c[1],g=c[2],h=c[3];switch(d){case 0:switch(c.length){case 0:return function(){return a.call(b)};default:return function(){return a.apply(b,c)}}break;case 1:switch(c.length){case 0:return function(c){return a.call(b,c)};case 1:return function(c){return a.call(b,e,c)};case 2:return function(c){return a.call(b,e,f,c)};case 3:return function(c){return a.call(b,e,f,g,c)};case 4:return function(c){return a.call(b,e,f,g,h,c)};default:return function(d){return a.apply(b,m(c,[d]))}}break;case 2:switch(c.length){case 0:return function(c,d){return a.call(b,c,d)};case 1:return function(c,d){return a.call(b,e,c,d)};case 2:return function(c,d){return a.call(b,e,f,c,d)};case 3:return function(c,d){return a.call(b,e,f,g,c,d)};case 4:return function(c,d){return a.call(b,e,f,g,h,c,d)};default:return function(d,e){return a.apply(b,m(c,[d,e]))}}break;default:switch(c.length){case 0:return function(){return a.apply(b,arguments)};default:return function(){return a.apply(b,m(c,arguments))}}}}function l(a,b,c,d){return null==b?j(a,c,d):k(a,b,c,d)}function m(a,b){var c,d,e=new Array(a.length+b.length),f=0;for(c=a.length,d=0;c>d;d++,f++)e[f]=a[d];for(c=b.length,d=0;c>d;d++,f++)e[f]=b[d];return e}function n(a){var b,c=a.length,d=new Array(c);for(b=0;c>b;b++)d[b]=a[b];return d}function o(a,b){var c,d=a.length;for(c=0;d>c;c++)a[c]=b}function p(a,b){var c,d=a.length;for(c=0;d>c;c++)if(a[c]===b)return!0;return!1}function q(a,b,c){return a.length>b?Array.prototype.slice.call(a,b):c}function r(a){return"function"==typeof a}function s(a){return S(a)||T(a)}function t(a,b){var c,d;if(null==a&&null==b)return!0;if(null==a||null==b)return!1;if(a.length!==b.length)return!1;for(d=0,c=a.length;c>d;d++)if(a[d]!==b[d])return!1;return!0}function u(){for(var a=0;a<arguments.length;a++)if(!arguments[a])return arguments[a];return arguments[a-1]}function v(){for(var a=0;a<arguments.length;a++)if(arguments[a])return arguments[a];return arguments[a-1]}function w(a,b){function c(a,b){C.call(this),this._wait=a,this._intervalId=null;var c=this;this._$onTick=function(){c._onTick()},this._init(b)}f(c,C,{_name:a,_init:function(){},_free:function(){},_onTick:function(){},_onActivation:function(){this._intervalId=setInterval(this._$onTick,this._wait)},_onDeactivation:function(){null!==this._intervalId&&(clearInterval(this._intervalId),this._intervalId=null)},_clear:function(){C.prototype._clear.call(this),this._$onTick=null,this._free()}},b),U[a]=function(a){return new c(a,q(arguments,1,[]))}}function x(a,b,c){function d(c){function d(b,d){c.call(this),this._source=b,this._name=b._name+"."+a,this._init(d)}return f(d,c,{_clear:function(){c.prototype._clear.call(this),this._source=null,this._free()}},b),d}c=e({streamMethod:function(a){return function(){return new a(this,arguments)}},propertyMethod:function(a,b){return function(){return new b(this,arguments)}}},c||{}),b=e({_init:function(){},_free:function(){},_handleValue:function(a,b){this._send("value",a,b)},_handleEnd:function(a,b){this._send("end",null,b)},_onActivationHook:function(){},_onDeactivationHook:function(){},_handleAny:function(a){switch(a.type){case"value":this._handleValue(a.value,a.current);break;case"end":this._handleEnd(a.value,a.current)}},_onActivation:function(){this._onActivationHook(),this._source.onAny([this._handleAny,this])},_onDeactivation:function(){this._onDeactivationHook(),this._source.offAny([this._handleAny,this])}},b||{});var g=d(C),h=d(D);c.streamMethod&&(C.prototype[a]=c.streamMethod(g,h)),c.propertyMethod&&(D.prototype[a]=c.propertyMethod(g,h))}function y(a,b){this.context=null==a[1]?null:a[1],this.fn=h(a[0],this.context),this.args=q(a,2,[]),this.invoke=l(this.fn,this.context,this.args,b)}function z(a,b){if(a instanceof y)return a;if(null==b&&(b=100),r(a))return new y([a],b);if(s(a))return new y(a,b);throw new Error("can't convert to Fn "+a)}function A(){this.value=[],this.end=[],this.any=[],this.total=0}function B(){this._subscribers=new A,this._active=!1,this._alive=!0}function C(){B.call(this)}function D(){B.call(this),this._current=Q}function E(a,b){var c="<"+b.type+(b.current?":current":"")+">";"value"===b.type?console.log(a,c,b.value):console.log(a,c)}function F(a){C.call(this),0===a.length?this._send("end"):(this._sources=a,this._aliveCount=0)}function G(a,b,c){C.call(this),0===b.length?this._send("end"):(this._passiveCount=a.length,this._combinator=c?z(c):null,this._sources=m(a,b),this._aliveCount=0,this._currents=new Array(this._sources.length),o(this._currents,Q),this._activating=!1,this._emitAfterActivation=!1,this._endAfterActivation=!1)}function H(){C.call(this),this._sources=[]}function I(){H.call(this)}function J(a,b){H.call(this),this._source=a,this._name=a._name+".flatMap",this._fn=b?z(b,1):null,this._mainEnded=!1,this._lastValue=null}function K(a){return function(){return new a(this,arguments)}}function L(a,b){return function(){return new b(this,arguments)}}function M(a){C.call(this),this._fn=z(a,1),this._unsubscribe=null}function N(){C.call(this)}function O(a){D.call(this),this._send("value",a),this._send("end")}function P(a){C.call(this),this._value=a}var Q=["<nothing>"],R=Date.now?function(){return Date.now()}:function(){return(new Date).getTime()},S=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},T=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};T(arguments)||(T=function(a){return!(!a||!c(a,"callee"))});var U={};y.prototype.apply=function(a){return i(this.invoke,null,a)},y.prototype.applyWithContext=function(a,b){return null===this.context?0===this.args.length?i(this.fn,a,b):i(this.fn,a,m(this.args,b)):this.apply(b)},z.isEqual=function(a,b){return a===b?!0:(a=z(a,null,!0),b=z(b,null,!0),a.fn===b.fn&&a.context===b.context&&t(a.args,b.args))},U.Fn=z,e(A.prototype,{add:function(a,b){var c="end"===a?0:1;this[a].push(z(b,c,!0)),this.total++},remove:function(a,b){var c,d=this[a],e=d.length;for(b=z(b),c=0;e>c;c++)if(z.isEqual(d[c],b))return d.splice(c,1),void this.total--},call:function(a,b){var c,d=this[a],e=d.length;if(0!==e)if(1===e)"end"===a?d[0].invoke():d[0].invoke(b);else for(d=n(d),c=0;e>c;c++)"end"===a?d[c].invoke():d[c].invoke(b)},isEmpty:function(){return 0===this.total}}),U.Observable=B,e(B.prototype,{_name:"observable",_onActivation:function(){},_onDeactivation:function(){},_setActive:function(a){this._active!==a&&(this._active=a,a?this._onActivation():this._onDeactivation())},_clear:function(){this._setActive(!1),this._alive=!1,this._subscribers=null},_send:function(a,b,c){this._alive&&(this._subscribers.call(a,b),this._subscribers.call("any",{type:a,value:b,current:!!c}),"end"===a&&this._clear())},_callWithCurrent:function(a,b,c,d){b=z(b),a===c?"value"===a?b.invoke(d):b.invoke():"any"===a&&b.invoke({type:c,value:d,current:!0})},on:function(a,b){return this._alive?(this._subscribers.add(a,b),this._setActive(!0)):this._callWithCurrent(a,b,"end"),this},off:function(a,b){return this._alive&&(this._subscribers.remove(a,b),this._subscribers.isEmpty()&&this._setActive(!1)),this},onValue:function(a){this.on("value",a)},onEnd:function(a){this.on("end",a)},onAny:function(a){this.on("any",a)},offValue:function(a){this.off("value",a)},offEnd:function(a){this.off("end",a)},offAny:function(a){this.off("any",a)}}),B.prototype.toString=function(){return"["+this._name+"]"},U.Stream=C,f(C,B,{_name:"stream"}),U.Property=D,f(D,B,{_name:"property",_send:function(a,b,c){this._alive&&(c||(this._subscribers.call(a,b),this._subscribers.call("any",{type:a,value:b,current:!1})),"value"===a&&(this._current=b),"end"===a&&this._clear())},on:function(a,b){return this._alive&&(this._subscribers.add(a,b),this._setActive(!0)),this._current!==Q&&this._callWithCurrent(a,b,"value",this._current),this._alive||this._callWithCurrent(a,b,"end"),this}}),B.prototype.log=function(a){return this.onAny([E,null,a||this.toString()]),this},B.prototype.offLog=function(a){return this.offAny([E,null,a||this.toString()]),this},w("withInterval",{_init:function(a){this._fn=z(a[0],1);var b=this;this._emitter={emit:function(a){b._send("value",a)},end:function(){b._send("end")}}},_free:function(){this._fn=null,this._emitter=null},_onTick:function(){this._fn.invoke(this._emitter)}}),w("fromPoll",{_init:function(a){this._fn=z(a[0],0)},_free:function(){this._fn=null},_onTick:function(){this._send("value",this._fn.invoke())}}),w("interval",{_init:function(a){this._x=a[0]},_free:function(){this._x=null},_onTick:function(){this._send("value",this._x)}}),w("sequentially",{_init:function(a){this._xs=n(a[0]),0===this._xs.length&&this._send("end")},_free:function(){this._xs=null},_onTick:function(){switch(this._xs.length){case 1:this._send("value",this._xs[0]),this._send("end");break;default:this._send("value",this._xs.shift())}}}),w("repeatedly",{_init:function(a){this._xs=n(a[0]),this._i=-1},_onTick:function(){this._xs.length>0&&(this._i=(this._i+1)%this._xs.length,this._send("value",this._xs[this._i]))}}),w("later",{_init:function(a){this._x=a[0]},_free:function(){this._x=null},_onTick:function(){this._send("value",this._x),this._send("end")}}),f(F,C,{_name:"merge",_onActivation:function(){var a,b=this._sources.length;for(this._aliveCount=b,a=0;b>a;a++)this._sources[a].onAny([this._handleAny,this])},_onDeactivation:function(){var a,b=this._sources.length;for(a=0;b>a;a++)this._sources[a].offAny([this._handleAny,this])},_handleAny:function(a){"value"===a.type?this._send("value",a.value,a.current):(this._aliveCount--,0===this._aliveCount&&this._send("end",null,a.current))},_clear:function(){C.prototype._clear.call(this),this._sources=null}}),U.merge=function(){return new F(g(arguments))},B.prototype.merge=function(a){return U.merge([this,a])},f(G,C,{_name:"sampledBy",_onActivation:function(){var a,b=this._sources.length;for(this._aliveCount=b-this._passiveCount,this._activating=!0,a=0;b>a;a++)this._sources[a].onAny([this._handleAny,this,a]);this._activating=!1,this._emitAfterActivation&&(this._emitAfterActivation=!1,this._emitIfFull(!0)),this._endAfterActivation&&this._send("end",null,!0)},_onDeactivation:function(){var a,b=this._sources.length;for(a=0;b>a;a++)this._sources[a].offAny([this._handleAny,this,a])},_emitIfFull:function(a){if(!p(this._currents,Q)){var b=n(this._currents);this._combinator&&(b=this._combinator.apply(this._currents)),this._send("value",b,a)}},_handleAny:function(a,b){"value"===b.type?(this._currents[a]=b.value,a>=this._passiveCount&&(this._activating?this._emitAfterActivation=!0:this._emitIfFull(b.current))):a>=this._passiveCount&&(this._aliveCount--,0===this._aliveCount&&(this._activating?this._endAfterActivation=!0:this._send("end",null,b.current)))},_clear:function(){C.prototype._clear.call(this),this._sources=null,this._currents=null}}),U.sampledBy=function(a,b,c){return new G(a,b,c)},B.prototype.sampledBy=function(a,b){return U.sampledBy([this],[a],b)},U.combine=function(a,b){var c=new G([],a,b);return c._name="combine",c},B.prototype.combine=function(a,b){return U.combine([this,a],b)},f(H,C,{_name:"abstractPool",_sub:function(a){a.onAny([this._handleSubAny,this]),a.onEnd([this._remove,this,a])},_unsub:function(a){a.offAny([this._handleSubAny,this]),a.offEnd([this._remove,this,a])},_handleSubAny:function(a){"value"===a.type&&this._send("value",a.value,a.current)},_add:function(a){this._sources.push(a),this._active&&this._sub(a)},_remove:function(a){this._active&&this._unsub(a);for(var b=0;b<this._sources.length;b++)if(this._sources[b]===a)return void this._sources.splice(b,1)},_onActivation:function(){for(var a=n(this._sources),b=0;b<a.length;b++)this._sub(a[b])},_onDeactivation:function(){for(var a=0;a<this._sources.length;a++)this._unsub(this._sources[a])}}),f(I,H,{_name:"pool",add:function(a){return this._add(a),this},remove:function(a){return this._remove(a),this}}),U.pool=function(){return new I},f(J,H,{_onActivation:function(){H.prototype._onActivation.call(this),this._source.onAny([this._handleMainSource,this])},_onDeactivation:function(){H.prototype._onDeactivation.call(this),this._source.offAny([this._handleMainSource,this])},_handleMainSource:function(a){"value"===a.type?(a.current&&this._lastValue===a.value||this._add(this._fn?this._fn.invoke(a.value):a.value),this._lastValue=a.value):0===this._sources.length?this._send("end",null,a.current):this._mainEnded=!0},_remove:function(a){H.prototype._remove.call(this,a),this._mainEnded&&0===this._sources.length&&this._send("end")},_clear:function(){H.prototype._clear.call(this),this._source=null,this._lastValue=null}}),B.prototype.flatMap=function(a){return new J(this,a)},x("toProperty",{_init:function(a){a.length>0&&this._send("value",a[0])}},{propertyMethod:null,streamMethod:L}),x("changes",{_handleValue:function(a,b){b||this._send("value",a)}},{streamMethod:null,propertyMethod:K}),x("withHandler",{_init:function(a){this._handler=z(a[0],2),this._forcedCurrent=!1;var b=this;this._emitter={emit:function(a){b._send("value",a,b._forcedCurrent)},end:function(){b._send("end",null,b._forcedCurrent)}}},_free:function(){this._handler=null,this._emitter=null},_handleAny:function(a){this._forcedCurrent=a.current,this._handler.invoke(this._emitter,a),this._forcedCurrent=!1}});var V={_init:function(a){this._fn=z(a[0],1)},_free:function(){this._fn=null}};x("map",e({_handleValue:function(a,b){this._send("value",this._fn.invoke(a),b)}},V)),x("filter",e({_handleValue:function(a,b){this._fn.invoke(a)&&this._send("value",a,b)}},V)),x("takeWhile",e({_handleValue:function(a,b){this._fn.invoke(a)?this._send("value",a,b):this._send("end",null,b)}},V)),x("take",{_init:function(a){this._n=a[0],this._n<=0&&this._send("end")},_handleValue:function(a,b){this._n--,this._send("value",a,b),0===this._n&&this._send("end")}}),x("skip",{_init:function(a){this._n=a[0]<0?0:a[0]},_handleValue:function(a,b){0===this._n?this._send("value",a,b):this._n--}}),x("skipDuplicates",{_init:function(a){this._fn=a[0]&&z(a[0],2),this._prev=Q},_free:function(){this._fn=null,this._prev=null},_isEqual:function(a,b){return this._fn?this._fn.invoke(a,b):a===b},_handleValue:function(a,b){this._prev!==Q&&this._isEqual(this._prev,a)||(this._send("value",a,b),this._prev=a)}}),x("skipWhile",{_init:function(a){this._fn=z(a[0],1),this._skip=!0},_free:function(){this._fn=null},_handleValue:function(a,b){return this._skip?void(this._fn.invoke(a)||(this._skip=!1,this._fn=null,this._send("value",a,b))):void this._send("value",a,b)}}),x("diff",{_init:function(a){this._prev=a[0],this._fn=z(a[1],2)},_free:function(){this._prev=null,this._fn=null},_handleValue:function(a,b){this._send("value",this._fn.invoke(this._prev,a),b),this._prev=a}}),x("scan",{_init:function(a){this._send("value",a[0],!0),this._fn=z(a[1],2)},_free:function(){this._fn=null},_handleValue:function(a,b){this._send("value",this._fn.invoke(this._current,a),b)}},{streamMethod:L}),x("reduce",{_init:function(a){this._result=a[0],this._fn=z(a[1],2)},_free:function(){this._fn=null,this._result=null},_handleValue:function(a){this._result=this._fn.invoke(this._result,a)},_handleEnd:function(a,b){this._send("value",this._result,b),this._send("end",null,b)}}),x("throttle",{_init:function(a){this._wait=a[0],this._leading=b(a[1],"leading",!0),this._trailing=b(a[1],"trailing",!0),this._trailingCallValue=null,this._trailingCallTimeoutId=null,this._endAfterTrailingCall=!1,this._lastCallTime=0;var c=this;this._$makeTrailingCall=function(){c._makeTrailingCall()}},_free:function(){this._trailingCallValue=null,this._$makeTrailingCall=null},_handleValue:function(a,b){if(b)this._send("value",a,b);else{var c=R();0!==this._lastCallTime||this._leading||(this._lastCallTime=c);var d=this._wait-(c-this._lastCallTime);0>=d?(this._cancelTralingCall(),this._lastCallTime=c,this._send("value",a)):this._trailing&&this._scheduleTralingCall(a,d)}},_handleEnd:function(a,b){b?this._send("end",null,b):this._trailingCallTimeoutId?this._endAfterTrailingCall=!0:this._send("end")},_scheduleTralingCall:function(a,b){this._trailingCallTimeoutId&&this._cancelTralingCall(),this._trailingCallValue=a,this._trailingCallTimeoutId=setTimeout(this._$makeTrailingCall,b)},_cancelTralingCall:function(){null!==this._trailingCallTimeoutId&&(clearTimeout(this._trailingCallTimeoutId),this._trailingCallTimeoutId=null)},_makeTrailingCall:function(){this._send("value",this._trailingCallValue),this._trailingCallTimeoutId=null,this._trailingCallValue=null,this._lastCallTime=this._leading?R():0,this._endAfterTrailingCall&&this._send("end")}}),x("delay",{_init:function(a){this._wait=a[0],this._buff=[];var b=this;this._shiftBuff=function(){b._send("value",b._buff.shift())}},_free:function(){this._buff=null,this._shiftBuff=null},_handleValue:function(a,b){b?this._send("value",a,b):(this._buff.push(a),setTimeout(this._shiftBuff,this._wait))},_handleEnd:function(a,b){if(b)this._send("end",null,b);else{var c=this;setTimeout(function(){c._send("end")},this._wait)}}}),f(M,C,{_name:"fromBinder",_onActivation:function(){var a,b=this,c=!0,d={emit:function(a){b._send("value",a,c)},end:function(){b._send("end",null,c)}};a=this._fn.invoke(d),c=!1,a&&(this._unsubscribe=z(a,0))},_onDeactivation:function(){null!==this._unsubscribe&&(this._unsubscribe.invoke(),this._unsubscribe=null)},_clear:function(){C.prototype._clear.call(this),this._fn=null}}),U.fromBinder=function(a){return new M(a)},f(N,C,{_name:"emitter",emit:function(a){this._send("value",a)},end:function(){this._send("end")}}),U.emitter=function(){return new N};var W=new C;W._send("end"),W._name="never",U.never=function(){return W},f(O,D,{_name:"constant"}),U.constant=function(a){return new O(a)},f(P,C,{_name:"once",_onActivation:function(){this._send("value",this._value),this._send("end")}}),U.once=function(a){return new P(a)},B.prototype.setName=function(a,b){return this._name=b?a._name+"."+b:a,this},B.prototype.mapTo=function(a){return this.map(function(){return a}).setName(this,"mapTo")},B.prototype.pluck=function(a){return this.map(function(b){return b[a]}).setName(this,"pluck")},B.prototype.invoke=function(a){var b=q(arguments,1);return this.map(b?function(c){return i(c[a],c,b)}:function(b){return b[a]()}).setName(this,"invoke")},B.prototype.tap=function(a){return a=z(a,1),this.map(function(b){return a.invoke(b),b}).setName(this,"tap")},B.prototype.defer=function(){return this.delay(0).setName(this,"defer")},U.and=function(a){return U.combine(a,u).setName("and")},B.prototype.and=function(a){return this.combine(a,u).setName("and")},U.or=function(a){return U.combine(a,v).setName("or")},B.prototype.or=function(a){return this.combine(a,v).setName("or")},B.prototype.not=function(){return this.map(function(a){return!a}).setName(this,"not")},B.prototype.awaiting=function(a){return U.merge([this.mapTo(!0),a.mapTo(!1)]).skipDuplicates().toProperty(!1).setName(this,"awaiting")},B.prototype.filterBy=function(a){return a.sampledBy(this).withHandler(function(a,b){"end"===b.type?a.end():b.value[0]&&a.emit(b.value[1])}).setName(this,"filterBy")},"function"==typeof define&&define.amd?(define([],function(){return U}),a.Kefir=U):"object"==typeof module&&"object"==typeof exports?(module.exports=U,U.Kefir=U):a.Kefir=U}(this); | ||
!function(a){"use strict";function b(a,b,c){return a&&b in a?a[b]:c}function c(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function d(a){var b=function(){};return b.prototype=a,new b}function e(a){var b,c,d=arguments.length;for(b=1;d>b;b++)for(c in arguments[b])a[c]=arguments[b][c];return a}function f(a,b){var c,f=arguments.length;for(a.prototype=d(b.prototype),a.prototype.constructor=a,c=2;f>c;c++)e(a.prototype,arguments[c]);return a}function g(a){return 1===a.length&&$(a[0])?a[0]:p(a)}function h(a,b){if(w(a))return a;if(null!=b&&w(b[a]))return b[a];throw new Error("Not a function: "+a+" in context: "+b)}function i(a,b,c){var d=c?c.length:0;if(null==b)switch(d){case 0:return a();case 1:return a(c[0]);case 2:return a(c[0],c[1]);case 3:return a(c[0],c[1],c[2]);case 4:return a(c[0],c[1],c[2],c[3]);default:return a.apply(null,c)}else switch(d){case 0:return a.call(b);default:return a.apply(b,c)}}function j(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3];switch(c){case 0:switch(b.length){case 0:return a;case 1:return function(){return a(d)};case 2:return function(){return a(d,e)};case 3:return function(){return a(d,e,f)};case 4:return function(){return a(d,e,f,g)};default:return function(){return a.apply(null,b)}}break;case 1:switch(b.length){case 0:return a;case 1:return function(b){return a(d,b)};case 2:return function(b){return a(d,e,b)};case 3:return function(b){return a(d,e,f,b)};case 4:return function(b){return a(d,e,f,g,b)};default:return function(c){return a.apply(null,m(b,[c]))}}break;case 2:switch(b.length){case 0:return a;case 1:return function(b,c){return a(d,b,c)};case 2:return function(b,c){return a(d,e,b,c)};case 3:return function(b,c){return a(d,e,f,b,c)};case 4:return function(b,c){return a(d,e,f,g,b,c)};default:return function(c,d){return a.apply(null,m(b,[c,d]))}}break;default:switch(b.length){case 0:return a;default:return function(){return i(a,null,m(b,arguments))}}}}function k(a,b,c,d){var e=c[0],f=c[1],g=c[2],h=c[3];switch(d){case 0:switch(c.length){case 0:return function(){return a.call(b)};default:return function(){return a.apply(b,c)}}break;case 1:switch(c.length){case 0:return function(c){return a.call(b,c)};case 1:return function(c){return a.call(b,e,c)};case 2:return function(c){return a.call(b,e,f,c)};case 3:return function(c){return a.call(b,e,f,g,c)};case 4:return function(c){return a.call(b,e,f,g,h,c)};default:return function(d){return a.apply(b,m(c,[d]))}}break;case 2:switch(c.length){case 0:return function(c,d){return a.call(b,c,d)};case 1:return function(c,d){return a.call(b,e,c,d)};case 2:return function(c,d){return a.call(b,e,f,c,d)};case 3:return function(c,d){return a.call(b,e,f,g,c,d)};case 4:return function(c,d){return a.call(b,e,f,g,h,c,d)};default:return function(d,e){return a.apply(b,m(c,[d,e]))}}break;default:switch(c.length){case 0:return function(){return a.apply(b,arguments)};default:return function(){return a.apply(b,m(c,arguments))}}}}function l(a,b,c,d){return null==b?j(a,c,d):k(a,b,c,d)}function m(a,b){var c,d,e=new Array(a.length+b.length),f=0;if(0===a.length)return b;if(0===b.length)return a;for(c=a.length,d=0;c>d;d++,f++)e[f]=a[d];for(c=b.length,d=0;c>d;d++,f++)e[f]=b[d];return e}function n(a,b){var c,d=a.length;for(c=0;d>c;c++)if(a[c]===b)return c;return-1}function o(a,b){var c,d=a.length;for(c=0;d>c;c++)if(b(a[c]))return c;return-1}function p(a){var b,c=a.length,d=new Array(c);for(b=0;c>b;b++)d[b]=a[b];return d}function q(a,b){var c,d,e,f=a.length;if(b>=0&&f>b){if(1===f)return[];for(c=new Array(f-1),d=0,e=0;f>d;d++)d!==b&&(c[e]=a[d],e++);return c}return a}function r(a,b){return q(a,o(a,b))}function s(a,b){var c,d=a.length;for(c=0;d>c;c++)b(a[c])}function t(a,b){var c,d=a.length;for(c=0;d>c;c++)a[c]=b}function u(a,b){return-1!==n(a,b)}function v(a,b,c){return a.length>b?Array.prototype.slice.call(a,b):c}function w(a){return"function"==typeof a}function x(a){return $(a)||_(a)}function y(a,b){var c,d;if(null==a&&null==b)return!0;if(null==a||null==b)return!1;if(a.length!==b.length)return!1;for(d=0,c=a.length;c>d;d++)if(a[d]!==b[d])return!1;return!0}function z(){for(var a=0;a<arguments.length;a++)if(!arguments[a])return arguments[a];return arguments[a-1]}function A(){for(var a=0;a<arguments.length;a++)if(arguments[a])return arguments[a];return arguments[a-1]}function B(a,b){function c(a,b){K.call(this),this._wait=a,this._intervalId=null;var c=this;this._$onTick=function(){c._onTick()},this._init(b)}f(c,K,{_name:a,_init:function(){},_free:function(){},_onTick:function(){},_onActivation:function(){this._intervalId=setInterval(this._$onTick,this._wait)},_onDeactivation:function(){null!==this._intervalId&&(clearInterval(this._intervalId),this._intervalId=null)},_clear:function(){K.prototype._clear.call(this),this._$onTick=null,this._free()}},b),ab[a]=function(a){return new c(a,v(arguments,1,[]))}}function C(a,b,c){function d(c){function d(b,d){c.call(this),this._source=b,this._name=b._name+"."+a,this._init(d)}return f(d,c,{_clear:function(){c.prototype._clear.call(this),this._source=null,this._free()}},b),d}c=e({streamMethod:function(a){return function(){return new a(this,arguments)}},propertyMethod:function(a,b){return function(){return new b(this,arguments)}}},c||{}),b=e({_init:function(){},_free:function(){},_handleValue:function(a,b){this._send("value",a,b)},_handleEnd:function(a,b){this._send("end",null,b)},_onActivationHook:function(){},_onDeactivationHook:function(){},_handleAny:function(a){switch(a.type){case"value":this._handleValue(a.value,a.current);break;case"end":this._handleEnd(a.value,a.current)}},_onActivation:function(){this._onActivationHook(),this._source.onAny([this._handleAny,this])},_onDeactivation:function(){this._onDeactivationHook(),this._source.offAny([this._handleAny,this])}},b||{});var g=d(K),h=d(L);c.streamMethod&&(K.prototype[a]=c.streamMethod(g,h)),c.propertyMethod&&(L.prototype[a]=c.propertyMethod(g,h))}function D(a){if(a instanceof F)return a;if(w(a))return{fn:a,context:null,args:[]};if(x(a))return{fn:h(a[0],a[1]),context:null==a[1]?null:a[1],args:v(a,2,[])};throw new Error("Object isn't a function, and can't be converted to it: "+a)}function E(a,b){return a=D(a),i(a.fn,a.context,m(a.args,b))}function F(a,b){this.context=a.context,this.fn=a.fn,this.args=a.args,this.invoke=l(this.fn,this.context,this.args,b)}function G(a,b){return a instanceof F?a:new F(D(a),null==b?100:b)}function H(){this._fns=[]}function I(a,b,c){return{type:a,value:b,current:!!c}}function J(){this._subscribers=new H,this._active=!1,this._alive=!0}function K(){J.call(this)}function L(){J.call(this),this._current=Y}function M(a,b){var c="<"+b.type+(b.current?":current":"")+">";"value"===b.type?console.log(a,c,b.value):console.log(a,c)}function N(a){if(K.call(this),this._queueLim=b(a,"queueLim",0),this._concurLim=b(a,"concurLim",-1),this._drop=b(a,"drop","new"),0===this._concurLim)throw new Error("options.concurLim can't be 0");this._queue=[],this._curSources=[],this._activating=!1}function O(a){N.call(this),0===a.length?this._send("end"):this._addAll(a),this._initialised=!0}function P(a){N.call(this,{concurLim:1,queueLim:-1}),0===a.length?this._send("end"):this._addAll(a),this._initialised=!0}function Q(){N.call(this)}function R(a,b,c){N.call(this,c),this._source=a,this._fn=b?G(b,1):null,this._mainEnded=!1,this._lastCurrent=null}function S(a,b,c){K.call(this),0===b.length?this._send("end"):(this._passiveCount=a.length,this._combinator=c?G(c):null,this._sources=m(a,b),this._aliveCount=0,this._currents=new Array(this._sources.length),t(this._currents,Y),this._activating=!1,this._emitAfterActivation=!1,this._endAfterActivation=!1)}function T(a){return function(){return new a(this,arguments)}}function U(a,b){return function(){return new b(this,arguments)}}function V(a){K.call(this),this._fn=G(a,1),this._unsubscribe=null}function W(){K.call(this)}function X(a){L.call(this),this._send("value",a),this._send("end")}var Y=["<nothing>"],Z=Date.now?function(){return Date.now()}:function(){return(new Date).getTime()},$=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},_=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};_(arguments)||(_=function(a){return!(!a||!c(a,"callee"))});var ab={};F.prototype.apply=function(a){return i(this.invoke,null,a)},F.prototype.applyWithContext=function(a,b){return null===this.context?i(this.fn,a,m(this.args,b)):this.apply(b)},G.isEqual=function(a,b){return a===b?!0:(a=G(a,null,!0),b=G(b,null,!0),a.fn===b.fn&&a.context===b.context&&y(a.args,b.args))},ab.Fn=G,e(H,{callOne:function(a,b){"any"===a.type?a.invoke(b):a.type===b.type&&("value"===a.type?a.invoke(b.value):a.invoke())},callOnce:function(a,b,c){"any"===a?E(b,[c]):a===c.type&&("value"===a?E(b,[c.value]):E(b,[]))}}),e(H.prototype,{add:function(a,b){b=G(b,"end"===a?0:1),b.type=a,this._fns=m(this._fns,[b])},remove:function(a,b){b=G(b),this._fns=r(this._fns,function(c){return c.type===a&&G.isEqual(c,b)})},callAll:function(a){for(var b=this._fns,c=0;c<b.length;c++)H.callOne(b[c],a)},isEmpty:function(){return 0===this._fns.length}});var bb=I("end",void 0,!0);ab.Observable=J,e(J.prototype,{_name:"observable",_onActivation:function(){},_onDeactivation:function(){},_setActive:function(a){this._active!==a&&(this._active=a,a?this._onActivation():this._onDeactivation())},_clear:function(){this._setActive(!1),this._alive=!1,this._subscribers=null},_send:function(a,b,c){this._alive&&(this._subscribers.callAll(I(a,b,c)),"end"===a&&this._clear())},on:function(a,b){return this._alive?(this._subscribers.add(a,b),this._setActive(!0)):H.callOnce(a,b,bb),this},off:function(a,b){return this._alive&&(this._subscribers.remove(a,b),this._subscribers.isEmpty()&&this._setActive(!1)),this},onValue:function(a){return this.on("value",a)},onEnd:function(a){return this.on("end",a)},onAny:function(a){return this.on("any",a)},offValue:function(a){return this.off("value",a)},offEnd:function(a){return this.off("end",a)},offAny:function(a){return this.off("any",a)}}),J.prototype.toString=function(){return"["+this._name+"]"},ab.Stream=K,f(K,J,{_name:"stream"}),ab.Property=L,f(L,J,{_name:"property",_send:function(a,b,c){this._alive&&(c||this._subscribers.callAll(I(a,b)),"value"===a&&(this._current=b),"end"===a&&this._clear())},on:function(a,b){return this._alive&&(this._subscribers.add(a,b),this._setActive(!0)),this._current!==Y&&H.callOnce(a,b,I("value",this._current,!0)),this._alive||H.callOnce(a,b,bb),this}}),J.prototype.log=function(a){return this.onAny([M,null,a||this.toString()]),this},J.prototype.offLog=function(a){return this.offAny([M,null,a||this.toString()]),this},B("withInterval",{_init:function(a){this._fn=G(a[0],1);var b=this;this._emitter={emit:function(a){b._send("value",a)},end:function(){b._send("end")}}},_free:function(){this._fn=null,this._emitter=null},_onTick:function(){this._fn.invoke(this._emitter)}}),B("fromPoll",{_init:function(a){this._fn=G(a[0],0)},_free:function(){this._fn=null},_onTick:function(){this._send("value",this._fn.invoke())}}),B("interval",{_init:function(a){this._x=a[0]},_free:function(){this._x=null},_onTick:function(){this._send("value",this._x)}}),B("sequentially",{_init:function(a){this._xs=p(a[0]),0===this._xs.length&&this._send("end")},_free:function(){this._xs=null},_onTick:function(){switch(this._xs.length){case 1:this._send("value",this._xs[0]),this._send("end");break;default:this._send("value",this._xs.shift())}}}),B("repeatedly",{_init:function(a){this._xs=p(a[0]),this._i=-1},_onTick:function(){this._xs.length>0&&(this._i=(this._i+1)%this._xs.length,this._send("value",this._xs[this._i]))}}),B("later",{_init:function(a){this._x=a[0]},_free:function(){this._x=null},_onTick:function(){this._send("value",this._x),this._send("end")}}),f(N,K,{_name:"abstractPool",_add:function(a){-1===this._concurLim||this._curSources.length<this._concurLim?this._addToCur(a):-1===this._queueLim||this._queue.length<this._queueLim?this._addToQueue(a):"old"===this._drop&&(this._removeOldest(),this._add(a))},_addAll:function(a){var b=this;s(a,function(a){b._add(a)})},_remove:function(a){-1===this._removeCur(a)&&this._removeQueue(a)},_addToQueue:function(a){this._queue=m(this._queue,[a])},_addToCur:function(a){this._curSources=m(this._curSources,[a]),this._active&&this._sub(a)},_sub:function(a){a.onAny([this._handleSubAny,this]),a.onEnd([this._removeCur,this,a])},_unsub:function(a){a.offAny([this._handleSubAny,this]),a.offEnd([this._removeCur,this,a])},_handleSubAny:function(a){"value"===a.type&&this._send("value",a.value,a.current&&this._activating)},_removeQueue:function(a){var b=n(this._queue,a);return this._queue=q(this._queue,b),b},_removeCur:function(a){this._active&&this._unsub(a);var b=n(this._curSources,a);return this._curSources=q(this._curSources,b),-1!==b&&(0!==this._queue.length?this._pullQueue():0===this._curSources.length&&this._onEmpty()),b},_removeOldest:function(){this._removeCur(this._curSources[0])},_pullQueue:function(){0!==this._queue.length&&(this._queue=p(this._queue),this._addToCur(this._queue.shift()))},_onActivation:function(){var a,b=this._curSources;for(this._activating=!0,a=0;a<b.length;a++)this._sub(b[a]);this._activating=!1},_onDeactivation:function(){var a,b=this._curSources;for(a=0;a<b.length;a++)this._unsub(b[a])},_isEmpty:function(){return 0===this._curSources.length},_onEmpty:function(){},_clear:function(){K.prototype._clear.call(this),this._queue=null,this._curSources=null}});var cb={_onEmpty:function(){this._initialised&&this._send("end",null,this._activating)}};f(O,N,e({_name:"merge"},cb)),ab.merge=function(){return new O(g(arguments))},J.prototype.merge=function(a){return ab.merge([this,a])},f(P,N,e({_name:"concat"},cb)),ab.concat=function(){return new P(g(arguments))},J.prototype.concat=function(a){return ab.concat([this,a])},f(Q,N,{_name:"pool",add:function(a){return this._add(a),this},remove:function(a){return this._remove(a),this}}),ab.pool=function(){return new Q},f(R,N,{_onActivation:function(){N.prototype._onActivation.call(this),this._activating=!0,this._source.onAny([this._handleMainSource,this]),this._activating=!1},_onDeactivation:function(){N.prototype._onDeactivation.call(this),this._source.offAny([this._handleMainSource,this])},_handleMainSource:function(a){"value"===a.type?(a.current&&this._lastCurrent===a.value||this._add(this._fn?this._fn.invoke(a.value):a.value),this._lastCurrent=a.value):this._isEmpty()?this._send("end",null,a.current):this._mainEnded=!0},_onEmpty:function(){this._mainEnded&&this._send("end")},_clear:function(){N.prototype._clear.call(this),this._source=null,this._lastCurrent=null}}),J.prototype.flatMap=function(a){return new R(this,a).setName(this,"flatMap")},J.prototype.flatMapLatest=function(a){return new R(this,a,{concurLim:1,drop:"old"}).setName(this,"flatMapLatest")},J.prototype.flatMapFirst=function(a){return new R(this,a,{concurLim:1}).setName(this,"flatMapFirst")},J.prototype.flatMapConcat=function(a){return new R(this,a,{queueLim:-1,concurLim:1}).setName(this,"flatMapConcat")},J.prototype.flatMapWithConcurrencyLimit=function(a,b){var c;return 0===b?c=ab.never():(0>b&&(b=-1),c=new R(this,a,{queueLim:-1,concurLim:b})),c.setName(this,"flatMapWithConcurrencyLimit")},f(S,K,{_name:"sampledBy",_onActivation:function(){var a,b=this._sources.length;for(this._aliveCount=b-this._passiveCount,this._activating=!0,a=0;b>a;a++)this._sources[a].onAny([this._handleAny,this,a]);this._activating=!1,this._emitAfterActivation&&(this._emitAfterActivation=!1,this._emitIfFull(!0)),this._endAfterActivation&&this._send("end",null,!0)},_onDeactivation:function(){var a,b=this._sources.length;for(a=0;b>a;a++)this._sources[a].offAny([this._handleAny,this,a])},_emitIfFull:function(a){if(!u(this._currents,Y)){var b=p(this._currents);this._combinator&&(b=this._combinator.apply(this._currents)),this._send("value",b,a)}},_handleAny:function(a,b){"value"===b.type?(this._currents[a]=b.value,a>=this._passiveCount&&(this._activating?this._emitAfterActivation=!0:this._emitIfFull(b.current))):a>=this._passiveCount&&(this._aliveCount--,0===this._aliveCount&&(this._activating?this._endAfterActivation=!0:this._send("end",null,b.current)))},_clear:function(){K.prototype._clear.call(this),this._sources=null,this._currents=null}}),ab.sampledBy=function(a,b,c){return new S(a,b,c)},J.prototype.sampledBy=function(a,b){return ab.sampledBy([this],[a],b)},ab.combine=function(a,b){var c=new S([],a,b);return c._name="combine",c},J.prototype.combine=function(a,b){return ab.combine([this,a],b)},C("toProperty",{_init:function(a){a.length>0&&this._send("value",a[0])}},{propertyMethod:null,streamMethod:U}),C("changes",{_handleValue:function(a,b){b||this._send("value",a)}},{streamMethod:null,propertyMethod:T}),C("withHandler",{_init:function(a){this._handler=G(a[0],2),this._forcedCurrent=!1;var b=this;this._emitter={emit:function(a){b._send("value",a,b._forcedCurrent)},end:function(){b._send("end",null,b._forcedCurrent)}}},_free:function(){this._handler=null,this._emitter=null},_handleAny:function(a){this._forcedCurrent=a.current,this._handler.invoke(this._emitter,a),this._forcedCurrent=!1}});var db={_init:function(a){this._fn=G(a[0],1)},_free:function(){this._fn=null}};C("map",e({_handleValue:function(a,b){this._send("value",this._fn.invoke(a),b)}},db)),C("filter",e({_handleValue:function(a,b){this._fn.invoke(a)&&this._send("value",a,b)}},db)),C("takeWhile",e({_handleValue:function(a,b){this._fn.invoke(a)?this._send("value",a,b):this._send("end",null,b)}},db)),C("take",{_init:function(a){this._n=a[0],this._n<=0&&this._send("end")},_handleValue:function(a,b){this._n--,this._send("value",a,b),0===this._n&&this._send("end")}}),C("skip",{_init:function(a){this._n=a[0]<0?0:a[0]},_handleValue:function(a,b){0===this._n?this._send("value",a,b):this._n--}}),C("skipDuplicates",{_init:function(a){this._fn=a[0]&&G(a[0],2),this._prev=Y},_free:function(){this._fn=null,this._prev=null},_isEqual:function(a,b){return this._fn?this._fn.invoke(a,b):a===b},_handleValue:function(a,b){this._prev!==Y&&this._isEqual(this._prev,a)||(this._send("value",a,b),this._prev=a)}}),C("skipWhile",{_init:function(a){this._fn=G(a[0],1),this._skip=!0},_free:function(){this._fn=null},_handleValue:function(a,b){return this._skip?void(this._fn.invoke(a)||(this._skip=!1,this._fn=null,this._send("value",a,b))):void this._send("value",a,b)}}),C("diff",{_init:function(a){this._prev=a[0],this._fn=G(a[1],2)},_free:function(){this._prev=null,this._fn=null},_handleValue:function(a,b){this._send("value",this._fn.invoke(this._prev,a),b),this._prev=a}}),C("scan",{_init:function(a){this._send("value",a[0],!0),this._fn=G(a[1],2)},_free:function(){this._fn=null},_handleValue:function(a,b){this._send("value",this._fn.invoke(this._current,a),b)}},{streamMethod:U}),C("reduce",{_init:function(a){this._result=a[0],this._fn=G(a[1],2)},_free:function(){this._fn=null,this._result=null},_handleValue:function(a){this._result=this._fn.invoke(this._result,a)},_handleEnd:function(a,b){this._send("value",this._result,b),this._send("end",null,b)}}),C("debounce",{_init:function(a){this._wait=Math.max(0,a[0]),this._immediate=b(a[1],"immediate",!1),this._lastAttempt=0,this._timeoutId=null,this._laterValue=null,this._endLater=!1;var c=this;this._$later=function(){c._later()}},_free:function(){this._laterValue=null,this._$later=null},_handleValue:function(a,b){b?this._send("value",a,b):(this._lastAttempt=Z(),this._immediate&&!this._timeoutId&&this._send("value",a),this._timeoutId||(this._timeoutId=setTimeout(this._$later,this._wait)),this._immediate||(this._laterValue=a))},_handleEnd:function(a,b){b?this._send("end",null,b):this._timeoutId&&!this._immediate?this._endLater=!0:this._send("end")},_later:function(){var a=Z()-this._lastAttempt;a<this._wait&&a>=0?this._timeoutId=setTimeout(this._$later,this._wait-a):(this._timeoutId=null,this._immediate||(this._send("value",this._laterValue),this._laterValue=null),this._endLater&&this._send("end"))}}),C("throttle",{_init:function(a){this._wait=Math.max(0,a[0]),this._leading=b(a[1],"leading",!0),this._trailing=b(a[1],"trailing",!0),this._trailingValue=null,this._timeoutId=null,this._endLater=!1,this._lastCallTime=0;var c=this;this._$trailingCall=function(){c._trailingCall()}},_free:function(){this._trailingValue=null,this._$trailingCall=null},_handleValue:function(a,b){if(b)this._send("value",a,b);else{var c=Z();0!==this._lastCallTime||this._leading||(this._lastCallTime=c);var d=this._wait-(c-this._lastCallTime);0>=d?(this._cancelTraling(),this._lastCallTime=c,this._send("value",a)):this._trailing&&(this._cancelTraling(),this._trailingValue=a,this._timeoutId=setTimeout(this._$trailingCall,d))}},_handleEnd:function(a,b){b?this._send("end",null,b):this._timeoutId?this._endLater=!0:this._send("end")},_cancelTraling:function(){null!==this._timeoutId&&(clearTimeout(this._timeoutId),this._timeoutId=null)},_trailingCall:function(){this._send("value",this._trailingValue),this._timeoutId=null,this._trailingValue=null,this._lastCallTime=this._leading?Z():0,this._endLater&&this._send("end")}}),C("delay",{_init:function(a){this._wait=Math.max(0,a[0]),this._buff=[];var b=this;this._$shiftBuff=function(){b._send("value",b._buff.shift())}},_free:function(){this._buff=null,this._$shiftBuff=null},_handleValue:function(a,b){b?this._send("value",a,b):(this._buff.push(a),setTimeout(this._$shiftBuff,this._wait))},_handleEnd:function(a,b){if(b)this._send("end",null,b);else{var c=this;setTimeout(function(){c._send("end")},this._wait)}}}),f(V,K,{_name:"fromBinder",_onActivation:function(){var a,b=this,c=!0,d={emit:function(a){b._send("value",a,c)},end:function(){b._send("end",null,c)}};a=this._fn.invoke(d),c=!1,a&&(this._unsubscribe=G(a,0))},_onDeactivation:function(){null!==this._unsubscribe&&(this._unsubscribe.invoke(),this._unsubscribe=null)},_clear:function(){K.prototype._clear.call(this),this._fn=null}}),ab.fromBinder=function(a){return new V(a)},f(W,K,{_name:"emitter",emit:function(a){this._send("value",a)},end:function(){this._send("end")}}),ab.emitter=function(){return new W};var eb=new K;eb._send("end"),eb._name="never",ab.never=function(){return eb},f(X,L,{_name:"constant"}),ab.constant=function(a){return new X(a)},J.prototype.setName=function(a,b){return this._name=b?a._name+"."+b:a,this},J.prototype.mapTo=function(a){return this.map(function(){return a}).setName(this,"mapTo")},J.prototype.pluck=function(a){return this.map(function(b){return b[a]}).setName(this,"pluck")},J.prototype.invoke=function(a){var b=v(arguments,1);return this.map(b?function(c){return i(c[a],c,b)}:function(b){return b[a]()}).setName(this,"invoke")},J.prototype.tap=function(a){return a=G(a,1),this.map(function(b){return a.invoke(b),b}).setName(this,"tap")},ab.and=function(a){return ab.combine(a,z).setName("and")},J.prototype.and=function(a){return this.combine(a,z).setName("and")},ab.or=function(a){return ab.combine(a,A).setName("or")},J.prototype.or=function(a){return this.combine(a,A).setName("or")},J.prototype.not=function(){return this.map(function(a){return!a}).setName(this,"not")},J.prototype.awaiting=function(a){return ab.merge([this.mapTo(!0),a.mapTo(!1)]).skipDuplicates().toProperty(!1).setName(this,"awaiting")},J.prototype.filterBy=function(a){return a.sampledBy(this).withHandler(function(a,b){"end"===b.type?a.end():b.value[0]&&a.emit(b.value[1])}).setName(this,"filterBy")},ab.fromCallback=function(a){a=G(a,1);var b=!1;return ab.fromBinder(function(c){b||(a.invoke(function(a){c.emit(a),c.end()}),b=!0)}).setName("fromCallback")},"function"==typeof define&&define.amd?(define([],function(){return ab}),a.Kefir=ab):"object"==typeof module&&"object"==typeof exports?(module.exports=ab,ab.Kefir=ab):a.Kefir=ab}(this); | ||
//# sourceMappingURL=kefir.min.js.map |
{ | ||
"name": "kefir", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"description": "FRP library for JavaScript inspired by Bacon.js and RxJS with focus on high performance and low memory consumption", | ||
@@ -5,0 +5,0 @@ "main": "dist/kefir.js", |
@@ -33,3 +33,12 @@ ;(function(global){ | ||
// $.fn.asKefirProperty = function(event, selector, getter) { ... } | ||
$.fn.asKefirProperty = function(eventName, selector, getter) { | ||
if (getter == null) { | ||
getter = selector; | ||
selector = null; | ||
} | ||
getter = Kefir.Fn(getter); | ||
return this.asKefirStream(eventName, selector, getter) | ||
.toProperty(getter.invoke()) | ||
.setName('asKefirProperty'); | ||
} | ||
@@ -36,0 +45,0 @@ |
179
src/core.js
@@ -10,6 +10,35 @@ | ||
function normFnMeta(fnMeta) { | ||
if (fnMeta instanceof _Fn) { | ||
return fnMeta; | ||
} else { | ||
if (isFn(fnMeta)) { | ||
return { | ||
fn: fnMeta, | ||
context: null, | ||
args: [] | ||
}; | ||
} else { | ||
if (isArrayLike(fnMeta)) { | ||
return { | ||
fn: getFn(fnMeta[0], fnMeta[1]), | ||
context: (fnMeta[1] == null ? null : fnMeta[1]), | ||
args: rest(fnMeta, 2, []) | ||
}; | ||
} else { | ||
throw new Error('Object isn\'t a function, and can\'t be converted to it: ' + fnMeta); | ||
} | ||
} | ||
} | ||
} | ||
function applyFnMeta(fnMeta, args) { | ||
fnMeta = normFnMeta(fnMeta); | ||
return apply(fnMeta.fn, fnMeta.context, concat(fnMeta.args, args)); | ||
} | ||
function _Fn(fnMeta, length) { | ||
this.context = (fnMeta[1] == null) ? null : fnMeta[1]; | ||
this.fn = getFn(fnMeta[0], this.context); | ||
this.args = rest(fnMeta, 2, []); | ||
this.context = fnMeta.context; | ||
this.fn = fnMeta.fn; | ||
this.args = fnMeta.args; | ||
this.invoke = bind(this.fn, this.context, this.args, length); | ||
@@ -24,7 +53,3 @@ } | ||
if (this.context === null) { | ||
if (this.args.length === 0) { | ||
return apply(this.fn, context, args); | ||
} else { | ||
return apply(this.fn, context, concat(this.args, args)); | ||
} | ||
return apply(this.fn, context, concat(this.args, args)); | ||
} else { | ||
@@ -39,14 +64,3 @@ return this.apply(args); | ||
} else { | ||
if (length == null) { | ||
length = 100; | ||
} | ||
if (isFn(fnMeta)) { | ||
return new _Fn([fnMeta], length); | ||
} else { | ||
if (isArrayLike(fnMeta)) { | ||
return new _Fn(fnMeta, length); | ||
} else { | ||
throw new Error('can\'t convert to Fn ' + fnMeta); | ||
} | ||
} | ||
return new _Fn(normFnMeta(fnMeta), length == null ? 100 : length); | ||
} | ||
@@ -75,52 +89,50 @@ } | ||
function Subscribers() { | ||
this.value = []; | ||
this.end = []; | ||
this.any = []; | ||
this.total = 0; | ||
this._fns = []; | ||
} | ||
extend(Subscribers, { | ||
callOne: function(fn, event) { | ||
if (fn.type === 'any') { | ||
fn.invoke(event); | ||
} else if (fn.type === event.type) { | ||
if (fn.type === 'value') { | ||
fn.invoke(event.value); | ||
} else { | ||
fn.invoke(); | ||
} | ||
} | ||
}, | ||
callOnce: function(type, fnMeta, event) { | ||
if (type === 'any') { | ||
applyFnMeta(fnMeta, [event]); | ||
} else if (type === event.type) { | ||
if (type === 'value') { | ||
applyFnMeta(fnMeta, [event.value]); | ||
} else { | ||
applyFnMeta(fnMeta, []); | ||
} | ||
} | ||
} | ||
}); | ||
extend(Subscribers.prototype, { | ||
add: function(type, fn) { | ||
var length = (type === 'end' ? 0 : 1); | ||
this[type].push(Fn(fn, length, true)); | ||
this.total++; | ||
fn = Fn(fn, type === 'end' ? 0 : 1); | ||
fn.type = type; | ||
this._fns = concat(this._fns, [fn]); | ||
}, | ||
remove: function(type, fn) { | ||
var subs = this[type] | ||
, length = subs.length | ||
, i; | ||
fn = Fn(fn); | ||
for (i = 0; i < length; i++) { | ||
if (Fn.isEqual(subs[i], fn)) { | ||
subs.splice(i, 1); | ||
this.total--; | ||
return; | ||
} | ||
} | ||
this._fns = removeByPred(this._fns, function(x) { | ||
return x.type === type && Fn.isEqual(x, fn); | ||
}); | ||
}, | ||
call: function(type, x) { | ||
var subs = this[type] | ||
, length = subs.length | ||
, i; | ||
if (length !== 0) { | ||
if (length === 1) { | ||
if (type === 'end') { | ||
subs[0].invoke(); | ||
} else { | ||
subs[0].invoke(x); | ||
} | ||
} else { | ||
subs = cloneArray(subs); | ||
for (i = 0; i < length; i++) { | ||
if (type === 'end') { | ||
subs[i].invoke(); | ||
} else { | ||
subs[i].invoke(x); | ||
} | ||
} | ||
} | ||
callAll: function(event) { | ||
var fns = this._fns; | ||
for (var i = 0; i < fns.length; i++) { | ||
Subscribers.callOne(fns[i], event); | ||
} | ||
}, | ||
isEmpty: function() { | ||
return this.total === 0; | ||
return this._fns.length === 0; | ||
} | ||
@@ -133,2 +145,14 @@ }); | ||
// Events | ||
function Event(type, value, current) { | ||
return {type: type, value: value, current: !!current}; | ||
} | ||
var CURRENT_END = Event('end', undefined, true); | ||
// Observable | ||
@@ -169,4 +193,3 @@ | ||
if (this._alive) { | ||
this._subscribers.call(type, x); | ||
this._subscribers.call('any', {type: type, value: x, current: !!isCurrent}); | ||
this._subscribers.callAll(Event(type, x, isCurrent)); | ||
if (type === 'end') { this._clear() } | ||
@@ -176,15 +199,2 @@ } | ||
_callWithCurrent: function(fnType, fn, valueType, value) { | ||
fn = Fn(fn); | ||
if (fnType === valueType) { | ||
if (fnType === 'value') { | ||
fn.invoke(value); | ||
} else { | ||
fn.invoke(); | ||
} | ||
} else if (fnType === 'any') { | ||
fn.invoke({type: valueType, value: value, current: true}); | ||
} | ||
}, | ||
on: function(type, fn) { | ||
@@ -195,3 +205,3 @@ if (this._alive) { | ||
} else { | ||
this._callWithCurrent(type, fn, 'end'); | ||
Subscribers.callOnce(type, fn, CURRENT_END); | ||
} | ||
@@ -211,9 +221,9 @@ return this; | ||
onValue: function(fn) { this.on('value', fn) }, | ||
onEnd: function(fn) { this.on('end', fn) }, | ||
onAny: function(fn) { this.on('any', fn) }, | ||
onValue: function(fn) { return this.on('value', fn) }, | ||
onEnd: function(fn) { return this.on('end', fn) }, | ||
onAny: function(fn) { return this.on('any', fn) }, | ||
offValue: function(fn) { this.off('value', fn) }, | ||
offEnd: function(fn) { this.off('end', fn) }, | ||
offAny: function(fn) { this.off('any', fn) } | ||
offValue: function(fn) { return this.off('value', fn) }, | ||
offEnd: function(fn) { return this.off('end', fn) }, | ||
offAny: function(fn) { return this.off('any', fn) } | ||
@@ -268,4 +278,3 @@ }); | ||
if (!isCurrent) { | ||
this._subscribers.call(type, x); | ||
this._subscribers.call('any', {type: type, value: x, current: false}); | ||
this._subscribers.callAll(Event(type, x)); | ||
} | ||
@@ -283,6 +292,6 @@ if (type === 'value') { this._current = x } | ||
if (this._current !== NOTHING) { | ||
this._callWithCurrent(type, fn, 'value', this._current); | ||
Subscribers.callOnce(type, fn, Event('value', this._current, true)); | ||
} | ||
if (!this._alive) { | ||
this._callWithCurrent(type, fn, 'end'); | ||
Subscribers.callOnce(type, fn, CURRENT_END); | ||
} | ||
@@ -289,0 +298,0 @@ return this; |
@@ -1,48 +0,112 @@ | ||
// .merge() | ||
function _AbstractPool(options) { | ||
Stream.call(this); | ||
function Merge(sources) { | ||
Stream.call(this); | ||
if (sources.length === 0) { | ||
this._send('end'); | ||
} else { | ||
this._sources = sources; | ||
this._aliveCount = 0; | ||
this._queueLim = get(options, 'queueLim', 0); // -1...∞ | ||
this._concurLim = get(options, 'concurLim', -1); // -1, 1...∞ | ||
this._drop = get(options, 'drop', 'new'); // old, new | ||
if (this._concurLim === 0) { | ||
throw new Error('options.concurLim can\'t be 0'); | ||
} | ||
this._queue = []; | ||
this._curSources = []; | ||
this._activating = false; | ||
} | ||
inherit(Merge, Stream, { | ||
inherit(_AbstractPool, Stream, { | ||
_name: 'merge', | ||
_name: 'abstractPool', | ||
_onActivation: function() { | ||
var length = this._sources.length, | ||
i; | ||
this._aliveCount = length; | ||
for (i = 0; i < length; i++) { | ||
this._sources[i].onAny([this._handleAny, this]); | ||
_add: function(obs) { | ||
if (this._concurLim === -1 || this._curSources.length < this._concurLim) { | ||
this._addToCur(obs); | ||
} else { | ||
if (this._queueLim === -1 || this._queue.length < this._queueLim) { | ||
this._addToQueue(obs); | ||
} else if (this._drop === 'old') { | ||
this._removeOldest(); | ||
this._add(obs); | ||
} | ||
} | ||
}, | ||
_addAll: function(obss) { | ||
var $ = this; | ||
forEach(obss, function(obs) { $._add(obs) }); | ||
}, | ||
_remove: function(obs) { | ||
if (this._removeCur(obs) === -1) { | ||
this._removeQueue(obs); | ||
} | ||
}, | ||
_onDeactivation: function() { | ||
var length = this._sources.length, | ||
i; | ||
for (i = 0; i < length; i++) { | ||
this._sources[i].offAny([this._handleAny, this]); | ||
_addToQueue: function(obs) { | ||
this._queue = concat(this._queue, [obs]); | ||
}, | ||
_addToCur: function(obs) { | ||
this._curSources = concat(this._curSources, [obs]); | ||
if (this._active) { this._sub(obs) } | ||
}, | ||
_sub: function(obs) { | ||
obs.onAny([this._handleSubAny, this]); | ||
obs.onEnd([this._removeCur, this, obs]); | ||
}, | ||
_unsub: function(obs) { | ||
obs.offAny([this._handleSubAny, this]); | ||
obs.offEnd([this._removeCur, this, obs]); | ||
}, | ||
_handleSubAny: function(event) { | ||
if (event.type === 'value') { | ||
this._send('value', event.value, event.current && this._activating); | ||
} | ||
}, | ||
_handleAny: function(event) { | ||
if (event.type === 'value') { | ||
this._send('value', event.value, event.current); | ||
} else { | ||
this._aliveCount--; | ||
if (this._aliveCount === 0) { | ||
this._send('end', null, event.current); | ||
_removeQueue: function(obs) { | ||
var index = find(this._queue, obs); | ||
this._queue = remove(this._queue, index); | ||
return index; | ||
}, | ||
_removeCur: function(obs) { | ||
if (this._active) { this._unsub(obs) } | ||
var index = find(this._curSources, obs); | ||
this._curSources = remove(this._curSources, index); | ||
if (index !== -1) { | ||
if (this._queue.length !== 0) { | ||
this._pullQueue(); | ||
} else if (this._curSources.length === 0) { | ||
this._onEmpty(); | ||
} | ||
} | ||
return index; | ||
}, | ||
_removeOldest: function() { | ||
this._removeCur(this._curSources[0]); | ||
}, | ||
_pullQueue: function() { | ||
if (this._queue.length !== 0) { | ||
this._queue = cloneArray(this._queue); | ||
this._addToCur(this._queue.shift()); | ||
} | ||
}, | ||
_onActivation: function() { | ||
var sources = this._curSources | ||
, i; | ||
this._activating = true; | ||
for (i = 0; i < sources.length; i++) { this._sub(sources[i]) } | ||
this._activating = false; | ||
}, | ||
_onDeactivation: function() { | ||
var sources = this._curSources | ||
, i; | ||
for (i = 0; i < sources.length; i++) { this._unsub(sources[i]) } | ||
}, | ||
_isEmpty: function() { return this._curSources.length === 0 }, | ||
_onEmpty: function() {}, | ||
_clear: function() { | ||
Stream.prototype._clear.call(this); | ||
this._sources = null; | ||
this._queue = null; | ||
this._curSources = null; | ||
} | ||
@@ -52,2 +116,22 @@ | ||
// .merge() | ||
var MergeLike = { | ||
_onEmpty: function() { | ||
if (this._initialised) { this._send('end', null, this._activating) } | ||
} | ||
}; | ||
function Merge(sources) { | ||
_AbstractPool.call(this); | ||
if (sources.length === 0) { this._send('end') } else { this._addAll(sources) } | ||
this._initialised = true; | ||
} | ||
inherit(Merge, _AbstractPool, extend({_name: 'merge'}, MergeLike)); | ||
Kefir.merge = function() { | ||
@@ -64,4 +148,139 @@ return new Merge(agrsToArray(arguments)); | ||
// .concat() | ||
function Concat(sources) { | ||
_AbstractPool.call(this, {concurLim: 1, queueLim: -1}); | ||
if (sources.length === 0) { this._send('end') } else { this._addAll(sources) } | ||
this._initialised = true; | ||
} | ||
inherit(Concat, _AbstractPool, extend({_name: 'concat'}, MergeLike)); | ||
Kefir.concat = function() { | ||
return new Concat(agrsToArray(arguments)); | ||
} | ||
Observable.prototype.concat = function(other) { | ||
return Kefir.concat([this, other]); | ||
} | ||
// .pool() | ||
function Pool() { | ||
_AbstractPool.call(this); | ||
} | ||
inherit(Pool, _AbstractPool, { | ||
_name: 'pool', | ||
add: function(obs) { | ||
this._add(obs); | ||
return this; | ||
}, | ||
remove: function(obs) { | ||
this._remove(obs); | ||
return this; | ||
} | ||
}); | ||
Kefir.pool = function() { | ||
return new Pool(); | ||
} | ||
// .flatMap() | ||
function FlatMap(source, fn, options) { | ||
_AbstractPool.call(this, options); | ||
this._source = source; | ||
this._fn = fn ? Fn(fn, 1) : null; | ||
this._mainEnded = false; | ||
this._lastCurrent = null; | ||
} | ||
inherit(FlatMap, _AbstractPool, { | ||
_onActivation: function() { | ||
_AbstractPool.prototype._onActivation.call(this); | ||
this._activating = true; | ||
this._source.onAny([this._handleMainSource, this]); | ||
this._activating = false; | ||
}, | ||
_onDeactivation: function() { | ||
_AbstractPool.prototype._onDeactivation.call(this); | ||
this._source.offAny([this._handleMainSource, this]); | ||
}, | ||
_handleMainSource: function(event) { | ||
if (event.type === 'value') { | ||
if (!event.current || this._lastCurrent !== event.value) { | ||
this._add(this._fn ? this._fn.invoke(event.value) : event.value); | ||
} | ||
this._lastCurrent = event.value; | ||
} else { | ||
if (this._isEmpty()) { | ||
this._send('end', null, event.current); | ||
} else { | ||
this._mainEnded = true; | ||
} | ||
} | ||
}, | ||
_onEmpty: function() { | ||
if (this._mainEnded) { this._send('end') } | ||
}, | ||
_clear: function() { | ||
_AbstractPool.prototype._clear.call(this); | ||
this._source = null; | ||
this._lastCurrent = null; | ||
} | ||
}); | ||
Observable.prototype.flatMap = function(fn) { | ||
return new FlatMap(this, fn) | ||
.setName(this, 'flatMap'); | ||
} | ||
Observable.prototype.flatMapLatest = function(fn) { | ||
return new FlatMap(this, fn, {concurLim: 1, drop: 'old'}) | ||
.setName(this, 'flatMapLatest'); | ||
} | ||
Observable.prototype.flatMapFirst = function(fn) { | ||
return new FlatMap(this, fn, {concurLim: 1}) | ||
.setName(this, 'flatMapFirst'); | ||
} | ||
Observable.prototype.flatMapConcat = function(fn) { | ||
return new FlatMap(this, fn, {queueLim: -1, concurLim: 1}) | ||
.setName(this, 'flatMapConcat'); | ||
} | ||
Observable.prototype.flatMapWithConcurrencyLimit = function(fn, limit) { | ||
var result; | ||
if (limit === 0) { | ||
result = Kefir.never(); | ||
} else { | ||
if (limit < 0) { limit = -1 } | ||
result = new FlatMap(this, fn, {queueLim: -1, concurLim: limit}); | ||
} | ||
return result.setName(this, 'flatMapWithConcurrencyLimit'); | ||
} | ||
// .sampledBy() | ||
@@ -169,4 +388,2 @@ | ||
// .combine() | ||
@@ -183,159 +400,1 @@ | ||
} | ||
// .pool() | ||
function _AbstractPool() { | ||
Stream.call(this); | ||
this._sources = []; | ||
} | ||
inherit(_AbstractPool, Stream, { | ||
_name: 'abstractPool', | ||
_sub: function(obs) { | ||
obs.onAny([this._handleSubAny, this]); | ||
obs.onEnd([this._remove, this, obs]); | ||
}, | ||
_unsub: function(obs) { | ||
obs.offAny([this._handleSubAny, this]); | ||
obs.offEnd([this._remove, this, obs]); | ||
}, | ||
_handleSubAny: function(event) { | ||
if (event.type === 'value') { | ||
this._send('value', event.value, event.current); | ||
} | ||
}, | ||
_add: function(obs) { | ||
this._sources.push(obs); | ||
if (this._active) { | ||
this._sub(obs); | ||
} | ||
}, | ||
_remove: function(obs) { | ||
if (this._active) { | ||
this._unsub(obs); | ||
} | ||
for (var i = 0; i < this._sources.length; i++) { | ||
if (this._sources[i] === obs) { | ||
this._sources.splice(i, 1); | ||
return; | ||
} | ||
} | ||
}, | ||
_onActivation: function() { | ||
var sources = cloneArray(this._sources); | ||
for (var i = 0; i < sources.length; i++) { | ||
this._sub(sources[i]); | ||
} | ||
}, | ||
_onDeactivation: function() { | ||
for (var i = 0; i < this._sources.length; i++) { | ||
this._unsub(this._sources[i]); | ||
} | ||
} | ||
}); | ||
function Pool() { | ||
_AbstractPool.call(this); | ||
} | ||
inherit(Pool, _AbstractPool, { | ||
_name: 'pool', | ||
add: function(obs) { | ||
this._add(obs); | ||
return this; | ||
}, | ||
remove: function(obs) { | ||
this._remove(obs); | ||
return this; | ||
} | ||
}); | ||
Kefir.pool = function() { | ||
return new Pool(); | ||
} | ||
// .flatMap() | ||
function FlatMap(source, fn) { | ||
_AbstractPool.call(this); | ||
this._source = source; | ||
this._name = source._name + '.flatMap'; | ||
this._fn = fn ? Fn(fn, 1) : null; | ||
this._mainEnded = false; | ||
this._lastValue = null; | ||
} | ||
inherit(FlatMap, _AbstractPool, { | ||
_onActivation: function() { | ||
_AbstractPool.prototype._onActivation.call(this); | ||
this._source.onAny([this._handleMainSource, this]); | ||
}, | ||
_onDeactivation: function() { | ||
_AbstractPool.prototype._onDeactivation.call(this); | ||
this._source.offAny([this._handleMainSource, this]); | ||
}, | ||
_handleMainSource: function(event) { | ||
if (event.type === 'value') { | ||
if (!event.current || this._lastValue !== event.value) { | ||
this._add(this._fn ? this._fn.invoke(event.value) : event.value); | ||
} | ||
this._lastValue = event.value; | ||
} else { | ||
if (this._sources.length === 0) { | ||
this._send('end', null, event.current); | ||
} else { | ||
this._mainEnded = true; | ||
} | ||
} | ||
}, | ||
_remove: function(obs) { | ||
_AbstractPool.prototype._remove.call(this, obs); | ||
if (this._mainEnded && this._sources.length === 0) { | ||
this._send('end'); | ||
} | ||
}, | ||
_clear: function() { | ||
_AbstractPool.prototype._clear.call(this); | ||
this._source = null; | ||
this._lastValue = null; | ||
} | ||
}); | ||
Observable.prototype.flatMap = function(fn) { | ||
return new FlatMap(this, fn); | ||
} | ||
// .flatMapLatest() | ||
// TODO | ||
@@ -9,2 +9,3 @@ function produceStream(StreamClass, PropertyClass) { | ||
// .toProperty() | ||
@@ -267,2 +268,67 @@ | ||
// .debounce(wait, {immediate}) | ||
withOneSource('debounce', { | ||
_init: function(args) { | ||
this._wait = Math.max(0, args[0]); | ||
this._immediate = get(args[1], 'immediate', false); | ||
this._lastAttempt = 0; | ||
this._timeoutId = null; | ||
this._laterValue = null; | ||
this._endLater = false; | ||
var $ = this; | ||
this._$later = function() { $._later() }; | ||
}, | ||
_free: function() { | ||
this._laterValue = null; | ||
this._$later = null; | ||
}, | ||
_handleValue: function(x, isCurrent) { | ||
if (isCurrent) { | ||
this._send('value', x, isCurrent); | ||
} else { | ||
this._lastAttempt = now(); | ||
if (this._immediate && !this._timeoutId) { | ||
this._send('value', x); | ||
} | ||
if (!this._timeoutId) { | ||
this._timeoutId = setTimeout(this._$later, this._wait); | ||
} | ||
if (!this._immediate) { | ||
this._laterValue = x; | ||
} | ||
} | ||
}, | ||
_handleEnd: function(__, isCurrent) { | ||
if (isCurrent) { | ||
this._send('end', null, isCurrent); | ||
} else { | ||
if (this._timeoutId && !this._immediate) { | ||
this._endLater = true; | ||
} else { | ||
this._send('end'); | ||
} | ||
} | ||
}, | ||
_later: function() { | ||
var last = now() - this._lastAttempt; | ||
if (last < this._wait && last >= 0) { | ||
this._timeoutId = setTimeout(this._$later, this._wait - last); | ||
} else { | ||
this._timeoutId = null; | ||
if (!this._immediate) { | ||
this._send('value', this._laterValue); | ||
this._laterValue = null; | ||
} | ||
if (this._endLater) { | ||
this._send('end'); | ||
} | ||
} | ||
} | ||
}); | ||
// .throttle(wait, {leading, trailing}) | ||
@@ -272,15 +338,15 @@ | ||
_init: function(args) { | ||
this._wait = args[0]; | ||
this._wait = Math.max(0, args[0]); | ||
this._leading = get(args[1], 'leading', true); | ||
this._trailing = get(args[1], 'trailing', true); | ||
this._trailingCallValue = null; | ||
this._trailingCallTimeoutId = null; | ||
this._endAfterTrailingCall = false; | ||
this._trailingValue = null; | ||
this._timeoutId = null; | ||
this._endLater = false; | ||
this._lastCallTime = 0; | ||
var $ = this; | ||
this._$makeTrailingCall = function() { $._makeTrailingCall() }; | ||
this._$trailingCall = function() { $._trailingCall() }; | ||
}, | ||
_free: function() { | ||
this._trailingCallValue = null; | ||
this._$makeTrailingCall = null; | ||
this._trailingValue = null; | ||
this._$trailingCall = null; | ||
}, | ||
@@ -297,7 +363,9 @@ _handleValue: function(x, isCurrent) { | ||
if (remaining <= 0) { | ||
this._cancelTralingCall(); | ||
this._cancelTraling(); | ||
this._lastCallTime = curTime; | ||
this._send('value', x); | ||
} else if (this._trailing) { | ||
this._scheduleTralingCall(x, remaining); | ||
this._cancelTraling(); | ||
this._trailingValue = x; | ||
this._timeoutId = setTimeout(this._$trailingCall, remaining); | ||
} | ||
@@ -310,4 +378,4 @@ } | ||
} else { | ||
if (this._trailingCallTimeoutId) { | ||
this._endAfterTrailingCall = true; | ||
if (this._timeoutId) { | ||
this._endLater = true; | ||
} else { | ||
@@ -318,21 +386,14 @@ this._send('end'); | ||
}, | ||
_scheduleTralingCall: function(value, wait) { | ||
if (this._trailingCallTimeoutId) { | ||
this._cancelTralingCall(); | ||
_cancelTraling: function() { | ||
if (this._timeoutId !== null) { | ||
clearTimeout(this._timeoutId); | ||
this._timeoutId = null; | ||
} | ||
this._trailingCallValue = value; | ||
this._trailingCallTimeoutId = setTimeout(this._$makeTrailingCall, wait); | ||
}, | ||
_cancelTralingCall: function() { | ||
if (this._trailingCallTimeoutId !== null) { | ||
clearTimeout(this._trailingCallTimeoutId); | ||
this._trailingCallTimeoutId = null; | ||
} | ||
}, | ||
_makeTrailingCall: function() { | ||
this._send('value', this._trailingCallValue); | ||
this._trailingCallTimeoutId = null; | ||
this._trailingCallValue = null; | ||
_trailingCall: function() { | ||
this._send('value', this._trailingValue); | ||
this._timeoutId = null; | ||
this._trailingValue = null; | ||
this._lastCallTime = !this._leading ? 0 : now(); | ||
if (this._endAfterTrailingCall) { | ||
if (this._endLater) { | ||
this._send('end'); | ||
@@ -347,3 +408,2 @@ } | ||
// .delay() | ||
@@ -353,12 +413,10 @@ | ||
_init: function(args) { | ||
this._wait = args[0]; | ||
this._wait = Math.max(0, args[0]); | ||
this._buff = []; | ||
var $ = this; | ||
this._shiftBuff = function() { | ||
$._send('value', $._buff.shift()); | ||
} | ||
this._$shiftBuff = function() { $._send('value', $._buff.shift()) } | ||
}, | ||
_free: function() { | ||
this._buff = null; | ||
this._shiftBuff = null; | ||
this._$shiftBuff = null; | ||
}, | ||
@@ -370,3 +428,3 @@ _handleValue: function(x, isCurrent) { | ||
this._buff.push(x); | ||
setTimeout(this._shiftBuff, this._wait); | ||
setTimeout(this._$shiftBuff, this._wait); | ||
} | ||
@@ -373,0 +431,0 @@ }, |
@@ -99,21 +99,1 @@ // Kefir.fromBinder(fn) | ||
// Kefir.once(x) | ||
function Once(x) { | ||
Stream.call(this); | ||
this._value = x; | ||
} | ||
inherit(Once, Stream, { | ||
_name: 'once', | ||
_onActivation: function() { | ||
this._send('value', this._value); | ||
this._send('end'); | ||
} | ||
}); | ||
Kefir.once = function(x) { | ||
return new Once(x); | ||
} |
@@ -52,10 +52,2 @@ // .setName | ||
// .defer | ||
Observable.prototype.defer = function() { | ||
return this.delay(0).setName(this, 'defer'); | ||
} | ||
// .and | ||
@@ -119,1 +111,19 @@ | ||
// .fromCallback | ||
Kefir.fromCallback = function(callbackConsumer) { | ||
callbackConsumer = Fn(callbackConsumer, 1); | ||
var called = false; | ||
return Kefir.fromBinder(function(emitter) { | ||
if (!called) { | ||
callbackConsumer.invoke(function(x) { | ||
emitter.emit(x); | ||
emitter.end(); | ||
}); | ||
called = true; | ||
} | ||
}).setName('fromCallback'); | ||
} |
@@ -55,3 +55,3 @@ var NOTHING = ['<nothing>']; | ||
if (context == null || !isFn(context[fn])) { | ||
throw new Error('not a function: ' + fn + ' in ' + context); | ||
throw new Error('Not a function: ' + fn + ' in context: ' + context); | ||
} else { | ||
@@ -172,2 +172,4 @@ return context[fn]; | ||
, length, i; | ||
if (a.length === 0) { return b } | ||
if (b.length === 0) { return a } | ||
length = a.length; | ||
@@ -184,2 +186,20 @@ for (i = 0; i < length; i++, j++) { | ||
function find(arr, value) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
if (arr[i] === value) { return i } | ||
} | ||
return -1; | ||
} | ||
function findByPred(arr, pred) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
if (pred(arr[i])) { return i } | ||
} | ||
return -1; | ||
} | ||
function cloneArray(input) { | ||
@@ -195,2 +215,27 @@ var length = input.length | ||
function remove(input, index) { | ||
var length = input.length | ||
, result, i, j; | ||
if (index >= 0 && index < length) { | ||
if (length === 1) { | ||
return []; | ||
} else { | ||
result = new Array(length - 1); | ||
for (i = 0, j = 0; i < length; i++) { | ||
if (i !== index) { | ||
result[j] = input[i]; | ||
j++; | ||
} | ||
} | ||
return result; | ||
} | ||
} else { | ||
return input; | ||
} | ||
} | ||
function removeByPred(input, pred) { | ||
return remove(input, findByPred(input, pred)); | ||
} | ||
function map(input, fn) { | ||
@@ -206,2 +251,8 @@ var length = input.length | ||
function forEach(arr, fn) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { fn(arr[i]) } | ||
} | ||
function fillArray(arr, value) { | ||
@@ -216,10 +267,3 @@ var length = arr.length | ||
function contains(arr, value) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
if (arr[i] === value) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
return find(arr, value) !== -1; | ||
} | ||
@@ -226,0 +270,0 @@ |
very base stream (1000 samples) | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.38 KiB w/ subscr. +0.62 KiB sum 1.00 KiB | ||
Bacon w/o subscr. 1.93 KiB w/ subscr. +0.92 KiB sum 2.85 KiB | ||
Rx w/o subscr. 1.48 KiB w/ subscr. +1.25 KiB sum 2.73 KiB | ||
Kefir w/o subscr. 0.29 KiB w/ subscr. +0.67 KiB sum 0.96 KiB | ||
Bacon w/o subscr. 1.94 KiB w/ subscr. +0.92 KiB sum 2.86 KiB | ||
Rx w/o subscr. 1.48 KiB w/ subscr. +1.25 KiB sum 2.74 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 5.14 1.48 2.86 Rx 3.95 2.02 2.75 | ||
Kefir 1.00 1.00 1.00 Bacon 6.74 1.37 2.98 Rx 5.16 1.87 2.86 | ||
@@ -13,6 +13,6 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.20 KiB w/ subscr. +0.24 KiB sum 0.44 KiB | ||
Bacon w/o subscr. 2.65 KiB w/ subscr. +0.76 KiB sum 3.41 KiB | ||
Kefir w/o subscr. 0.11 KiB w/ subscr. +0.17 KiB sum 0.28 KiB | ||
Bacon w/o subscr. 2.69 KiB w/ subscr. +0.76 KiB sum 3.46 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 13.47 3.13 7.78 | ||
Kefir 1.00 1.00 1.00 Bacon 24.29 4.41 12.16 | ||
@@ -22,6 +22,6 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.24 KiB w/ subscr. +0.25 KiB sum 0.49 KiB | ||
Bacon w/o subscr. 2.68 KiB w/ subscr. +0.75 KiB sum 3.43 KiB | ||
Kefir w/o subscr. 0.23 KiB w/ subscr. +0.18 KiB sum 0.42 KiB | ||
Bacon w/o subscr. 2.67 KiB w/ subscr. +0.76 KiB sum 3.44 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 11.22 3.03 7.05 | ||
Kefir 1.00 1.00 1.00 Bacon 11.42 4.17 8.24 | ||
@@ -31,7 +31,7 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.45 KiB w/ subscr. +1.43 KiB sum 1.88 KiB | ||
Kefir w/o subscr. 0.28 KiB w/ subscr. +1.54 KiB sum 1.82 KiB | ||
Bacon w/o subscr. 6.46 KiB w/ subscr. +5.27 KiB sum 11.73 KiB | ||
Rx w/o subscr. 0.34 KiB w/ subscr. +3.61 KiB sum 3.95 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 14.23 3.69 6.23 Rx 0.75 2.52 2.09 | ||
Kefir 1.00 1.00 1.00 Bacon 22.74 3.42 6.43 Rx 1.19 2.34 2.16 | ||
@@ -41,7 +41,7 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.55 KiB w/ subscr. +0.82 KiB sum 1.37 KiB | ||
Bacon w/o subscr. 8.85 KiB w/ subscr. +4.28 KiB sum 13.12 KiB | ||
Kefir w/o subscr. 0.41 KiB w/ subscr. +0.83 KiB sum 1.24 KiB | ||
Bacon w/o subscr. 8.85 KiB w/ subscr. +4.28 KiB sum 13.13 KiB | ||
Rx w/o subscr. 0.42 KiB w/ subscr. +2.88 KiB sum 3.30 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 16.12 5.24 9.61 Rx 0.77 3.52 2.41 | ||
Kefir 1.00 1.00 1.00 Bacon 21.75 5.16 10.62 Rx 1.03 3.47 2.67 | ||
@@ -51,6 +51,6 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.08 KiB w/ subscr. +0.00 KiB sum 0.09 KiB | ||
Bacon w/o subscr. 2.47 KiB w/ subscr. +1.07 KiB sum 3.55 KiB | ||
Kefir w/o subscr. 0.08 KiB w/ subscr. +0.01 KiB sum 0.09 KiB | ||
Bacon w/o subscr. 2.48 KiB w/ subscr. +1.07 KiB sum 3.55 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 29.42 558.32 41.23 | ||
Kefir 1.00 1.00 1.00 Bacon 32.14 81.35 39.33 | ||
@@ -60,7 +60,7 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.48 KiB w/ subscr. +0.50 KiB sum 0.97 KiB | ||
Kefir w/o subscr. 0.41 KiB w/ subscr. +0.48 KiB sum 0.89 KiB | ||
Bacon w/o subscr. 2.41 KiB w/ subscr. +2.32 KiB sum 4.72 KiB | ||
Rx w/o subscr. 0.33 KiB w/ subscr. +3.06 KiB sum 3.40 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 5.05 4.66 4.85 Rx 0.70 6.16 3.49 | ||
Kefir 1.00 1.00 1.00 Bacon 5.88 4.84 5.32 Rx 0.82 6.41 3.83 | ||
@@ -70,7 +70,7 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.48 KiB w/ subscr. +0.50 KiB sum 0.97 KiB | ||
Bacon w/o subscr. 3.46 KiB w/ subscr. +1.35 KiB sum 4.82 KiB | ||
Kefir w/o subscr. 0.39 KiB w/ subscr. +0.48 KiB sum 0.87 KiB | ||
Bacon w/o subscr. 3.46 KiB w/ subscr. +1.35 KiB sum 4.81 KiB | ||
Rx w/o subscr. 0.37 KiB w/ subscr. +1.45 KiB sum 1.83 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 7.26 2.73 4.95 Rx 0.78 2.93 1.88 | ||
Kefir 1.00 1.00 1.00 Bacon 8.79 2.83 5.52 Rx 0.95 3.04 2.09 | ||
@@ -80,7 +80,7 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.48 KiB w/ subscr. +0.50 KiB sum 0.98 KiB | ||
Kefir w/o subscr. 0.52 KiB w/ subscr. +0.48 KiB sum 1.01 KiB | ||
Bacon w/o subscr. 2.23 KiB w/ subscr. +2.31 KiB sum 4.54 KiB | ||
Rx w/o subscr. 0.79 KiB w/ subscr. +2.49 KiB sum 3.27 KiB | ||
Rx w/o subscr. 0.79 KiB w/ subscr. +2.48 KiB sum 3.27 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 4.68 4.59 4.64 Rx 1.66 4.94 3.34 | ||
Kefir 1.00 1.00 1.00 Bacon 4.26 4.78 4.51 Rx 1.51 5.13 3.25 | ||
@@ -90,6 +90,6 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.37 KiB w/ subscr. +0.55 KiB sum 0.92 KiB | ||
Bacon w/o subscr. 2.42 KiB w/ subscr. +1.41 KiB sum 3.83 KiB | ||
Kefir w/o subscr. 0.28 KiB w/ subscr. +0.50 KiB sum 0.78 KiB | ||
Bacon w/o subscr. 2.42 KiB w/ subscr. +1.42 KiB sum 3.83 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 6.51 2.56 4.15 | ||
Kefir 1.00 1.00 1.00 Bacon 8.53 2.84 4.91 | ||
@@ -99,7 +99,7 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.47 KiB w/ subscr. +0.50 KiB sum 0.97 KiB | ||
Kefir w/o subscr. 0.38 KiB w/ subscr. +0.48 KiB sum 0.87 KiB | ||
Bacon w/o subscr. 3.46 KiB w/ subscr. +1.35 KiB sum 4.81 KiB | ||
Rx w/o subscr. 0.37 KiB w/ subscr. +1.45 KiB sum 1.82 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 7.35 2.68 4.94 Rx 0.79 2.88 1.87 | ||
Kefir 1.00 1.00 1.00 Bacon 9.08 2.79 5.56 Rx 0.97 2.99 2.11 | ||
@@ -109,7 +109,7 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.21 KiB w/ subscr. +1.30 KiB sum 1.51 KiB | ||
Bacon w/o subscr. 2.03 KiB w/ subscr. +3.14 KiB sum 5.18 KiB | ||
Rx w/o subscr. 0.65 KiB w/ subscr. +5.26 KiB sum 5.91 KiB | ||
Kefir w/o subscr. 0.32 KiB w/ subscr. +2.72 KiB sum 3.04 KiB | ||
Bacon w/o subscr. 2.03 KiB w/ subscr. +3.15 KiB sum 5.18 KiB | ||
Rx w/o subscr. 0.65 KiB w/ subscr. +5.26 KiB sum 5.92 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 9.58 2.42 3.43 Rx 3.08 4.05 3.91 | ||
Kefir 1.00 1.00 1.00 Bacon 6.29 1.16 1.70 Rx 2.02 1.94 1.94 | ||
@@ -119,7 +119,7 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. -0.00 KiB w/ subscr. -0.01 KiB sum -0.02 KiB | ||
Kefir w/o subscr. -0.00 KiB w/ subscr. -0.02 KiB sum -0.02 KiB | ||
Bacon w/o subscr. 2.05 KiB w/ subscr. +0.89 KiB sum 2.94 KiB | ||
Rx w/o subscr. 0.23 KiB w/ subscr. -0.00 KiB sum 0.23 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon -595.95 -61.33 -164.20 Rx -67.46 0.15 -12.86 | ||
Kefir 1.00 1.00 1.00 Bacon -795.94 -52.83 -151.67 Rx -90.28 0.17 -11.86 | ||
@@ -129,6 +129,6 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.56 KiB w/ subscr. +0.81 KiB sum 1.37 KiB | ||
Kefir w/o subscr. 0.47 KiB w/ subscr. +0.83 KiB sum 1.30 KiB | ||
Bacon w/o subscr. 5.97 KiB w/ subscr. +3.86 KiB sum 9.83 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 10.57 4.80 7.17 | ||
Kefir 1.00 1.00 1.00 Bacon 12.64 4.67 7.56 | ||
@@ -138,7 +138,7 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.46 KiB w/ subscr. +0.50 KiB sum 0.96 KiB | ||
Kefir w/o subscr. 0.37 KiB w/ subscr. +0.48 KiB sum 0.85 KiB | ||
Bacon w/o subscr. 2.96 KiB w/ subscr. +1.54 KiB sum 4.50 KiB | ||
Rx w/o subscr. 0.38 KiB w/ subscr. +1.15 KiB sum 1.53 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 6.44 3.09 4.70 Rx 0.84 2.30 1.60 | ||
Kefir 1.00 1.00 1.00 Bacon 8.00 3.19 5.27 Rx 1.04 2.38 1.80 | ||
@@ -148,6 +148,6 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.43 KiB w/ subscr. +0.51 KiB sum 0.94 KiB | ||
Kefir w/o subscr. 0.34 KiB w/ subscr. +0.45 KiB sum 0.80 KiB | ||
Bacon w/o subscr. 2.38 KiB w/ subscr. +1.41 KiB sum 3.79 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 5.53 2.78 4.05 | ||
Kefir 1.00 1.00 1.00 Bacon 6.91 3.11 4.76 | ||
@@ -157,7 +157,7 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.48 KiB w/ subscr. +0.50 KiB sum 0.98 KiB | ||
Kefir w/o subscr. 0.39 KiB w/ subscr. +0.48 KiB sum 0.87 KiB | ||
Bacon w/o subscr. 3.57 KiB w/ subscr. +1.35 KiB sum 4.92 KiB | ||
Rx w/o subscr. 0.38 KiB w/ subscr. +1.46 KiB sum 1.84 KiB | ||
Rx w/o subscr. 0.38 KiB w/ subscr. +1.46 KiB sum 1.83 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 7.46 2.69 5.02 Rx 0.79 2.91 1.87 | ||
Kefir 1.00 1.00 1.00 Bacon 9.07 2.81 5.63 Rx 0.96 3.03 2.10 | ||
@@ -167,7 +167,7 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.31 KiB w/ subscr. +0.50 KiB sum 0.81 KiB | ||
Kefir w/o subscr. 0.23 KiB w/ subscr. +0.48 KiB sum 0.71 KiB | ||
Bacon w/o subscr. 3.32 KiB w/ subscr. +1.35 KiB sum 4.67 KiB | ||
Rx w/o subscr. 0.29 KiB w/ subscr. +1.45 KiB sum 1.74 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 10.64 2.72 5.78 Rx 0.94 2.92 2.15 | ||
Kefir 1.00 1.00 1.00 Bacon 14.56 2.82 6.61 Rx 1.28 3.03 2.47 | ||
@@ -177,7 +177,7 @@ | ||
---------------------------------------------------------------- | ||
Kefir w/o subscr. 0.52 KiB w/ subscr. +0.50 KiB sum 1.02 KiB | ||
Kefir w/o subscr. 0.45 KiB w/ subscr. +0.48 KiB sum 0.93 KiB | ||
Bacon w/o subscr. 7.30 KiB w/ subscr. +2.18 KiB sum 9.47 KiB | ||
Rx w/o subscr. 0.43 KiB w/ subscr. +1.01 KiB sum 1.44 KiB | ||
----------------------- | ||
Kefir 1.00 1.00 1.00 Bacon 14.04 4.38 9.32 Rx 0.83 2.02 1.41 | ||
Kefir 1.00 1.00 1.00 Bacon 16.22 4.53 10.19 Rx 0.96 2.10 1.55 | ||
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 not supported yet
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 not supported yet
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 not supported yet
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 not supported yet
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 not supported yet
Sorry, the diff of this file is too big to display
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 not supported yet
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 not supported yet
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 not supported yet
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 not supported yet
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 not supported yet
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 not supported yet
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 not supported yet
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 not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
1698391
153
37729