Comparing version 0.2.10 to 0.2.11
@@ -0,1 +1,9 @@ | ||
## 0.2.11 | ||
- The `fn` argument of the `.diff` method is now optional | ||
- New method `.waitFor` | ||
- New method `.takeWhileBy` | ||
- New method `.skipWhileBy` | ||
## 0.2.10 | ||
@@ -9,4 +17,4 @@ | ||
- The `fn` argument in the `.transform` method is now optional | ||
- Transducers support via `.transduce` method | ||
- The `fn` argument of the `.transform` method is now optional | ||
- New method `.transduce` | ||
@@ -16,11 +24,8 @@ | ||
Method `.flatMapWithConcurrencyLimit` renamed to `.flatMapConcurLimit`. | ||
- Method `.flatMapWithConcurrencyLimit` renamed to `.flatMapConcurLimit` | ||
- New method `.transform` | ||
- New method `.timestamp` | ||
- New method `Kefir.bus` | ||
New methods: | ||
- .transform | ||
- .timestamp | ||
- Kefir.bus | ||
## 0.2.7 | ||
@@ -27,0 +32,0 @@ |
@@ -1,2 +0,2 @@ | ||
/*! An addon for Kefir.js v0.2.10 | ||
/*! An addon for Kefir.js v0.2.11 | ||
* https://github.com/pozadi/kefir | ||
@@ -3,0 +3,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
/*! An addon for Kefir.js v0.2.10 | ||
/*! An addon for Kefir.js v0.2.11 | ||
* https://github.com/pozadi/kefir | ||
@@ -3,0 +3,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
/*! Kefir.js v0.2.10 | ||
/*! Kefir.js v0.2.11 | ||
* https://github.com/pozadi/kefir | ||
@@ -7,63 +7,159 @@ */ | ||
var NOTHING = ['<nothing>']; | ||
var Kefir = {}; | ||
function get(map, key, notFound) { | ||
if (map && key in map) { | ||
return map[key]; | ||
} else { | ||
return notFound; | ||
function and() { | ||
for (var i = 0; i < arguments.length; i++) { | ||
if (!arguments[i]) { | ||
return arguments[i]; | ||
} | ||
} | ||
return arguments[i - 1]; | ||
} | ||
function own(obj, prop) { | ||
return Object.prototype.hasOwnProperty.call(obj, prop); | ||
function or() { | ||
for (var i = 0; i < arguments.length; i++) { | ||
if (arguments[i]) { | ||
return arguments[i]; | ||
} | ||
} | ||
return arguments[i - 1]; | ||
} | ||
function createObj(proto) { | ||
var F = function() {}; | ||
F.prototype = proto; | ||
return new F(); | ||
function concat(a, b) { | ||
var result = new Array(a.length + b.length) | ||
, j = 0 | ||
, length, i; | ||
if (a.length === 0) { return b } | ||
if (b.length === 0) { return a } | ||
length = a.length; | ||
for (i = 0; i < length; i++, j++) { | ||
result[j] = a[i]; | ||
} | ||
length = b.length; | ||
for (i = 0; i < length; i++, j++) { | ||
result[j] = b[i]; | ||
} | ||
return result; | ||
} | ||
function extend(target /*, mixin1, mixin2...*/) { | ||
var length = arguments.length | ||
, i, prop; | ||
for (i = 1; i < length; i++) { | ||
for (prop in arguments[i]) { | ||
target[prop] = arguments[i][prop]; | ||
} | ||
function find(arr, value) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
if (arr[i] === value) { return i } | ||
} | ||
return target; | ||
return -1; | ||
} | ||
function inherit(Child, Parent /*, mixin1, mixin2...*/) { | ||
var length = arguments.length | ||
function findByPred(arr, pred) { | ||
var length = arr.length | ||
, i; | ||
Child.prototype = createObj(Parent.prototype); | ||
Child.prototype.constructor = Child; | ||
for (i = 2; i < length; i++) { | ||
extend(Child.prototype, arguments[i]); | ||
for (i = 0; i < length; i++) { | ||
if (pred(arr[i])) { return i } | ||
} | ||
return Child; | ||
return -1; | ||
} | ||
function agrsToArray(args) { | ||
if (args.length === 1 && isArray(args[0])) { | ||
return args[0]; | ||
function cloneArray(input) { | ||
var length = input.length | ||
, result = new Array(length) | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
result[i] = input[i]; | ||
} | ||
return cloneArray(args); | ||
return result; | ||
} | ||
function getFn(fn, context) { | ||
if (isFn(fn)) { | ||
return fn; | ||
} else { | ||
if (context == null || !isFn(context[fn])) { | ||
throw new Error('Not a function: ' + fn + ' in context: ' + context); | ||
function remove(input, index) { | ||
var length = input.length | ||
, result, i, j; | ||
if (index >= 0 && index < length) { | ||
if (length === 1) { | ||
return []; | ||
} else { | ||
return context[fn]; | ||
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) { | ||
var length = input.length | ||
, result = new Array(length) | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
result[i] = fn(input[i]); | ||
} | ||
return result; | ||
} | ||
function forEach(arr, fn) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { fn(arr[i]) } | ||
} | ||
function fillArray(arr, value) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
arr[i] = value; | ||
} | ||
} | ||
function contains(arr, value) { | ||
return find(arr, value) !== -1; | ||
} | ||
function rest(arr, start, onEmpty) { | ||
if (arr.length > start) { | ||
return Array.prototype.slice.call(arr, start); | ||
} | ||
return onEmpty; | ||
} | ||
function slide(cur, next, max) { | ||
var length = Math.min(max, cur.length + 1), | ||
offset = cur.length - length + 1, | ||
result = new Array(length), | ||
i; | ||
for (i = offset; i < length; i++) { | ||
result[i - offset] = cur[i]; | ||
} | ||
result[length - 1] = next; | ||
return result; | ||
} | ||
function isEqualArrays(a, b) { | ||
var length, i; | ||
if (a == null && b == null) { | ||
return true; | ||
} | ||
if (a == null || b == null) { | ||
return false; | ||
} | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
for (i = 0, length = a.length; i < length; i++) { | ||
if (a[i] !== b[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function apply(fn, c, a) { | ||
@@ -174,117 +270,141 @@ var aLength = a ? a.length : 0; | ||
function concat(a, b) { | ||
var result = new Array(a.length + b.length) | ||
, j = 0 | ||
, length, i; | ||
if (a.length === 0) { return b } | ||
if (b.length === 0) { return a } | ||
length = a.length; | ||
for (i = 0; i < length; i++, j++) { | ||
result[j] = a[i]; | ||
// array functions (a.k.a fnMeta) helpers | ||
function normFnMeta(fnMeta) { | ||
var fn, context, args; | ||
if (fnMeta instanceof _Fn) { | ||
return fnMeta; | ||
} else { | ||
if (isFn(fnMeta)) { | ||
return {fn: fnMeta, context: null, args: []}; | ||
} else { | ||
if (isArrayLike(fnMeta)) { | ||
context = (fnMeta[1] == null ? null : fnMeta[1]); | ||
fn = fnMeta[0]; | ||
args = rest(fnMeta, 2, []); | ||
if (!isFn(fn)) { | ||
if (context !== null && isFn(context[fn])) { | ||
fn = context[fn]; | ||
} else { | ||
throw new Error('Object isn\'t a function, and can\'t be converted to it: ' + fnMeta); | ||
} | ||
} | ||
return {fn: fn, context: context, args: args}; | ||
} else { | ||
throw new Error('Object isn\'t a function, and can\'t be converted to it: ' + fnMeta); | ||
} | ||
} | ||
} | ||
length = b.length; | ||
for (i = 0; i < length; i++, j++) { | ||
result[j] = b[i]; | ||
} | ||
return result; | ||
} | ||
function find(arr, value) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
if (arr[i] === value) { return i } | ||
} | ||
return -1; | ||
function applyFnMeta(fnMeta, args) { | ||
fnMeta = normFnMeta(fnMeta); | ||
return apply(fnMeta.fn, fnMeta.context, concat(fnMeta.args, args)); | ||
} | ||
function findByPred(arr, pred) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
if (pred(arr[i])) { return i } | ||
} | ||
return -1; | ||
function buildFn(fnMeta, length) { | ||
fnMeta = normFnMeta(fnMeta); | ||
return bind(fnMeta.fn, fnMeta.context, fnMeta.args, length); | ||
} | ||
function cloneArray(input) { | ||
var length = input.length | ||
, result = new Array(length) | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
result[i] = input[i]; | ||
// Fn class | ||
function _Fn(fnMeta, length) { | ||
this.context = fnMeta.context; | ||
this.fn = fnMeta.fn; | ||
this.args = fnMeta.args; | ||
this.invoke = bind(this.fn, this.context, this.args, length); | ||
} | ||
_Fn.prototype.apply = function(args) { | ||
return apply(this.invoke, null, args); | ||
} | ||
_Fn.prototype.applyWithContext = function(context, args) { | ||
if (this.context === null) { | ||
return apply(this.fn, context, concat(this.args, args)); | ||
} else { | ||
return this.apply(args); | ||
} | ||
return result; | ||
} | ||
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; | ||
} | ||
function Fn(fnMeta, length) { | ||
if (fnMeta instanceof _Fn) { | ||
return fnMeta; | ||
} else { | ||
return input; | ||
return new _Fn(normFnMeta(fnMeta), length == null ? 100 : length); | ||
} | ||
} | ||
function removeByPred(input, pred) { | ||
return remove(input, findByPred(input, pred)); | ||
Fn.isEqual = function(a, b) { | ||
if (a === b) { | ||
return true; | ||
} | ||
a = Fn(a); | ||
b = Fn(b); | ||
return a.fn === b.fn && | ||
a.context === b.context && | ||
isEqualArrays(a.args, b.args); | ||
} | ||
function map(input, fn) { | ||
var length = input.length | ||
, result = new Array(length) | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
result[i] = fn(input[i]); | ||
Kefir.Fn = Fn; | ||
function get(map, key, notFound) { | ||
if (map && key in map) { | ||
return map[key]; | ||
} else { | ||
return notFound; | ||
} | ||
return result; | ||
} | ||
function forEach(arr, fn) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { fn(arr[i]) } | ||
function own(obj, prop) { | ||
return Object.prototype.hasOwnProperty.call(obj, prop); | ||
} | ||
function fillArray(arr, value) { | ||
var length = arr.length | ||
, i; | ||
for (i = 0; i < length; i++) { | ||
arr[i] = value; | ||
} | ||
function createObj(proto) { | ||
var F = function() {}; | ||
F.prototype = proto; | ||
return new F(); | ||
} | ||
function contains(arr, value) { | ||
return find(arr, value) !== -1; | ||
function extend(target /*, mixin1, mixin2...*/) { | ||
var length = arguments.length | ||
, i, prop; | ||
for (i = 1; i < length; i++) { | ||
for (prop in arguments[i]) { | ||
target[prop] = arguments[i][prop]; | ||
} | ||
} | ||
return target; | ||
} | ||
function rest(arr, start, onEmpty) { | ||
if (arr.length > start) { | ||
return Array.prototype.slice.call(arr, start); | ||
function inherit(Child, Parent /*, mixin1, mixin2...*/) { | ||
var length = arguments.length | ||
, i; | ||
Child.prototype = createObj(Parent.prototype); | ||
Child.prototype.constructor = Child; | ||
for (i = 2; i < length; i++) { | ||
extend(Child.prototype, arguments[i]); | ||
} | ||
return onEmpty; | ||
return Child; | ||
} | ||
function slide(cur, next, max) { | ||
var length = Math.min(max, cur.length + 1), | ||
offset = cur.length - length + 1, | ||
result = new Array(length), | ||
i; | ||
for (i = offset; i < length; i++) { | ||
result[i - offset] = cur[i]; | ||
var NOTHING = ['<nothing>']; | ||
function agrsToArray(args) { | ||
if (args.length === 1 && isArray(args[0])) { | ||
return args[0]; | ||
} | ||
result[length - 1] = next; | ||
return result; | ||
return cloneArray(args); | ||
} | ||
@@ -323,39 +443,2 @@ | ||
function isEqualArrays(a, b) { | ||
var length, i; | ||
if (a == null && b == null) { | ||
return true; | ||
} | ||
if (a == null || b == null) { | ||
return false; | ||
} | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
for (i = 0, length = a.length; i < length; i++) { | ||
if (a[i] !== b[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
function and() { | ||
for (var i = 0; i < arguments.length; i++) { | ||
if (!arguments[i]) { | ||
return arguments[i]; | ||
} | ||
} | ||
return arguments[i - 1]; | ||
} | ||
function or() { | ||
for (var i = 0; i < arguments.length; i++) { | ||
if (arguments[i]) { | ||
return arguments[i]; | ||
} | ||
} | ||
return arguments[i - 1]; | ||
} | ||
function withInterval(name, mixin) { | ||
@@ -480,84 +563,89 @@ | ||
function withTwoSources(name, mixin /*, options*/) { | ||
mixin = extend({ | ||
_init: function() {}, | ||
_free: function() {}, | ||
var Kefir = {}; | ||
_handlePrimaryValue: function(x, isCurrent) {}, | ||
_handlePrimaryEnd: function(__, isCurrent) { this._send('end', null, isCurrent) }, | ||
_handleSecondaryValue: function(x, isCurrent) { this._lastSecondary = x }, | ||
_handleSecondaryEnd: function(__, isCurrent) {}, | ||
_handlePrimaryAny: function(event) { | ||
switch (event.type) { | ||
case 'value': this._handlePrimaryValue(event.value, event.current); break; | ||
case 'end': this._handlePrimaryEnd(event.value, event.current); break; | ||
} | ||
}, | ||
_handleSecondaryAny: function(event) { | ||
switch (event.type) { | ||
case 'value': this._handleSecondaryValue(event.value, event.current); break; | ||
case 'end': this._handleSecondaryEnd(event.value, event.current); break; | ||
} | ||
}, | ||
_removeSecondary: function() { | ||
this._secondary.offAny([this._handleSecondaryAny, this]); | ||
this._secondary = null; | ||
this._secondaryRemoved = true; | ||
}, | ||
// Fn | ||
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); | ||
_onActivation: function() { | ||
if (!this._secondaryRemoved) { | ||
this._secondary.onAny([this._handleSecondaryAny, this]); | ||
} | ||
if (this._alive) { | ||
this._primary.onAny([this._handlePrimaryAny, this]); | ||
} | ||
}, | ||
_onDeactivation: function() { | ||
if (!this._secondaryRemoved) { | ||
this._secondary.offAny([this._handleSecondaryAny, this]); | ||
} | ||
this._primary.offAny([this._handlePrimaryAny, this]); | ||
} | ||
} | ||
} | ||
}, mixin || {}); | ||
function applyFnMeta(fnMeta, args) { | ||
fnMeta = normFnMeta(fnMeta); | ||
return apply(fnMeta.fn, fnMeta.context, concat(fnMeta.args, args)); | ||
} | ||
function _Fn(fnMeta, length) { | ||
this.context = fnMeta.context; | ||
this.fn = fnMeta.fn; | ||
this.args = fnMeta.args; | ||
this.invoke = bind(this.fn, this.context, this.args, length); | ||
} | ||
_Fn.prototype.apply = function(args) { | ||
return apply(this.invoke, null, args); | ||
} | ||
function buildClass(BaseClass) { | ||
function AnonymousObservable(primary, secondary) { | ||
BaseClass.call(this); | ||
this._primary = primary; | ||
this._secondary = secondary; | ||
this._name = primary._name + '.' + name; | ||
this._lastSecondary = NOTHING; | ||
this._secondaryRemoved = false; | ||
this._init(); | ||
} | ||
_Fn.prototype.applyWithContext = function(context, args) { | ||
if (this.context === null) { | ||
return apply(this.fn, context, concat(this.args, args)); | ||
} else { | ||
return this.apply(args); | ||
} | ||
} | ||
inherit(AnonymousObservable, BaseClass, { | ||
_clear: function() { | ||
BaseClass.prototype._clear.call(this); | ||
this._primary = null; | ||
this._secondary = null; | ||
this._lastSecondary = null; | ||
this._free(); | ||
} | ||
}, mixin); | ||
function Fn(fnMeta, length) { | ||
if (fnMeta instanceof _Fn) { | ||
return fnMeta; | ||
} else { | ||
return new _Fn(normFnMeta(fnMeta), length == null ? 100 : length); | ||
return AnonymousObservable; | ||
} | ||
} | ||
Fn.isEqual = function(a, b) { | ||
if (a === b) { | ||
return true; | ||
} | ||
a = Fn(a, null, true); | ||
b = Fn(b, null, true); | ||
return a.fn === b.fn && | ||
a.context === b.context && | ||
isEqualArrays(a.args, b.args); | ||
} | ||
Kefir.Fn = Fn; | ||
var AnonymousStream = buildClass(Stream); | ||
var AnonymousProperty = buildClass(Property); | ||
Stream.prototype[name] = function(secondary) { | ||
return new AnonymousStream(this, secondary); | ||
} | ||
Property.prototype[name] = function(secondary) { | ||
return new AnonymousProperty(this, secondary); | ||
} | ||
} | ||
// Subscribers | ||
@@ -804,3 +892,3 @@ | ||
_init: function(args) { | ||
this._fn = Fn(args[0], 1); | ||
this._fn = buildFn(args[0], 1); | ||
var $ = this; | ||
@@ -817,3 +905,3 @@ this._emitter = { | ||
_onTick: function() { | ||
this._fn.invoke(this._emitter); | ||
this._fn(this._emitter); | ||
} | ||
@@ -830,3 +918,3 @@ }); | ||
_init: function(args) { | ||
this._fn = Fn(args[0], 0); | ||
this._fn = buildFn(args[0], 0); | ||
}, | ||
@@ -837,3 +925,3 @@ _free: function() { | ||
_onTick: function() { | ||
this._send('value', this._fn.invoke()); | ||
this._send('value', this._fn()); | ||
} | ||
@@ -1165,3 +1253,3 @@ }); | ||
this._source = source; | ||
this._fn = fn ? Fn(fn, 1) : null; | ||
this._fn = fn ? buildFn(fn, 1) : null; | ||
this._mainEnded = false; | ||
@@ -1187,3 +1275,3 @@ this._lastCurrent = null; | ||
if (!event.current || this._lastCurrent !== event.value) { | ||
this._add(this._fn ? this._fn.invoke(event.value) : event.value); | ||
this._add(this._fn ? this._fn(event.value) : event.value); | ||
} | ||
@@ -1400,3 +1488,3 @@ this._lastCurrent = event.value; | ||
_init: function(args) { | ||
this._handler = Fn(args[0], 2); | ||
this._handler = buildFn(args[0], 2); | ||
this._forcedCurrent = false; | ||
@@ -1415,3 +1503,3 @@ var $ = this; | ||
this._forcedCurrent = event.current; | ||
this._handler.invoke(this._emitter, event); | ||
this._handler(this._emitter, event); | ||
this._forcedCurrent = false; | ||
@@ -1428,3 +1516,3 @@ } | ||
_init: function(args) { | ||
this._fn = args[0] ? Fn(args[0], 1) : null; | ||
this._fn = args[0] ? buildFn(args[0], 1) : null; | ||
}, | ||
@@ -1435,3 +1523,3 @@ _free: function() { | ||
_handleValue: function(x, isCurrent) { | ||
var xs = this._fn === null ? x : this._fn.invoke(x); | ||
var xs = this._fn === null ? x : this._fn(x); | ||
for (var i = 0; i < xs.length; i++) { | ||
@@ -1499,3 +1587,3 @@ this._send('value', xs[i], isCurrent); | ||
var withFnArgMixin = { | ||
_init: function(args) { this._fn = Fn(args[0], 1) }, | ||
_init: function(args) { this._fn = buildFn(args[0], 1) }, | ||
_free: function() { this._fn = null } | ||
@@ -1510,3 +1598,3 @@ }; | ||
_handleValue: function(x, isCurrent) { | ||
this._send('value', this._fn.invoke(x), isCurrent); | ||
this._send('value', this._fn(x), isCurrent); | ||
} | ||
@@ -1523,3 +1611,3 @@ }, withFnArgMixin)); | ||
_handleValue: function(x, isCurrent) { | ||
if (this._fn.invoke(x)) { | ||
if (this._fn(x)) { | ||
this._send('value', x, isCurrent); | ||
@@ -1538,3 +1626,3 @@ } | ||
_handleValue: function(x, isCurrent) { | ||
if (this._fn.invoke(x)) { | ||
if (this._fn(x)) { | ||
this._send('value', x, isCurrent); | ||
@@ -1564,3 +1652,3 @@ } else { | ||
if (this._n === 0) { | ||
this._send('end'); | ||
this._send('end', null, isCurrent); | ||
} | ||
@@ -1596,3 +1684,3 @@ } | ||
_init: function(args) { | ||
this._fn = args[0] ? Fn(args[0], 2) : null; | ||
this._fn = args[0] ? buildFn(args[0], 2) : null; | ||
this._prev = NOTHING; | ||
@@ -1605,3 +1693,3 @@ }, | ||
_isEqual: function(a, b) { | ||
return this._fn === null ? a === b : this._fn.invoke(a, b); | ||
return this._fn === null ? a === b : this._fn(a, b); | ||
}, | ||
@@ -1624,3 +1712,3 @@ _handleValue: function(x, isCurrent) { | ||
_init: function(args) { | ||
this._fn = Fn(args[0], 1); | ||
this._fn = buildFn(args[0], 1); | ||
this._skip = true; | ||
@@ -1636,3 +1724,3 @@ }, | ||
} | ||
if (!this._fn.invoke(x)) { | ||
if (!this._fn(x)) { | ||
this._skip = false; | ||
@@ -1654,3 +1742,3 @@ this._fn = null; | ||
this._prev = args[0]; | ||
this._fn = Fn(args[1], 2); | ||
this._fn = args[1] ? buildFn(args[1], 2) : null; | ||
}, | ||
@@ -1662,3 +1750,6 @@ _free: function() { | ||
_handleValue: function(x, isCurrent) { | ||
this._send('value', this._fn.invoke(this._prev, x), isCurrent); | ||
var result = (this._fn === null) ? | ||
[this._prev, x] : | ||
this._fn(this._prev, x); | ||
this._send('value', result, isCurrent); | ||
this._prev = x; | ||
@@ -1677,3 +1768,3 @@ } | ||
this._send('value', args[0], true); | ||
this._fn = Fn(args[1], 2); | ||
this._fn = buildFn(args[1], 2); | ||
}, | ||
@@ -1684,3 +1775,3 @@ _free: function() { | ||
_handleValue: function(x, isCurrent) { | ||
this._send('value', this._fn.invoke(this._current, x), isCurrent); | ||
this._send('value', this._fn(this._current, x), isCurrent); | ||
} | ||
@@ -1698,3 +1789,3 @@ }, {streamMethod: produceProperty}); | ||
this._result = args[0]; | ||
this._fn = Fn(args[1], 2); | ||
this._fn = buildFn(args[1], 2); | ||
}, | ||
@@ -1706,3 +1797,3 @@ _free: function() { | ||
_handleValue: function(x) { | ||
this._result = this._fn.invoke(this._result, x); | ||
this._result = this._fn(this._result, x); | ||
}, | ||
@@ -1911,3 +2002,3 @@ _handleEnd: function(__, isCurrent) { | ||
Stream.call(this); | ||
this._fn = Fn(fn, 1); | ||
this._fn = buildFn(fn, 1); | ||
this._unsubscribe = null; | ||
@@ -1928,6 +2019,6 @@ } | ||
}; | ||
unsub = this._fn.invoke(emitter); | ||
unsub = this._fn(emitter); | ||
isCurrent = false; | ||
if (unsub) { | ||
this._unsubscribe = Fn(unsub, 0); | ||
this._unsubscribe = buildFn(unsub, 0); | ||
} | ||
@@ -1937,3 +2028,3 @@ }, | ||
if (this._unsubscribe !== null) { | ||
this._unsubscribe.invoke(); | ||
this._unsubscribe(); | ||
this._unsubscribe = null; | ||
@@ -2067,5 +2158,5 @@ } | ||
Observable.prototype.tap = function(fn) { | ||
fn = Fn(fn, 1); | ||
fn = buildFn(fn, 1); | ||
return this.map(function(x) { | ||
fn.invoke(x); | ||
fn(x); | ||
return x; | ||
@@ -2120,28 +2211,11 @@ }).setName(this, 'tap'); | ||
// .filterBy | ||
Observable.prototype.filterBy = function(other) { | ||
return other | ||
.sampledBy(this) | ||
.withHandler(function(emitter, e) { | ||
if (e.type === 'end') { | ||
emitter.end(); | ||
} else if (e.value[0]) { | ||
emitter.emit(e.value[1]); | ||
} | ||
}) | ||
.setName(this, 'filterBy'); | ||
} | ||
// .fromCallback | ||
Kefir.fromCallback = function(callbackConsumer) { | ||
callbackConsumer = Fn(callbackConsumer, 1); | ||
callbackConsumer = buildFn(callbackConsumer, 1); | ||
var called = false; | ||
return Kefir.fromBinder(function(emitter) { | ||
if (!called) { | ||
callbackConsumer.invoke(function(x) { | ||
callbackConsumer(function(x) { | ||
emitter.emit(x); | ||
@@ -2176,3 +2250,93 @@ emitter.end(); | ||
withTwoSources('filterBy', { | ||
_handlePrimaryValue: function(x, isCurrent) { | ||
if (this._lastSecondary !== NOTHING && this._lastSecondary) { | ||
this._send('value', x, isCurrent); | ||
} | ||
}, | ||
_handleSecondaryEnd: function(__, isCurrent) { | ||
if (this._lastSecondary === NOTHING || !this._lastSecondary) { | ||
this._send('end', null, isCurrent); | ||
} | ||
} | ||
}); | ||
withTwoSources('waitFor', { | ||
_handlePrimaryValue: function(x, isCurrent) { | ||
if (this._lastSecondary !== NOTHING) { | ||
this._send('value', x, isCurrent); | ||
} | ||
}, | ||
_handleSecondaryValue: function(x) { | ||
this._lastSecondary = x; | ||
this._removeSecondary(); | ||
}, | ||
_handleSecondaryEnd: function(__, isCurrent) { | ||
if (this._lastSecondary === NOTHING) { | ||
this._send('end', null, isCurrent); | ||
} | ||
} | ||
}); | ||
withTwoSources('takeWhileBy', { | ||
_handlePrimaryValue: function(x, isCurrent) { | ||
if (this._lastSecondary !== NOTHING) { | ||
this._send('value', x, isCurrent); | ||
} | ||
}, | ||
_handleSecondaryValue: function(x, isCurrent) { | ||
this._lastSecondary = x; | ||
if (!this._lastSecondary) { | ||
this._send('end', null, isCurrent); | ||
} | ||
}, | ||
_handleSecondaryEnd: function(__, isCurrent) { | ||
if (this._lastSecondary === NOTHING) { | ||
this._send('end', null, isCurrent); | ||
} | ||
} | ||
}); | ||
withTwoSources('skipWhileBy', { | ||
_handlePrimaryValue: function(x, isCurrent) { | ||
if (this._lastSecondary !== NOTHING && !this._lastSecondary) { | ||
this._send('value', x, isCurrent); | ||
} | ||
}, | ||
_handleSecondaryValue: function(x, isCurrent) { | ||
this._lastSecondary = x; | ||
if (!this._lastSecondary) { | ||
this._removeSecondary(); | ||
} | ||
}, | ||
_handleSecondaryEnd: function(__, isCurrent) { | ||
if (this._lastSecondary === NOTHING || this._lastSecondary) { | ||
this._send('end', null, isCurrent); | ||
} | ||
} | ||
}); | ||
if (typeof define === 'function' && define.amd) { | ||
@@ -2179,0 +2343,0 @@ define([], function() { |
@@ -1,6 +0,6 @@ | ||
/*! Kefir.js v0.2.10 | ||
/*! Kefir.js v0.2.11 | ||
* 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&&bb(a[0])?a[0]:p(a)}function h(a,b){if(x(a))return a;if(null!=b&&x(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,b,c){var d,e=Math.min(c,a.length+1),f=a.length-e+1,g=new Array(e);for(d=f;e>d;d++)g[d-f]=a[d];return g[e-1]=b,g}function x(a){return"function"==typeof a}function y(a){return bb(a)||cb(a)}function z(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 A(){for(var a=0;a<arguments.length;a++)if(!arguments[a])return arguments[a];return arguments[a-1]}function B(){for(var a=0;a<arguments.length;a++)if(arguments[a])return arguments[a];return arguments[a-1]}function C(a,b){function c(a,b){L.call(this),this._wait=a,this._intervalId=null;var c=this;this._$onTick=function(){c._onTick()},this._init(b)}f(c,L,{_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(){L.prototype._clear.call(this),this._$onTick=null,this._free()}},b),db[a]=function(a){return new c(a,v(arguments,1,[]))}}function D(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(L),h=d(M);c.streamMethod&&(L.prototype[a]=c.streamMethod(g,h)),c.propertyMethod&&(M.prototype[a]=c.propertyMethod(g,h))}function E(a){if(a instanceof G)return a;if(x(a))return{fn:a,context:null,args:[]};if(y(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 F(a,b){return a=E(a),i(a.fn,a.context,m(a.args,b))}function G(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 H(a,b){return a instanceof G?a:new G(E(a),null==b?100:b)}function I(){this._fns=[]}function J(a,b,c){return{type:a,value:b,current:!!c}}function K(){this._subscribers=new I,this._active=!1,this._alive=!0}function L(){K.call(this)}function M(){K.call(this),this._current=_}function N(a,b){var c="<"+b.type+(b.current?":current":"")+">";"value"===b.type?console.log(a,c,b.value):console.log(a,c)}function O(a){if(L.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 P(a){O.call(this),0===a.length?this._send("end"):this._addAll(a),this._initialised=!0}function Q(a){O.call(this,{concurLim:1,queueLim:-1}),0===a.length?this._send("end"):this._addAll(a),this._initialised=!0}function R(){O.call(this)}function S(){O.call(this)}function T(a,b,c){O.call(this,c),this._source=a,this._fn=b?H(b,1):null,this._mainEnded=!1,this._lastCurrent=null}function U(a,b,c){L.call(this),0===b.length?this._send("end"):(this._passiveCount=a.length,this._combinator=c?H(c):null,this._sources=m(a,b),this._aliveCount=0,this._currents=new Array(this._sources.length),t(this._currents,_),this._activating=!1,this._emitAfterActivation=!1,this._endAfterActivation=!1)}function V(a){return function(){return new a(this,arguments)}}function W(a,b){return function(){return new b(this,arguments)}}function X(a){return{init:function(){return null},step:function(b,c){return a._send("value",c,a._forcedCurrent),null},result:function(){return a._send("end",null,a._forcedCurrent),null}}}function Y(a){L.call(this),this._fn=H(a,1),this._unsubscribe=null}function Z(){L.call(this)}function $(a){M.call(this),this._send("value",a),this._send("end")}var _=["<nothing>"],ab=Date.now?function(){return Date.now()}:function(){return(new Date).getTime()},bb=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},cb=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};cb(arguments)||(cb=function(a){return!(!a||!c(a,"callee"))});var db={};G.prototype.apply=function(a){return i(this.invoke,null,a)},G.prototype.applyWithContext=function(a,b){return null===this.context?i(this.fn,a,m(this.args,b)):this.apply(b)},H.isEqual=function(a,b){return a===b?!0:(a=H(a,null,!0),b=H(b,null,!0),a.fn===b.fn&&a.context===b.context&&z(a.args,b.args))},db.Fn=H,e(I,{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?F(b,[c]):a===c.type&&("value"===a?F(b,[c.value]):F(b,[]))}}),e(I.prototype,{add:function(a,b){b=H(b,"end"===a?0:1),b.type=a,this._fns=m(this._fns,[b])},remove:function(a,b){b=H(b),this._fns=r(this._fns,function(c){return c.type===a&&H.isEqual(c,b)})},callAll:function(a){for(var b=this._fns,c=0;c<b.length;c++)I.callOne(b[c],a)},isEmpty:function(){return 0===this._fns.length}});var eb=J("end",void 0,!0);db.Observable=K,e(K.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(J(a,b,c)),"end"===a&&this._clear())},on:function(a,b){return this._alive?(this._subscribers.add(a,b),this._setActive(!0)):I.callOnce(a,b,eb),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)}}),K.prototype.toString=function(){return"["+this._name+"]"},db.Stream=L,f(L,K,{_name:"stream"}),db.Property=M,f(M,K,{_name:"property",_send:function(a,b,c){this._alive&&(c||this._subscribers.callAll(J(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!==_&&I.callOnce(a,b,J("value",this._current,!0)),this._alive||I.callOnce(a,b,eb),this}}),K.prototype.log=function(a){return this.onAny([N,null,a||this.toString()]),this},K.prototype.offLog=function(a){return this.offAny([N,null,a||this.toString()]),this},C("withInterval",{_init:function(a){this._fn=H(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)}}),C("fromPoll",{_init:function(a){this._fn=H(a[0],0)},_free:function(){this._fn=null},_onTick:function(){this._send("value",this._fn.invoke())}}),C("interval",{_init:function(a){this._x=a[0]},_free:function(){this._x=null},_onTick:function(){this._send("value",this._x)}}),C("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())}}}),C("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]))}}),C("later",{_init:function(a){this._x=a[0]},_free:function(){this._x=null},_onTick:function(){this._send("value",this._x),this._send("end")}}),f(O,L,{_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(){L.prototype._clear.call(this),this._queue=null,this._curSources=null}});var fb={_onEmpty:function(){this._initialised&&this._send("end",null,this._activating)}};f(P,O,e({_name:"merge"},fb)),db.merge=function(){return new P(g(arguments))},K.prototype.merge=function(a){return db.merge([this,a])},f(Q,O,e({_name:"concat"},fb)),db.concat=function(){return new Q(g(arguments))},K.prototype.concat=function(a){return db.concat([this,a])},f(R,O,{_name:"pool",plug:function(a){return this._add(a),this},unplug:function(a){return this._remove(a),this}}),db.pool=function(){return new R},f(S,O,{_name:"bus",plug:function(a){return this._add(a),this},unplug:function(a){return this._remove(a),this},emit:function(a){return this._send("value",a),this},end:function(){return this._send("end"),this}}),db.bus=function(){return new S},f(T,O,{_onActivation:function(){O.prototype._onActivation.call(this),this._activating=!0,this._source.onAny([this._handleMainSource,this]),this._activating=!1},_onDeactivation:function(){O.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(){O.prototype._clear.call(this),this._source=null,this._lastCurrent=null}}),K.prototype.flatMap=function(a){return new T(this,a).setName(this,"flatMap")},K.prototype.flatMapLatest=function(a){return new T(this,a,{concurLim:1,drop:"old"}).setName(this,"flatMapLatest")},K.prototype.flatMapFirst=function(a){return new T(this,a,{concurLim:1}).setName(this,"flatMapFirst")},K.prototype.flatMapConcat=function(a){return new T(this,a,{queueLim:-1,concurLim:1}).setName(this,"flatMapConcat")},K.prototype.flatMapConcurLimit=function(a,b){var c;return 0===b?c=db.never():(0>b&&(b=-1),c=new T(this,a,{queueLim:-1,concurLim:b})),c.setName(this,"flatMapConcurLimit")},f(U,L,{_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,_)){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(){L.prototype._clear.call(this),this._sources=null,this._currents=null}}),db.sampledBy=function(a,b,c){return new U(a,b,c)},K.prototype.sampledBy=function(a,b){return db.sampledBy([this],[a],b)},db.combine=function(a,b){var c=new U([],a,b);return c._name="combine",c},K.prototype.combine=function(a,b){return db.combine([this,a],b)},D("toProperty",{_init:function(a){a.length>0&&this._send("value",a[0])}},{propertyMethod:null,streamMethod:W}),D("changes",{_handleValue:function(a,b){b||this._send("value",a)}},{streamMethod:null,propertyMethod:V}),D("withHandler",{_init:function(a){this._handler=H(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}}),D("flatten",{_init:function(a){this._fn=a[0]?H(a[0],1):null},_free:function(){this._fn=null},_handleValue:function(a,b){for(var c=null===this._fn?a:this._fn.invoke(a),d=0;d<c.length;d++)this._send("value",c[d],b)}}),D("transduce",{_init:function(a){this._xform=a[0](X(this)),this._forcedCurrent=!0,this._endIfReduced(this._xform.init()),this._forcedCurrent=!1},_free:function(){this._xform=null},_endIfReduced:function(a){null!==a&&this._xform.result(null)},_handleValue:function(a,b){this._forcedCurrent=b,this._endIfReduced(this._xform.step(null,a)),this._forcedCurrent=!1},_handleEnd:function(a,b){this._forcedCurrent=b,this._xform.result(null),this._forcedCurrent=!1}});var gb={_init:function(a){this._fn=H(a[0],1)},_free:function(){this._fn=null}};D("map",e({_handleValue:function(a,b){this._send("value",this._fn.invoke(a),b)}},gb)),D("filter",e({_handleValue:function(a,b){this._fn.invoke(a)&&this._send("value",a,b)}},gb)),D("takeWhile",e({_handleValue:function(a,b){this._fn.invoke(a)?this._send("value",a,b):this._send("end",null,b)}},gb)),D("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")}}),D("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--}}),D("skipDuplicates",{_init:function(a){this._fn=a[0]?H(a[0],2):null,this._prev=_},_free:function(){this._fn=null,this._prev=null},_isEqual:function(a,b){return null===this._fn?a===b:this._fn.invoke(a,b)},_handleValue:function(a,b){this._prev!==_&&this._isEqual(this._prev,a)||(this._send("value",a,b),this._prev=a)}}),D("skipWhile",{_init:function(a){this._fn=H(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)}}),D("diff",{_init:function(a){this._prev=a[0],this._fn=H(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}}),D("scan",{_init:function(a){this._send("value",a[0],!0),this._fn=H(a[1],2)},_free:function(){this._fn=null},_handleValue:function(a,b){this._send("value",this._fn.invoke(this._current,a),b)}},{streamMethod:W}),D("reduce",{_init:function(a){this._result=a[0],this._fn=H(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)}}),D("slidingWindow",{_init:function(a){this._max=a[0],this._min=a[1]||0,this._cache=[]},_free:function(){this._cache=null},_handleValue:function(a,b){this._cache=w(this._cache,a,this._max),this._cache.length>=this._min&&this._send("value",this._cache,b)}}),D("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=ab(),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=ab()-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"))}}),D("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=ab();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?ab():0,this._endLater&&this._send("end")}}),D("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(Y,L,{_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=H(a,0))},_onDeactivation:function(){null!==this._unsubscribe&&(this._unsubscribe.invoke(),this._unsubscribe=null)},_clear:function(){L.prototype._clear.call(this),this._fn=null}}),db.fromBinder=function(a){return new Y(a)},f(Z,L,{_name:"emitter",emit:function(a){return this._send("value",a),this},end:function(){return this._send("end"),this}}),db.emitter=function(){return new Z};var hb=new L;hb._send("end"),hb._name="never",db.never=function(){return hb},f($,M,{_name:"constant"}),db.constant=function(a){return new $(a)},K.prototype.setName=function(a,b){return this._name=b?a._name+"."+b:a,this},K.prototype.mapTo=function(a){return this.map(function(){return a}).setName(this,"mapTo")},K.prototype.pluck=function(a){return this.map(function(b){return b[a]}).setName(this,"pluck")},K.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")},K.prototype.timestamp=function(){return this.map(function(a){return{value:a,time:ab()}}).setName(this,"timestamp")},K.prototype.tap=function(a){return a=H(a,1),this.map(function(b){return a.invoke(b),b}).setName(this,"tap")},db.and=function(a){return db.combine(a,A).setName("and")},K.prototype.and=function(a){return this.combine(a,A).setName("and")},db.or=function(a){return db.combine(a,B).setName("or")},K.prototype.or=function(a){return this.combine(a,B).setName("or")},K.prototype.not=function(){return this.map(function(a){return!a}).setName(this,"not")},K.prototype.awaiting=function(a){return db.merge([this.mapTo(!0),a.mapTo(!1)]).skipDuplicates().toProperty(!1).setName(this,"awaiting")},K.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")},db.fromCallback=function(a){a=H(a,1);var b=!1;return db.fromBinder(function(c){b||(a.invoke(function(a){c.emit(a),c.end()}),b=!0)}).setName("fromCallback")},db.fromEvent=function(a,b,c){c=c&&H(c);var d=a.addEventListener||a.addListener||a.bind,e=a.removeEventListener||a.removeListener||a.unbind;return db.fromBinder(function(f){var g=c?function(){f.emit(c.applyWithContext(this,arguments))}:f.emit;return d.call(a,b,g),function(){e.call(a,b,g)}}).setName("fromEvent")},"function"==typeof define&&define.amd?(define([],function(){return db}),a.Kefir=db):"object"==typeof module&&"object"==typeof exports?(module.exports=db,db.Kefir=db):a.Kefir=db}(this); | ||
!function(a){"use strict";function b(){for(var a=0;a<arguments.length;a++)if(!arguments[a])return arguments[a];return arguments[a-1]}function c(){for(var a=0;a<arguments.length;a++)if(arguments[a])return arguments[a];return arguments[a-1]}function d(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 e(a,b){var c,d=a.length;for(c=0;d>c;c++)if(a[c]===b)return c;return-1}function f(a,b){var c,d=a.length;for(c=0;d>c;c++)if(b(a[c]))return c;return-1}function g(a){var b,c=a.length,d=new Array(c);for(b=0;c>b;b++)d[b]=a[b];return d}function h(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 i(a,b){return h(a,f(a,b))}function j(a,b){var c,d=a.length;for(c=0;d>c;c++)b(a[c])}function k(a,b){var c,d=a.length;for(c=0;d>c;c++)a[c]=b}function l(a,b){return-1!==e(a,b)}function m(a,b,c){return a.length>b?Array.prototype.slice.call(a,b):c}function n(a,b,c){var d,e=Math.min(c,a.length+1),f=a.length-e+1,g=new Array(e);for(d=f;e>d;d++)g[d-f]=a[d];return g[e-1]=b,g}function o(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 p(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 q(a,b,c){var e=b[0],f=b[1],g=b[2],h=b[3];switch(c){case 0:switch(b.length){case 0:return a;case 1:return function(){return a(e)};case 2:return function(){return a(e,f)};case 3:return function(){return a(e,f,g)};case 4:return function(){return a(e,f,g,h)};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(e,b)};case 2:return function(b){return a(e,f,b)};case 3:return function(b){return a(e,f,g,b)};case 4:return function(b){return a(e,f,g,h,b)};default:return function(c){return a.apply(null,d(b,[c]))}}break;case 2:switch(b.length){case 0:return a;case 1:return function(b,c){return a(e,b,c)};case 2:return function(b,c){return a(e,f,b,c)};case 3:return function(b,c){return a(e,f,g,b,c)};case 4:return function(b,c){return a(e,f,g,h,b,c)};default:return function(c,e){return a.apply(null,d(b,[c,e]))}}break;default:switch(b.length){case 0:return a;default:return function(){return p(a,null,d(b,arguments))}}}}function r(a,b,c,e){var f=c[0],g=c[1],h=c[2],i=c[3];switch(e){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,f,c)};case 2:return function(c){return a.call(b,f,g,c)};case 3:return function(c){return a.call(b,f,g,h,c)};case 4:return function(c){return a.call(b,f,g,h,i,c)};default:return function(e){return a.apply(b,d(c,[e]))}}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,f,c,d)};case 2:return function(c,d){return a.call(b,f,g,c,d)};case 3:return function(c,d){return a.call(b,f,g,h,c,d)};case 4:return function(c,d){return a.call(b,f,g,h,i,c,d)};default:return function(e,f){return a.apply(b,d(c,[e,f]))}}break;default:switch(c.length){case 0:return function(){return a.apply(b,arguments)};default:return function(){return a.apply(b,d(c,arguments))}}}}function s(a,b,c,d){return null==b?q(a,c,d):r(a,b,c,d)}function t(a){var b,c,d;if(a instanceof w)return a;if(E(a))return{fn:a,context:null,args:[]};if(F(a)){if(c=null==a[1]?null:a[1],b=a[0],d=m(a,2,[]),!E(b)){if(null===c||!E(c[b]))throw new Error("Object isn't a function, and can't be converted to it: "+a);b=c[b]}return{fn:b,context:c,args:d}}throw new Error("Object isn't a function, and can't be converted to it: "+a)}function u(a,b){return a=t(a),p(a.fn,a.context,d(a.args,b))}function v(a,b){return a=t(a),s(a.fn,a.context,a.args,b)}function w(a,b){this.context=a.context,this.fn=a.fn,this.args=a.args,this.invoke=s(this.fn,this.context,this.args,b)}function x(a,b){return a instanceof w?a:new w(t(a),null==b?100:b)}function y(a,b,c){return a&&b in a?a[b]:c}function z(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function A(a){var b=function(){};return b.prototype=a,new b}function B(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 C(a,b){var c,d=arguments.length;for(a.prototype=A(b.prototype),a.prototype.constructor=a,c=2;d>c;c++)B(a.prototype,arguments[c]);return a}function D(a){return 1===a.length&&db(a[0])?a[0]:g(a)}function E(a){return"function"==typeof a}function F(a){return db(a)||eb(a)}function G(a,b){function c(a,b){M.call(this),this._wait=a,this._intervalId=null;var c=this;this._$onTick=function(){c._onTick()},this._init(b)}C(c,M,{_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(){M.prototype._clear.call(this),this._$onTick=null,this._free()}},b),ab[a]=function(a){return new c(a,m(arguments,1,[]))}}function H(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 C(d,c,{_clear:function(){c.prototype._clear.call(this),this._source=null,this._free()}},b),d}c=B({streamMethod:function(a){return function(){return new a(this,arguments)}},propertyMethod:function(a,b){return function(){return new b(this,arguments)}}},c||{}),b=B({_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 e=d(M),f=d(N);c.streamMethod&&(M.prototype[a]=c.streamMethod(e,f)),c.propertyMethod&&(N.prototype[a]=c.propertyMethod(e,f))}function I(a,b){function c(c){function d(b,d){c.call(this),this._primary=b,this._secondary=d,this._name=b._name+"."+a,this._lastSecondary=bb,this._secondaryRemoved=!1,this._init()}return C(d,c,{_clear:function(){c.prototype._clear.call(this),this._primary=null,this._secondary=null,this._lastSecondary=null,this._free()}},b),d}b=B({_init:function(){},_free:function(){},_handlePrimaryValue:function(){},_handlePrimaryEnd:function(a,b){this._send("end",null,b)},_handleSecondaryValue:function(a){this._lastSecondary=a},_handleSecondaryEnd:function(){},_handlePrimaryAny:function(a){switch(a.type){case"value":this._handlePrimaryValue(a.value,a.current);break;case"end":this._handlePrimaryEnd(a.value,a.current)}},_handleSecondaryAny:function(a){switch(a.type){case"value":this._handleSecondaryValue(a.value,a.current);break;case"end":this._handleSecondaryEnd(a.value,a.current)}},_removeSecondary:function(){this._secondary.offAny([this._handleSecondaryAny,this]),this._secondary=null,this._secondaryRemoved=!0},_onActivation:function(){this._secondaryRemoved||this._secondary.onAny([this._handleSecondaryAny,this]),this._alive&&this._primary.onAny([this._handlePrimaryAny,this])},_onDeactivation:function(){this._secondaryRemoved||this._secondary.offAny([this._handleSecondaryAny,this]),this._primary.offAny([this._handlePrimaryAny,this])}},b||{});var d=c(M),e=c(N);M.prototype[a]=function(a){return new d(this,a)},N.prototype[a]=function(a){return new e(this,a)}}function J(){this._fns=[]}function K(a,b,c){return{type:a,value:b,current:!!c}}function L(){this._subscribers=new J,this._active=!1,this._alive=!0}function M(){L.call(this)}function N(){L.call(this),this._current=bb}function O(a,b){var c="<"+b.type+(b.current?":current":"")+">";"value"===b.type?console.log(a,c,b.value):console.log(a,c)}function P(a){if(M.call(this),this._queueLim=y(a,"queueLim",0),this._concurLim=y(a,"concurLim",-1),this._drop=y(a,"drop","new"),0===this._concurLim)throw new Error("options.concurLim can't be 0");this._queue=[],this._curSources=[],this._activating=!1}function Q(a){P.call(this),0===a.length?this._send("end"):this._addAll(a),this._initialised=!0}function R(a){P.call(this,{concurLim:1,queueLim:-1}),0===a.length?this._send("end"):this._addAll(a),this._initialised=!0}function S(){P.call(this)}function T(){P.call(this)}function U(a,b,c){P.call(this,c),this._source=a,this._fn=b?v(b,1):null,this._mainEnded=!1,this._lastCurrent=null}function V(a,b,c){M.call(this),0===b.length?this._send("end"):(this._passiveCount=a.length,this._combinator=c?x(c):null,this._sources=d(a,b),this._aliveCount=0,this._currents=new Array(this._sources.length),k(this._currents,bb),this._activating=!1,this._emitAfterActivation=!1,this._endAfterActivation=!1)}function W(a){return function(){return new a(this,arguments)}}function X(a,b){return function(){return new b(this,arguments)}}function Y(a){return{init:function(){return null},step:function(b,c){return a._send("value",c,a._forcedCurrent),null},result:function(){return a._send("end",null,a._forcedCurrent),null}}}function Z(a){M.call(this),this._fn=v(a,1),this._unsubscribe=null}function $(){M.call(this)}function _(a){N.call(this),this._send("value",a),this._send("end")}var ab={};w.prototype.apply=function(a){return p(this.invoke,null,a)},w.prototype.applyWithContext=function(a,b){return null===this.context?p(this.fn,a,d(this.args,b)):this.apply(b)},x.isEqual=function(a,b){return a===b?!0:(a=x(a),b=x(b),a.fn===b.fn&&a.context===b.context&&o(a.args,b.args))},ab.Fn=x;var bb=["<nothing>"],cb=Date.now?function(){return Date.now()}:function(){return(new Date).getTime()},db=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},eb=function(a){return"[object Arguments]"===Object.prototype.toString.call(a)};eb(arguments)||(eb=function(a){return!(!a||!z(a,"callee"))}),B(J,{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?u(b,[c]):a===c.type&&("value"===a?u(b,[c.value]):u(b,[]))}}),B(J.prototype,{add:function(a,b){b=x(b,"end"===a?0:1),b.type=a,this._fns=d(this._fns,[b])},remove:function(a,b){b=x(b),this._fns=i(this._fns,function(c){return c.type===a&&x.isEqual(c,b)})},callAll:function(a){for(var b=this._fns,c=0;c<b.length;c++)J.callOne(b[c],a)},isEmpty:function(){return 0===this._fns.length}});var fb=K("end",void 0,!0);ab.Observable=L,B(L.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(K(a,b,c)),"end"===a&&this._clear())},on:function(a,b){return this._alive?(this._subscribers.add(a,b),this._setActive(!0)):J.callOnce(a,b,fb),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)}}),L.prototype.toString=function(){return"["+this._name+"]"},ab.Stream=M,C(M,L,{_name:"stream"}),ab.Property=N,C(N,L,{_name:"property",_send:function(a,b,c){this._alive&&(c||this._subscribers.callAll(K(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!==bb&&J.callOnce(a,b,K("value",this._current,!0)),this._alive||J.callOnce(a,b,fb),this}}),L.prototype.log=function(a){return this.onAny([O,null,a||this.toString()]),this},L.prototype.offLog=function(a){return this.offAny([O,null,a||this.toString()]),this},G("withInterval",{_init:function(a){this._fn=v(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(this._emitter)}}),G("fromPoll",{_init:function(a){this._fn=v(a[0],0)},_free:function(){this._fn=null},_onTick:function(){this._send("value",this._fn())}}),G("interval",{_init:function(a){this._x=a[0]},_free:function(){this._x=null},_onTick:function(){this._send("value",this._x)}}),G("sequentially",{_init:function(a){this._xs=g(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())}}}),G("repeatedly",{_init:function(a){this._xs=g(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]))}}),G("later",{_init:function(a){this._x=a[0]},_free:function(){this._x=null},_onTick:function(){this._send("value",this._x),this._send("end")}}),C(P,M,{_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;j(a,function(a){b._add(a)})},_remove:function(a){-1===this._removeCur(a)&&this._removeQueue(a)},_addToQueue:function(a){this._queue=d(this._queue,[a])},_addToCur:function(a){this._curSources=d(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=e(this._queue,a);return this._queue=h(this._queue,b),b},_removeCur:function(a){this._active&&this._unsub(a);var b=e(this._curSources,a);return this._curSources=h(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=g(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(){M.prototype._clear.call(this),this._queue=null,this._curSources=null}});var gb={_onEmpty:function(){this._initialised&&this._send("end",null,this._activating)}};C(Q,P,B({_name:"merge"},gb)),ab.merge=function(){return new Q(D(arguments))},L.prototype.merge=function(a){return ab.merge([this,a])},C(R,P,B({_name:"concat"},gb)),ab.concat=function(){return new R(D(arguments))},L.prototype.concat=function(a){return ab.concat([this,a])},C(S,P,{_name:"pool",plug:function(a){return this._add(a),this},unplug:function(a){return this._remove(a),this}}),ab.pool=function(){return new S},C(T,P,{_name:"bus",plug:function(a){return this._add(a),this},unplug:function(a){return this._remove(a),this},emit:function(a){return this._send("value",a),this},end:function(){return this._send("end"),this}}),ab.bus=function(){return new T},C(U,P,{_onActivation:function(){P.prototype._onActivation.call(this),this._activating=!0,this._source.onAny([this._handleMainSource,this]),this._activating=!1},_onDeactivation:function(){P.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(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(){P.prototype._clear.call(this),this._source=null,this._lastCurrent=null}}),L.prototype.flatMap=function(a){return new U(this,a).setName(this,"flatMap")},L.prototype.flatMapLatest=function(a){return new U(this,a,{concurLim:1,drop:"old"}).setName(this,"flatMapLatest")},L.prototype.flatMapFirst=function(a){return new U(this,a,{concurLim:1}).setName(this,"flatMapFirst")},L.prototype.flatMapConcat=function(a){return new U(this,a,{queueLim:-1,concurLim:1}).setName(this,"flatMapConcat")},L.prototype.flatMapConcurLimit=function(a,b){var c;return 0===b?c=ab.never():(0>b&&(b=-1),c=new U(this,a,{queueLim:-1,concurLim:b})),c.setName(this,"flatMapConcurLimit")},C(V,M,{_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(!l(this._currents,bb)){var b=g(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(){M.prototype._clear.call(this),this._sources=null,this._currents=null}}),ab.sampledBy=function(a,b,c){return new V(a,b,c)},L.prototype.sampledBy=function(a,b){return ab.sampledBy([this],[a],b)},ab.combine=function(a,b){var c=new V([],a,b);return c._name="combine",c},L.prototype.combine=function(a,b){return ab.combine([this,a],b)},H("toProperty",{_init:function(a){a.length>0&&this._send("value",a[0])}},{propertyMethod:null,streamMethod:X}),H("changes",{_handleValue:function(a,b){b||this._send("value",a)}},{streamMethod:null,propertyMethod:W}),H("withHandler",{_init:function(a){this._handler=v(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(this._emitter,a),this._forcedCurrent=!1}}),H("flatten",{_init:function(a){this._fn=a[0]?v(a[0],1):null},_free:function(){this._fn=null},_handleValue:function(a,b){for(var c=null===this._fn?a:this._fn(a),d=0;d<c.length;d++)this._send("value",c[d],b)}}),H("transduce",{_init:function(a){this._xform=a[0](Y(this)),this._forcedCurrent=!0,this._endIfReduced(this._xform.init()),this._forcedCurrent=!1},_free:function(){this._xform=null},_endIfReduced:function(a){null!==a&&this._xform.result(null)},_handleValue:function(a,b){this._forcedCurrent=b,this._endIfReduced(this._xform.step(null,a)),this._forcedCurrent=!1},_handleEnd:function(a,b){this._forcedCurrent=b,this._xform.result(null),this._forcedCurrent=!1}});var hb={_init:function(a){this._fn=v(a[0],1)},_free:function(){this._fn=null}};H("map",B({_handleValue:function(a,b){this._send("value",this._fn(a),b)}},hb)),H("filter",B({_handleValue:function(a,b){this._fn(a)&&this._send("value",a,b)}},hb)),H("takeWhile",B({_handleValue:function(a,b){this._fn(a)?this._send("value",a,b):this._send("end",null,b)}},hb)),H("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",null,b)}}),H("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--}}),H("skipDuplicates",{_init:function(a){this._fn=a[0]?v(a[0],2):null,this._prev=bb},_free:function(){this._fn=null,this._prev=null},_isEqual:function(a,b){return null===this._fn?a===b:this._fn(a,b)},_handleValue:function(a,b){this._prev!==bb&&this._isEqual(this._prev,a)||(this._send("value",a,b),this._prev=a)}}),H("skipWhile",{_init:function(a){this._fn=v(a[0],1),this._skip=!0},_free:function(){this._fn=null},_handleValue:function(a,b){return this._skip?void(this._fn(a)||(this._skip=!1,this._fn=null,this._send("value",a,b))):void this._send("value",a,b)}}),H("diff",{_init:function(a){this._prev=a[0],this._fn=a[1]?v(a[1],2):null},_free:function(){this._prev=null,this._fn=null},_handleValue:function(a,b){var c=null===this._fn?[this._prev,a]:this._fn(this._prev,a);this._send("value",c,b),this._prev=a}}),H("scan",{_init:function(a){this._send("value",a[0],!0),this._fn=v(a[1],2)},_free:function(){this._fn=null},_handleValue:function(a,b){this._send("value",this._fn(this._current,a),b)}},{streamMethod:X}),H("reduce",{_init:function(a){this._result=a[0],this._fn=v(a[1],2)},_free:function(){this._fn=null,this._result=null},_handleValue:function(a){this._result=this._fn(this._result,a)},_handleEnd:function(a,b){this._send("value",this._result,b),this._send("end",null,b)}}),H("slidingWindow",{_init:function(a){this._max=a[0],this._min=a[1]||0,this._cache=[]},_free:function(){this._cache=null},_handleValue:function(a,b){this._cache=n(this._cache,a,this._max),this._cache.length>=this._min&&this._send("value",this._cache,b)}}),H("debounce",{_init:function(a){this._wait=Math.max(0,a[0]),this._immediate=y(a[1],"immediate",!1),this._lastAttempt=0,this._timeoutId=null,this._laterValue=null,this._endLater=!1;var b=this;this._$later=function(){b._later()}},_free:function(){this._laterValue=null,this._$later=null},_handleValue:function(a,b){b?this._send("value",a,b):(this._lastAttempt=cb(),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=cb()-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"))}}),H("throttle",{_init:function(a){this._wait=Math.max(0,a[0]),this._leading=y(a[1],"leading",!0),this._trailing=y(a[1],"trailing",!0),this._trailingValue=null,this._timeoutId=null,this._endLater=!1,this._lastCallTime=0;var b=this;this._$trailingCall=function(){b._trailingCall()}},_free:function(){this._trailingValue=null,this._$trailingCall=null},_handleValue:function(a,b){if(b)this._send("value",a,b);else{var c=cb();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?cb():0,this._endLater&&this._send("end")}}),H("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)}}}),C(Z,M,{_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(d),c=!1,a&&(this._unsubscribe=v(a,0))},_onDeactivation:function(){null!==this._unsubscribe&&(this._unsubscribe(),this._unsubscribe=null)},_clear:function(){M.prototype._clear.call(this),this._fn=null}}),ab.fromBinder=function(a){return new Z(a)},C($,M,{_name:"emitter",emit:function(a){return this._send("value",a),this},end:function(){return this._send("end"),this}}),ab.emitter=function(){return new $};var ib=new M;ib._send("end"),ib._name="never",ab.never=function(){return ib},C(_,N,{_name:"constant"}),ab.constant=function(a){return new _(a)},L.prototype.setName=function(a,b){return this._name=b?a._name+"."+b:a,this},L.prototype.mapTo=function(a){return this.map(function(){return a}).setName(this,"mapTo")},L.prototype.pluck=function(a){return this.map(function(b){return b[a]}).setName(this,"pluck")},L.prototype.invoke=function(a){var b=m(arguments,1);return this.map(b?function(c){return p(c[a],c,b)}:function(b){return b[a]()}).setName(this,"invoke")},L.prototype.timestamp=function(){return this.map(function(a){return{value:a,time:cb()}}).setName(this,"timestamp")},L.prototype.tap=function(a){return a=v(a,1),this.map(function(b){return a(b),b}).setName(this,"tap")},ab.and=function(a){return ab.combine(a,b).setName("and")},L.prototype.and=function(a){return this.combine(a,b).setName("and")},ab.or=function(a){return ab.combine(a,c).setName("or")},L.prototype.or=function(a){return this.combine(a,c).setName("or")},L.prototype.not=function(){return this.map(function(a){return!a}).setName(this,"not")},L.prototype.awaiting=function(a){return ab.merge([this.mapTo(!0),a.mapTo(!1)]).skipDuplicates().toProperty(!1).setName(this,"awaiting")},ab.fromCallback=function(a){a=v(a,1);var b=!1;return ab.fromBinder(function(c){b||(a(function(a){c.emit(a),c.end()}),b=!0)}).setName("fromCallback")},ab.fromEvent=function(a,b,c){c=c&&x(c);var d=a.addEventListener||a.addListener||a.bind,e=a.removeEventListener||a.removeListener||a.unbind;return ab.fromBinder(function(f){var g=c?function(){f.emit(c.applyWithContext(this,arguments))}:f.emit;return d.call(a,b,g),function(){e.call(a,b,g)}}).setName("fromEvent")},I("filterBy",{_handlePrimaryValue:function(a,b){this._lastSecondary!==bb&&this._lastSecondary&&this._send("value",a,b)},_handleSecondaryEnd:function(a,b){this._lastSecondary!==bb&&this._lastSecondary||this._send("end",null,b)}}),I("waitFor",{_handlePrimaryValue:function(a,b){this._lastSecondary!==bb&&this._send("value",a,b)},_handleSecondaryValue:function(a){this._lastSecondary=a,this._removeSecondary()},_handleSecondaryEnd:function(a,b){this._lastSecondary===bb&&this._send("end",null,b)}}),I("takeWhileBy",{_handlePrimaryValue:function(a,b){this._lastSecondary!==bb&&this._send("value",a,b)},_handleSecondaryValue:function(a,b){this._lastSecondary=a,this._lastSecondary||this._send("end",null,b)},_handleSecondaryEnd:function(a,b){this._lastSecondary===bb&&this._send("end",null,b)}}),I("skipWhileBy",{_handlePrimaryValue:function(a,b){this._lastSecondary===bb||this._lastSecondary||this._send("value",a,b)},_handleSecondaryValue:function(a){this._lastSecondary=a,this._lastSecondary||this._removeSecondary()},_handleSecondaryEnd:function(a,b){(this._lastSecondary===bb||this._lastSecondary)&&this._send("end",null,b)}}),"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.10", | ||
"version": "0.2.11", | ||
"description": "FRP library for JavaScript inspired by Bacon.js and RxJS with focus on high performance and low memory consumption", | ||
@@ -32,3 +32,3 @@ "main": "dist/kefir.js", | ||
"devDependencies": { | ||
"baconjs": "~0.7.22", | ||
"baconjs": "~0.7.28", | ||
"benchmark": "~1.0.0", | ||
@@ -39,3 +39,3 @@ "coffee-script": "~1.8.0", | ||
"grunt-bower-task": "~0.4.0", | ||
"grunt-browserify": "~3.0.0", | ||
"grunt-browserify": "~3.1.0", | ||
"grunt-cli": "~0.1.13", | ||
@@ -51,3 +51,3 @@ "grunt-contrib-clean": "~0.6.0", | ||
"jquery": "~1.11.1", | ||
"load-grunt-tasks": "~0.6.0", | ||
"load-grunt-tasks": "~1.0.0", | ||
"marked": "~0.3.2", | ||
@@ -57,5 +57,5 @@ "rx": "~2.3.3", | ||
"shelljs": "~0.3.0", | ||
"sinon": "~1.10.1", | ||
"sinon": "~1.11.1", | ||
"transducers-js": "0.4.135", | ||
"transducers.js": "0.2.2" | ||
"transducers.js": "~0.2.3" | ||
}, | ||
@@ -62,0 +62,0 @@ "testling": { |
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
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
123151
1959