Comparing version 0.2.6 to 0.2.7
var flyd = require('flyd'); | ||
var flatMap = require('flyd/module/flatmap'); | ||
var takeUntil = require('flyd/module/takeuntil'); | ||
@@ -16,3 +15,3 @@ | ||
var mousedrag = flatMap(function(md) { | ||
var mousedrag = flyd.chain(function(md) { | ||
var startX = md.offsetX, startY = md.offsetY; | ||
@@ -19,0 +18,0 @@ |
597
flyd.js
@@ -1,6 +0,205 @@ | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.flyd = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
'use strict'; | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.flyd = factory()); | ||
}(this, (function () { 'use strict'; | ||
var curryN = require('ramda/src/curryN'); | ||
function _arity(n, fn) { | ||
/* eslint-disable no-unused-vars */ | ||
switch (n) { | ||
case 0: | ||
return function () { | ||
return fn.apply(this, arguments); | ||
}; | ||
case 1: | ||
return function (a0) { | ||
return fn.apply(this, arguments); | ||
}; | ||
case 2: | ||
return function (a0, a1) { | ||
return fn.apply(this, arguments); | ||
}; | ||
case 3: | ||
return function (a0, a1, a2) { | ||
return fn.apply(this, arguments); | ||
}; | ||
case 4: | ||
return function (a0, a1, a2, a3) { | ||
return fn.apply(this, arguments); | ||
}; | ||
case 5: | ||
return function (a0, a1, a2, a3, a4) { | ||
return fn.apply(this, arguments); | ||
}; | ||
case 6: | ||
return function (a0, a1, a2, a3, a4, a5) { | ||
return fn.apply(this, arguments); | ||
}; | ||
case 7: | ||
return function (a0, a1, a2, a3, a4, a5, a6) { | ||
return fn.apply(this, arguments); | ||
}; | ||
case 8: | ||
return function (a0, a1, a2, a3, a4, a5, a6, a7) { | ||
return fn.apply(this, arguments); | ||
}; | ||
case 9: | ||
return function (a0, a1, a2, a3, a4, a5, a6, a7, a8) { | ||
return fn.apply(this, arguments); | ||
}; | ||
case 10: | ||
return function (a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { | ||
return fn.apply(this, arguments); | ||
}; | ||
default: | ||
throw new Error('First argument to _arity must be a non-negative integer no greater than ten'); | ||
} | ||
} | ||
var _arity_1 = _arity; | ||
function _isPlaceholder(a) { | ||
return a != null && typeof a === 'object' && a['@@functional/placeholder'] === true; | ||
} | ||
var _isPlaceholder_1 = _isPlaceholder; | ||
/** | ||
* Optimized internal one-arity curry function. | ||
* | ||
* @private | ||
* @category Function | ||
* @param {Function} fn The function to curry. | ||
* @return {Function} The curried function. | ||
*/ | ||
function _curry1(fn) { | ||
return function f1(a) { | ||
if (arguments.length === 0 || _isPlaceholder_1(a)) { | ||
return f1; | ||
} else { | ||
return fn.apply(this, arguments); | ||
} | ||
}; | ||
} | ||
var _curry1_1 = _curry1; | ||
/** | ||
* Optimized internal two-arity curry function. | ||
* | ||
* @private | ||
* @category Function | ||
* @param {Function} fn The function to curry. | ||
* @return {Function} The curried function. | ||
*/ | ||
function _curry2(fn) { | ||
return function f2(a, b) { | ||
switch (arguments.length) { | ||
case 0: | ||
return f2; | ||
case 1: | ||
return _isPlaceholder_1(a) ? f2 : _curry1_1(function (_b) { | ||
return fn(a, _b); | ||
}); | ||
default: | ||
return _isPlaceholder_1(a) && _isPlaceholder_1(b) ? f2 : _isPlaceholder_1(a) ? _curry1_1(function (_a) { | ||
return fn(_a, b); | ||
}) : _isPlaceholder_1(b) ? _curry1_1(function (_b) { | ||
return fn(a, _b); | ||
}) : fn(a, b); | ||
} | ||
}; | ||
} | ||
var _curry2_1 = _curry2; | ||
/** | ||
* Internal curryN function. | ||
* | ||
* @private | ||
* @category Function | ||
* @param {Number} length The arity of the curried function. | ||
* @param {Array} received An array of arguments received thus far. | ||
* @param {Function} fn The function to curry. | ||
* @return {Function} The curried function. | ||
*/ | ||
function _curryN(length, received, fn) { | ||
return function () { | ||
var combined = []; | ||
var argsIdx = 0; | ||
var left = length; | ||
var combinedIdx = 0; | ||
while (combinedIdx < received.length || argsIdx < arguments.length) { | ||
var result; | ||
if (combinedIdx < received.length && (!_isPlaceholder_1(received[combinedIdx]) || argsIdx >= arguments.length)) { | ||
result = received[combinedIdx]; | ||
} else { | ||
result = arguments[argsIdx]; | ||
argsIdx += 1; | ||
} | ||
combined[combinedIdx] = result; | ||
if (!_isPlaceholder_1(result)) { | ||
left -= 1; | ||
} | ||
combinedIdx += 1; | ||
} | ||
return left <= 0 ? fn.apply(this, combined) : _arity_1(left, _curryN(length, combined, fn)); | ||
}; | ||
} | ||
var _curryN_1 = _curryN; | ||
/** | ||
* Returns a curried equivalent of the provided function, with the specified | ||
* arity. The curried function has two unusual capabilities. First, its | ||
* arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the | ||
* following are equivalent: | ||
* | ||
* - `g(1)(2)(3)` | ||
* - `g(1)(2, 3)` | ||
* - `g(1, 2)(3)` | ||
* - `g(1, 2, 3)` | ||
* | ||
* Secondly, the special placeholder value [`R.__`](#__) may be used to specify | ||
* "gaps", allowing partial application of any combination of arguments, | ||
* regardless of their positions. If `g` is as above and `_` is [`R.__`](#__), | ||
* the following are equivalent: | ||
* | ||
* - `g(1, 2, 3)` | ||
* - `g(_, 2, 3)(1)` | ||
* - `g(_, _, 3)(1)(2)` | ||
* - `g(_, _, 3)(1, 2)` | ||
* - `g(_, 2)(1)(3)` | ||
* - `g(_, 2)(1, 3)` | ||
* - `g(_, 2)(_, 3)(1)` | ||
* | ||
* @func | ||
* @memberOf R | ||
* @since v0.5.0 | ||
* @category Function | ||
* @sig Number -> (* -> a) -> (* -> a) | ||
* @param {Number} length The arity for the returned function. | ||
* @param {Function} fn The function to curry. | ||
* @return {Function} A new, curried function. | ||
* @see R.curry | ||
* @example | ||
* | ||
* var sumArgs = (...args) => R.sum(args); | ||
* | ||
* var curriedAddFourNumbers = R.curryN(4, sumArgs); | ||
* var f = curriedAddFourNumbers(1, 2); | ||
* var g = f(3); | ||
* g(4); //=> 10 | ||
*/ | ||
var curryN = /*#__PURE__*/_curry2_1(function curryN(length, fn) { | ||
if (length === 1) { | ||
return _curry1_1(fn); | ||
} | ||
return _arity_1(length, _curryN_1(length, [], fn)); | ||
}); | ||
var curryN_1 = curryN; | ||
// Utility | ||
@@ -20,3 +219,3 @@ function isFunction(obj) { | ||
/** @namespace */ | ||
var flyd = {} | ||
var flyd = {}; | ||
@@ -44,9 +243,9 @@ // /////////////////////////// API ///////////////////////////////// // | ||
endStream.listeners.push(s); | ||
s.toJSON = function() { | ||
return s(); | ||
}; | ||
if (arguments.length > 0) s(initialValue); | ||
return s; | ||
} | ||
}; | ||
// fantasy-land Applicative | ||
flyd.stream['fantasy-land/of'] = flyd.stream.of = flyd.stream; | ||
/** | ||
@@ -69,3 +268,3 @@ * Create a new dependent stream | ||
*/ | ||
flyd.combine = curryN(2, combine); | ||
flyd.combine = curryN_1(2, combine); | ||
function combine(fn, streams) { | ||
@@ -109,3 +308,3 @@ var i, s, deps, depEndStreams; | ||
return isFunction(stream) && 'hasVal' in stream; | ||
} | ||
}; | ||
@@ -143,3 +342,3 @@ /** | ||
return s; | ||
} | ||
}; | ||
@@ -169,3 +368,3 @@ /** | ||
return s; | ||
} | ||
}; | ||
@@ -190,7 +389,56 @@ /** | ||
// Library functions use self callback to accept (null, undefined) update triggers. | ||
flyd.map = curryN(2, function(f, s) { | ||
flyd.map = curryN_1(2, function(f, s) { | ||
return combine(function(s, self) { self(f(s.val)); }, [s]); | ||
}) | ||
}); | ||
/** | ||
* Chain a stream | ||
* | ||
* also known as flatMap | ||
* | ||
* Where `fn` returns a stream this function will flatten the resulting streams. | ||
* Every time `fn` is called the context of the returned stream will "switch" to that stream. | ||
* | ||
* __Signature__: `(a -> Stream b) -> Stream a -> Stream b` | ||
* | ||
* @name flyd.chain | ||
* @param {Function} fn - the function that produces the streams to be flattened | ||
* @param {stream} stream - the stream to map | ||
* @return {stream} a new stream with the mapped values | ||
* | ||
* @example | ||
* var filter = flyd.stream('who'); | ||
* var items = flyd.chain(function(filter){ | ||
* return flyd.stream(findUsers(filter)); | ||
* }, filter); | ||
*/ | ||
flyd.chain = curryN_1(2, chain); | ||
/** | ||
* Apply a stream | ||
* | ||
* Applies the value in `s2` to the function in `s1`. | ||
* | ||
* __Signature__: `Stream (a -> b) -> Stream a -> Stream b` | ||
* | ||
* @name flyd.ap | ||
* @param {stream} s1 - The value to be applied | ||
* @param {stream} s2 - The function expecting the value | ||
* @return {stream} a new stream with the mapped values | ||
* | ||
* @example | ||
* var add = stream(a => b => a + b) | ||
* var n1 = stream(1) | ||
* var n2 = stream(2) | ||
* | ||
* var added = flyd.ap(n2, flyd.ap(n1, add)) // stream(3) | ||
* // can also be written using pipe | ||
* var added_pipe = add | ||
* .pipe(ap(n1)) | ||
* .pipe(ap(n2)); | ||
* added_pipe() // 3 | ||
*/ | ||
flyd.ap = curryN_1(2, ap); | ||
/** | ||
* Listen to stream events | ||
@@ -209,5 +457,5 @@ * | ||
*/ | ||
flyd.on = curryN(2, function(f, s) { | ||
flyd.on = curryN_1(2, function(f, s) { | ||
return combine(function(s) { f(s.val); }, [s]); | ||
}) | ||
}); | ||
@@ -232,3 +480,3 @@ /** | ||
*/ | ||
flyd.scan = curryN(3, function(f, acc, s) { | ||
flyd.scan = curryN_1(3, function(f, acc, s) { | ||
var ns = combine(function(s, self) { | ||
@@ -259,3 +507,3 @@ self(acc = f(acc, s.val)); | ||
*/ | ||
flyd.merge = curryN(2, function(s1, s2) { | ||
flyd.merge = curryN_1(2, function(s1, s2) { | ||
var s = flyd.immediate(combine(function(s1, s2, self, changed) { | ||
@@ -297,3 +545,3 @@ if (changed[0]) { | ||
*/ | ||
flyd.transduce = curryN(2, function(xform, source) { | ||
flyd.transduce = curryN_1(2, function(xform, source) { | ||
xform = xform(new StreamTransformer()); | ||
@@ -326,3 +574,3 @@ return combine(function(source, self) { | ||
*/ | ||
flyd.curryN = curryN | ||
flyd.curryN = curryN_1; | ||
@@ -349,2 +597,66 @@ /** | ||
/** | ||
* Returns the result of applying function `fn` to this stream | ||
* | ||
* __Signature__: Called bound to `Stream a`: `(a -> Stream b) -> Stream b` | ||
* | ||
* @name stream.pipe | ||
* @param {Function} fn - the function to apply | ||
* @return {stream} A new stream | ||
* | ||
* @example | ||
* var numbers = flyd.stream(0); | ||
* var squaredNumbers = numbers.pipe(flyd.map(function(n){ return n*n; })); | ||
*/ | ||
function operator_pipe(f) { return f(this) } | ||
function boundChain(f) { | ||
return chain(f, this); | ||
} | ||
function chain(f, s) { | ||
// Internal state to end flat map stream | ||
var flatEnd = flyd.stream(1); | ||
var internalEnded = flyd.on(function() { | ||
var alive = flatEnd() - 1; | ||
flatEnd(alive); | ||
if (alive <= 0) { | ||
flatEnd.end(true); | ||
} | ||
}); | ||
internalEnded(s.end); | ||
var last = flyd.stream(); | ||
var flatStream = flyd.combine(function(s, own) { | ||
last.end(true); | ||
// Our fn stream makes streams | ||
var newS = f(s()); | ||
flatEnd(flatEnd() + 1); | ||
internalEnded(newS.end); | ||
// Update self on call -- newS is never handed out so deps don't matter | ||
last = flyd.map(own, newS); | ||
}, [s]); | ||
flyd.endsOn(flatEnd.end, flatStream); | ||
return flatStream; | ||
} | ||
flyd.fromPromise = function fromPromise(p) { | ||
var s = flyd.stream(); | ||
p.then(function(val) { | ||
s(val); | ||
s.end(true); | ||
}); | ||
return s; | ||
}; | ||
flyd.flattenPromise = function flattenPromise(s) { | ||
return combine(function(s, self) { | ||
s().then(self); | ||
}, [s]) | ||
}; | ||
/** | ||
* Returns a new stream which is the result of applying the | ||
@@ -371,8 +683,18 @@ * functions from `this` stream to the values in `stream` parameter. | ||
*/ | ||
function ap(s2) { | ||
var s1 = this; | ||
function ap(s2, s1) { | ||
return combine(function(s1, s2, self) { self(s1.val(s2.val)); }, [s1, s2]); | ||
} | ||
function boundAp(s2) { | ||
return ap(s2, this); | ||
} | ||
/** | ||
* @private | ||
*/ | ||
function fantasy_land_ap(s1) { | ||
return ap(this, s1); | ||
} | ||
/** | ||
* Get a human readable view of a stream | ||
@@ -419,3 +741,3 @@ * @name stream.toString | ||
if (arguments.length === 0) return s.val | ||
updateStreamValue(s, n) | ||
updateStreamValue(s, n); | ||
return s | ||
@@ -429,5 +751,20 @@ } | ||
s.end = undefined; | ||
s.map = boundMap; | ||
s.ap = ap; | ||
s.of = flyd.stream; | ||
// fantasy-land compatibility | ||
s.ap = boundAp; | ||
s['fantasy-land/map'] = s.map = boundMap; | ||
s['fantasy-land/ap'] = fantasy_land_ap; | ||
s['fantasy-land/of'] = s.of = flyd.stream; | ||
s['fantasy-land/chain'] = s.chain = boundChain; | ||
s.pipe = operator_pipe; | ||
// According to the fantasy-land Applicative specification | ||
// Given a value f, one can access its type representative via the constructor property: | ||
// `f.constructor.of` | ||
s.constructor = flyd.stream; | ||
s.toJSON = function() { | ||
return s.val; | ||
}; | ||
s.toString = streamToString; | ||
@@ -476,5 +813,7 @@ return s; | ||
if ((s.depsMet !== true && initialDepsNotMet(s)) || | ||
(s.end !== undefined && s.end.val === true)) return; | ||
(s.end !== undefined && s.end.val === true)) return; | ||
if (inStream !== undefined) { | ||
toUpdate.push(s); | ||
toUpdate.push(function() { | ||
updateStream(s); | ||
}); | ||
return; | ||
@@ -500,3 +839,3 @@ } | ||
function updateDeps(s) { | ||
var i, o, list | ||
var i, o, list;;; | ||
var listeners = s.listeners; | ||
@@ -527,3 +866,3 @@ for (i = 0; i < listeners.length; ++i) { | ||
function findDeps(s) { | ||
var i | ||
var i; | ||
var listeners = s.listeners; | ||
@@ -545,5 +884,4 @@ if (s.queued === false) { | ||
while (toUpdate.length > 0) { | ||
var s = toUpdate.shift(); | ||
if (s.vals.length > 0) s.val = s.vals.shift(); | ||
updateDeps(s); | ||
var updater = toUpdate.shift(); | ||
updater(); | ||
} | ||
@@ -560,6 +898,2 @@ flushing = false; | ||
function updateStreamValue(s, n) { | ||
if (n !== undefined && n !== null && isFunction(n.then)) { | ||
n.then(s); | ||
return; | ||
} | ||
s.val = n; | ||
@@ -574,4 +908,5 @@ s.hasVal = true; | ||
} else { | ||
s.vals.push(n); | ||
toUpdate.push(s); | ||
toUpdate.push(function() { | ||
updateStreamValue(s, n); | ||
}); | ||
} | ||
@@ -645,2 +980,5 @@ } | ||
* @private | ||
*/ | ||
/** | ||
* @private | ||
* transducer stream transformer | ||
@@ -653,181 +991,6 @@ */ | ||
module.exports = flyd; | ||
var lib = flyd; | ||
},{"ramda/src/curryN":2}],2:[function(require,module,exports){ | ||
var _arity = require('./internal/_arity'); | ||
var _curry1 = require('./internal/_curry1'); | ||
var _curry2 = require('./internal/_curry2'); | ||
var _curryN = require('./internal/_curryN'); | ||
return lib; | ||
/** | ||
* Returns a curried equivalent of the provided function, with the specified | ||
* arity. The curried function has two unusual capabilities. First, its | ||
* arguments needn't be provided one at a time. If `g` is `R.curryN(3, f)`, the | ||
* following are equivalent: | ||
* | ||
* - `g(1)(2)(3)` | ||
* - `g(1)(2, 3)` | ||
* - `g(1, 2)(3)` | ||
* - `g(1, 2, 3)` | ||
* | ||
* Secondly, the special placeholder value `R.__` may be used to specify | ||
* "gaps", allowing partial application of any combination of arguments, | ||
* regardless of their positions. If `g` is as above and `_` is `R.__`, the | ||
* following are equivalent: | ||
* | ||
* - `g(1, 2, 3)` | ||
* - `g(_, 2, 3)(1)` | ||
* - `g(_, _, 3)(1)(2)` | ||
* - `g(_, _, 3)(1, 2)` | ||
* - `g(_, 2)(1)(3)` | ||
* - `g(_, 2)(1, 3)` | ||
* - `g(_, 2)(_, 3)(1)` | ||
* | ||
* @func | ||
* @memberOf R | ||
* @since v0.5.0 | ||
* @category Function | ||
* @sig Number -> (* -> a) -> (* -> a) | ||
* @param {Number} length The arity for the returned function. | ||
* @param {Function} fn The function to curry. | ||
* @return {Function} A new, curried function. | ||
* @see R.curry | ||
* @example | ||
* | ||
* var sumArgs = (...args) => R.sum(args); | ||
* | ||
* var curriedAddFourNumbers = R.curryN(4, sumArgs); | ||
* var f = curriedAddFourNumbers(1, 2); | ||
* var g = f(3); | ||
* g(4); //=> 10 | ||
*/ | ||
module.exports = _curry2(function curryN(length, fn) { | ||
if (length === 1) { | ||
return _curry1(fn); | ||
} | ||
return _arity(length, _curryN(length, [], fn)); | ||
}); | ||
},{"./internal/_arity":3,"./internal/_curry1":4,"./internal/_curry2":5,"./internal/_curryN":6}],3:[function(require,module,exports){ | ||
module.exports = function _arity(n, fn) { | ||
/* eslint-disable no-unused-vars */ | ||
switch (n) { | ||
case 0: return function() { return fn.apply(this, arguments); }; | ||
case 1: return function(a0) { return fn.apply(this, arguments); }; | ||
case 2: return function(a0, a1) { return fn.apply(this, arguments); }; | ||
case 3: return function(a0, a1, a2) { return fn.apply(this, arguments); }; | ||
case 4: return function(a0, a1, a2, a3) { return fn.apply(this, arguments); }; | ||
case 5: return function(a0, a1, a2, a3, a4) { return fn.apply(this, arguments); }; | ||
case 6: return function(a0, a1, a2, a3, a4, a5) { return fn.apply(this, arguments); }; | ||
case 7: return function(a0, a1, a2, a3, a4, a5, a6) { return fn.apply(this, arguments); }; | ||
case 8: return function(a0, a1, a2, a3, a4, a5, a6, a7) { return fn.apply(this, arguments); }; | ||
case 9: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8) { return fn.apply(this, arguments); }; | ||
case 10: return function(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) { return fn.apply(this, arguments); }; | ||
default: throw new Error('First argument to _arity must be a non-negative integer no greater than ten'); | ||
} | ||
}; | ||
},{}],4:[function(require,module,exports){ | ||
var _isPlaceholder = require('./_isPlaceholder'); | ||
/** | ||
* Optimized internal one-arity curry function. | ||
* | ||
* @private | ||
* @category Function | ||
* @param {Function} fn The function to curry. | ||
* @return {Function} The curried function. | ||
*/ | ||
module.exports = function _curry1(fn) { | ||
return function f1(a) { | ||
if (arguments.length === 0 || _isPlaceholder(a)) { | ||
return f1; | ||
} else { | ||
return fn.apply(this, arguments); | ||
} | ||
}; | ||
}; | ||
},{"./_isPlaceholder":7}],5:[function(require,module,exports){ | ||
var _curry1 = require('./_curry1'); | ||
var _isPlaceholder = require('./_isPlaceholder'); | ||
/** | ||
* Optimized internal two-arity curry function. | ||
* | ||
* @private | ||
* @category Function | ||
* @param {Function} fn The function to curry. | ||
* @return {Function} The curried function. | ||
*/ | ||
module.exports = function _curry2(fn) { | ||
return function f2(a, b) { | ||
switch (arguments.length) { | ||
case 0: | ||
return f2; | ||
case 1: | ||
return _isPlaceholder(a) ? f2 | ||
: _curry1(function(_b) { return fn(a, _b); }); | ||
default: | ||
return _isPlaceholder(a) && _isPlaceholder(b) ? f2 | ||
: _isPlaceholder(a) ? _curry1(function(_a) { return fn(_a, b); }) | ||
: _isPlaceholder(b) ? _curry1(function(_b) { return fn(a, _b); }) | ||
: fn(a, b); | ||
} | ||
}; | ||
}; | ||
},{"./_curry1":4,"./_isPlaceholder":7}],6:[function(require,module,exports){ | ||
var _arity = require('./_arity'); | ||
var _isPlaceholder = require('./_isPlaceholder'); | ||
/** | ||
* Internal curryN function. | ||
* | ||
* @private | ||
* @category Function | ||
* @param {Number} length The arity of the curried function. | ||
* @param {Array} received An array of arguments received thus far. | ||
* @param {Function} fn The function to curry. | ||
* @return {Function} The curried function. | ||
*/ | ||
module.exports = function _curryN(length, received, fn) { | ||
return function() { | ||
var combined = []; | ||
var argsIdx = 0; | ||
var left = length; | ||
var combinedIdx = 0; | ||
while (combinedIdx < received.length || argsIdx < arguments.length) { | ||
var result; | ||
if (combinedIdx < received.length && | ||
(!_isPlaceholder(received[combinedIdx]) || | ||
argsIdx >= arguments.length)) { | ||
result = received[combinedIdx]; | ||
} else { | ||
result = arguments[argsIdx]; | ||
argsIdx += 1; | ||
} | ||
combined[combinedIdx] = result; | ||
if (!_isPlaceholder(result)) { | ||
left -= 1; | ||
} | ||
combinedIdx += 1; | ||
} | ||
return left <= 0 ? fn.apply(this, combined) | ||
: _arity(left, _curryN(length, combined, fn)); | ||
}; | ||
}; | ||
},{"./_arity":3,"./_isPlaceholder":7}],7:[function(require,module,exports){ | ||
module.exports = function _isPlaceholder(a) { | ||
return a != null && | ||
typeof a === 'object' && | ||
a['@@functional/placeholder'] === true; | ||
}; | ||
},{}]},{},[1])(1) | ||
}); | ||
}))); |
@@ -1,1 +0,1 @@ | ||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.flyd=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";var curryN=require("ramda/src/curryN");function isFunction(obj){return!!(obj&&obj.constructor&&obj.call&&obj.apply)}function trueFn(){return true}var toUpdate=[];var inStream;var order=[];var orderNextIdx=-1;var flushing=false;var flyd={};flyd.stream=function(initialValue){var endStream=createDependentStream([],trueFn);var s=createStream();s.end=endStream;s.fnArgs=[];endStream.listeners.push(s);s.toJSON=function(){return s()};if(arguments.length>0)s(initialValue);return s};flyd.combine=curryN(2,combine);function combine(fn,streams){var i,s,deps,depEndStreams;var endStream=createDependentStream([],trueFn);deps=[];depEndStreams=[];for(i=0;i<streams.length;++i){if(streams[i]!==undefined){deps.push(streams[i]);if(streams[i].end!==undefined)depEndStreams.push(streams[i].end)}}s=createDependentStream(deps,fn);s.depsChanged=[];s.fnArgs=s.deps.concat([s,s.depsChanged]);s.end=endStream;endStream.listeners.push(s);addListeners(depEndStreams,endStream);endStream.deps=depEndStreams;updateStream(s);return s}flyd.isStream=function(stream){return isFunction(stream)&&"hasVal"in stream};flyd.immediate=function(s){if(s.depsMet===false){s.depsMet=true;updateStream(s)}return s};flyd.endsOn=function(endS,s){detachDeps(s.end);endS.listeners.push(s.end);s.end.deps.push(endS);return s};flyd.map=curryN(2,function(f,s){return combine(function(s,self){self(f(s.val))},[s])});flyd.on=curryN(2,function(f,s){return combine(function(s){f(s.val)},[s])});flyd.scan=curryN(3,function(f,acc,s){var ns=combine(function(s,self){self(acc=f(acc,s.val))},[s]);if(!ns.hasVal)ns(acc);return ns});flyd.merge=curryN(2,function(s1,s2){var s=flyd.immediate(combine(function(s1,s2,self,changed){if(changed[0]){self(changed[0]())}else if(s1.hasVal){self(s1.val)}else if(s2.hasVal){self(s2.val)}},[s1,s2]));flyd.endsOn(combine(function(){return true},[s1.end,s2.end]),s);return s});flyd.transduce=curryN(2,function(xform,source){xform=xform(new StreamTransformer);return combine(function(source,self){var res=xform["@@transducer/step"](undefined,source.val);if(res&&res["@@transducer/reduced"]===true){self.end(true);return res["@@transducer/value"]}else{return res}},[source])});flyd.curryN=curryN;function boundMap(f){return flyd.map(f,this)}function ap(s2){var s1=this;return combine(function(s1,s2,self){self(s1.val(s2.val))},[s1,s2])}function streamToString(){return"stream("+this.val+")"}function createStream(){function s(n){if(arguments.length===0)return s.val;updateStreamValue(s,n);return s}s.hasVal=false;s.val=undefined;s.vals=[];s.listeners=[];s.queued=false;s.end=undefined;s.map=boundMap;s.ap=ap;s.of=flyd.stream;s.toString=streamToString;return s}function createDependentStream(deps,fn){var s=createStream();s.fn=fn;s.deps=deps;s.depsMet=false;s.depsChanged=deps.length>0?[]:undefined;s.shouldUpdate=false;addListeners(deps,s);return s}function initialDepsNotMet(stream){stream.depsMet=stream.deps.every(function(s){return s.hasVal});return!stream.depsMet}function updateStream(s){if(s.depsMet!==true&&initialDepsNotMet(s)||s.end!==undefined&&s.end.val===true)return;if(inStream!==undefined){toUpdate.push(s);return}inStream=s;if(s.depsChanged)s.fnArgs[s.fnArgs.length-1]=s.depsChanged;var returnVal=s.fn.apply(s.fn,s.fnArgs);if(returnVal!==undefined){s(returnVal)}inStream=undefined;if(s.depsChanged!==undefined)s.depsChanged=[];s.shouldUpdate=false;if(flushing===false)flushUpdate()}function updateDeps(s){var i,o,list;var listeners=s.listeners;for(i=0;i<listeners.length;++i){list=listeners[i];if(list.end===s){endStream(list)}else{if(list.depsChanged!==undefined)list.depsChanged.push(s);list.shouldUpdate=true;findDeps(list)}}for(;orderNextIdx>=0;--orderNextIdx){o=order[orderNextIdx];if(o.shouldUpdate===true)updateStream(o);o.queued=false}}function findDeps(s){var i;var listeners=s.listeners;if(s.queued===false){s.queued=true;for(i=0;i<listeners.length;++i){findDeps(listeners[i])}order[++orderNextIdx]=s}}function flushUpdate(){flushing=true;while(toUpdate.length>0){var s=toUpdate.shift();if(s.vals.length>0)s.val=s.vals.shift();updateDeps(s)}flushing=false}function updateStreamValue(s,n){if(n!==undefined&&n!==null&&isFunction(n.then)){n.then(s);return}s.val=n;s.hasVal=true;if(inStream===undefined){flushing=true;updateDeps(s);if(toUpdate.length>0)flushUpdate();else flushing=false}else if(inStream===s){markListeners(s,s.listeners)}else{s.vals.push(n);toUpdate.push(s)}}function markListeners(s,lists){var i,list;for(i=0;i<lists.length;++i){list=lists[i];if(list.end!==s){if(list.depsChanged!==undefined){list.depsChanged.push(s)}list.shouldUpdate=true}else{endStream(list)}}}function addListeners(deps,s){for(var i=0;i<deps.length;++i){deps[i].listeners.push(s)}}function removeListener(s,listeners){var idx=listeners.indexOf(s);listeners[idx]=listeners[listeners.length-1];listeners.length--}function detachDeps(s){for(var i=0;i<s.deps.length;++i){removeListener(s,s.deps[i].listeners)}s.deps.length=0}function endStream(s){if(s.deps!==undefined)detachDeps(s);if(s.end!==undefined)detachDeps(s.end)}function StreamTransformer(){}StreamTransformer.prototype["@@transducer/init"]=function(){};StreamTransformer.prototype["@@transducer/result"]=function(){};StreamTransformer.prototype["@@transducer/step"]=function(s,v){return v};module.exports=flyd},{"ramda/src/curryN":2}],2:[function(require,module,exports){var _arity=require("./internal/_arity");var _curry1=require("./internal/_curry1");var _curry2=require("./internal/_curry2");var _curryN=require("./internal/_curryN");module.exports=_curry2(function curryN(length,fn){if(length===1){return _curry1(fn)}return _arity(length,_curryN(length,[],fn))})},{"./internal/_arity":3,"./internal/_curry1":4,"./internal/_curry2":5,"./internal/_curryN":6}],3:[function(require,module,exports){module.exports=function _arity(n,fn){switch(n){case 0:return function(){return fn.apply(this,arguments)};case 1:return function(a0){return fn.apply(this,arguments)};case 2:return function(a0,a1){return fn.apply(this,arguments)};case 3:return function(a0,a1,a2){return fn.apply(this,arguments)};case 4:return function(a0,a1,a2,a3){return fn.apply(this,arguments)};case 5:return function(a0,a1,a2,a3,a4){return fn.apply(this,arguments)};case 6:return function(a0,a1,a2,a3,a4,a5){return fn.apply(this,arguments)};case 7:return function(a0,a1,a2,a3,a4,a5,a6){return fn.apply(this,arguments)};case 8:return function(a0,a1,a2,a3,a4,a5,a6,a7){return fn.apply(this,arguments)};case 9:return function(a0,a1,a2,a3,a4,a5,a6,a7,a8){return fn.apply(this,arguments)};case 10:return function(a0,a1,a2,a3,a4,a5,a6,a7,a8,a9){return fn.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}}},{}],4:[function(require,module,exports){var _isPlaceholder=require("./_isPlaceholder");module.exports=function _curry1(fn){return function f1(a){if(arguments.length===0||_isPlaceholder(a)){return f1}else{return fn.apply(this,arguments)}}}},{"./_isPlaceholder":7}],5:[function(require,module,exports){var _curry1=require("./_curry1");var _isPlaceholder=require("./_isPlaceholder");module.exports=function _curry2(fn){return function f2(a,b){switch(arguments.length){case 0:return f2;case 1:return _isPlaceholder(a)?f2:_curry1(function(_b){return fn(a,_b)});default:return _isPlaceholder(a)&&_isPlaceholder(b)?f2:_isPlaceholder(a)?_curry1(function(_a){return fn(_a,b)}):_isPlaceholder(b)?_curry1(function(_b){return fn(a,_b)}):fn(a,b)}}}},{"./_curry1":4,"./_isPlaceholder":7}],6:[function(require,module,exports){var _arity=require("./_arity");var _isPlaceholder=require("./_isPlaceholder");module.exports=function _curryN(length,received,fn){return function(){var combined=[];var argsIdx=0;var left=length;var combinedIdx=0;while(combinedIdx<received.length||argsIdx<arguments.length){var result;if(combinedIdx<received.length&&(!_isPlaceholder(received[combinedIdx])||argsIdx>=arguments.length)){result=received[combinedIdx]}else{result=arguments[argsIdx];argsIdx+=1}combined[combinedIdx]=result;if(!_isPlaceholder(result)){left-=1}combinedIdx+=1}return left<=0?fn.apply(this,combined):_arity(left,_curryN(length,combined,fn))}}},{"./_arity":3,"./_isPlaceholder":7}],7:[function(require,module,exports){module.exports=function _isPlaceholder(a){return a!=null&&typeof a==="object"&&a["@@functional/placeholder"]===true}},{}]},{},[1])(1)}); | ||
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):n.flyd=e()}(this,function(){"use strict";var n=function(n,e){switch(n){case 0:return function(){return e.apply(this,arguments)};case 1:return function(n){return e.apply(this,arguments)};case 2:return function(n,t){return e.apply(this,arguments)};case 3:return function(n,t,r){return e.apply(this,arguments)};case 4:return function(n,t,r,u){return e.apply(this,arguments)};case 5:return function(n,t,r,u,a){return e.apply(this,arguments)};case 6:return function(n,t,r,u,a,i){return e.apply(this,arguments)};case 7:return function(n,t,r,u,a,i,o){return e.apply(this,arguments)};case 8:return function(n,t,r,u,a,i,o,s){return e.apply(this,arguments)};case 9:return function(n,t,r,u,a,i,o,s,f){return e.apply(this,arguments)};case 10:return function(n,t,r,u,a,i,o,s,f,d){return e.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}};var e=function(n){return null!=n&&"object"==typeof n&&!0===n["@@functional/placeholder"]};var t=function(n){return function t(r){return 0===arguments.length||e(r)?t:n.apply(this,arguments)}};var r=function t(r,u,a){return function(){for(var i=[],o=0,s=r,f=0;f<u.length||o<arguments.length;){var d;f<u.length&&(!e(u[f])||o>=arguments.length)?d=u[f]:(d=arguments[o],o+=1),i[f]=d,e(d)||(s-=1),f+=1}return s<=0?a.apply(this,i):n(s,t(r,i,a))}},u=function(n){return function r(u,a){switch(arguments.length){case 0:return r;case 1:return e(u)?r:t(function(e){return n(u,e)});default:return e(u)&&e(a)?r:e(u)?t(function(e){return n(e,a)}):e(a)?t(function(e){return n(u,e)}):n(u,a)}}}(function(e,u){return 1===e?t(u):n(e,r(e,[],u))});function a(){return!0}var i,o=[],s=[],f=-1,d=!1,c={};function p(n,e){var t,r,u,i,o=b([],a);for(u=[],i=[],t=0;t<e.length;++t)void 0!==e[t]&&(u.push(e[t]),void 0!==e[t].end&&i.push(e[t].end));return(r=b(u,n)).depsChanged=[],r.fnArgs=r.deps.concat([r,r.depsChanged]),r.end=o,o.listeners.push(r),U(i,o),o.deps=i,w(r),r}function l(n){return c.map(n,this)}function h(n){return n(this)}function v(n){return g(n,this)}function g(n,e){var t=c.stream(1),r=c.on(function(){var n=t()-1;t(n),n<=0&&t.end(!0)});r(e.end);var u=c.stream(),a=c.combine(function(e,a){u.end(!0);var i=n(e());t(t()+1),r(i.end),u=c.map(a,i)},[e]);return c.endsOn(t.end,a),a}function m(n,e){return p(function(n,e,t){t(n.val(e.val))},[e,n])}function y(n){return m(n,this)}function C(n){return m(this,n)}function V(){return"stream("+this.val+")"}function M(){function n(e){return 0===arguments.length?n.val:(function n(e,t){e.val=t;e.hasVal=!0;void 0===i?(d=!0,function(n){var e,t,r,u=n.listeners;for(e=0;e<u.length;++e)(r=u[e]).end===n?S(r):(void 0!==r.depsChanged&&r.depsChanged.push(n),r.shouldUpdate=!0,A(r));for(;f>=0;--f)!0===(t=s[f]).shouldUpdate&&w(t),t.queued=!1}(e),o.length>0?O():d=!1):i===e?function(n,e){var t,r;for(t=0;t<e.length;++t)(r=e[t]).end!==n?(void 0!==r.depsChanged&&r.depsChanged.push(n),r.shouldUpdate=!0):S(r)}(e,e.listeners):o.push(function(){n(e,t)})}(n,e),n)}return n.hasVal=!1,n.val=void 0,n.vals=[],n.listeners=[],n.queued=!1,n.end=void 0,n.ap=y,n["fantasy-land/map"]=n.map=l,n["fantasy-land/ap"]=C,n["fantasy-land/of"]=n.of=c.stream,n["fantasy-land/chain"]=n.chain=v,n.pipe=h,n.constructor=c.stream,n.toJSON=function(){return n.val},n.toString=V,n}function b(n,e){var t=M();return t.fn=e,t.deps=n,t.depsMet=!1,t.depsChanged=n.length>0?[]:void 0,t.shouldUpdate=!1,U(n,t),t}function w(n){var e;if(!(!0!==n.depsMet&&(e=n,e.depsMet=e.deps.every(function(n){return n.hasVal}),!e.depsMet)||void 0!==n.end&&!0===n.end.val))if(void 0===i){i=n,n.depsChanged&&(n.fnArgs[n.fnArgs.length-1]=n.depsChanged);var t=n.fn.apply(n.fn,n.fnArgs);void 0!==t&&n(t),i=void 0,void 0!==n.depsChanged&&(n.depsChanged=[]),n.shouldUpdate=!1,!1===d&&O()}else o.push(function(){w(n)})}function A(n){var e,t=n.listeners;if(!1===n.queued){for(n.queued=!0,e=0;e<t.length;++e)A(t[e]);s[++f]=n}}function O(){for(d=!0;o.length>0;){o.shift()()}d=!1}function U(n,e){for(var t=0;t<n.length;++t)n[t].listeners.push(e)}function q(n,e){e[e.indexOf(n)]=e[e.length-1],e.length--}function x(n){for(var e=0;e<n.deps.length;++e)q(n,n.deps[e].listeners);n.deps.length=0}function S(n){void 0!==n.deps&&x(n),void 0!==n.end&&x(n.end)}function j(){}return c.stream=function(n){var e=b([],a),t=M();return t.end=e,t.fnArgs=[],e.listeners.push(t),arguments.length>0&&t(n),t},c.stream["fantasy-land/of"]=c.stream.of=c.stream,c.combine=u(2,p),c.isStream=function(n){return!!((e=n)&&e.constructor&&e.call&&e.apply)&&"hasVal"in n;var e},c.immediate=function(n){return!1===n.depsMet&&(n.depsMet=!0,w(n)),n},c.endsOn=function(n,e){return x(e.end),n.listeners.push(e.end),e.end.deps.push(n),e},c.map=u(2,function(n,e){return p(function(e,t){t(n(e.val))},[e])}),c.chain=u(2,g),c.ap=u(2,m),c.on=u(2,function(n,e){return p(function(e){n(e.val)},[e])}),c.scan=u(3,function(n,e,t){var r=p(function(t,r){r(e=n(e,t.val))},[t]);return r.hasVal||r(e),r}),c.merge=u(2,function(n,e){var t=c.immediate(p(function(n,e,t,r){r[0]?t(r[0]()):n.hasVal?t(n.val):e.hasVal&&t(e.val)},[n,e]));return c.endsOn(p(function(){return!0},[n.end,e.end]),t),t}),c.transduce=u(2,function(n,e){return n=n(new j),p(function(e,t){var r=n["@@transducer/step"](void 0,e.val);return r&&!0===r["@@transducer/reduced"]?(t.end(!0),r["@@transducer/value"]):r},[e])}),c.curryN=u,c.fromPromise=function(n){var e=c.stream();return n.then(function(n){e(n),e.end(!0)}),e},c.flattenPromise=function(n){return p(function(n,e){n().then(e)},[n])},j.prototype["@@transducer/init"]=function(){},j.prototype["@@transducer/result"]=function(){},j.prototype["@@transducer/step"]=function(n,e){return e},c}); |
@@ -124,4 +124,6 @@ type CurriedFunction2<T1, T2, R> = ((t1: T1, t2: T2) => R) & ((t1: T1, ...rest: Array<void>) => (t2: T2) => R); | ||
interface Filter { | ||
<T, V extends T>(project: (val: T) => val is V, stream: flyd.Stream<T>): flyd.Stream<T>; | ||
<T, V extends T>(project: (val: T) => val is V): (stream: flyd.Stream<T>) => flyd.Stream<T>; | ||
<T, V extends T>(project: (val: T) => val is V, stream: flyd.Stream<T>): flyd.Stream<V>; | ||
<T, V extends T>(project: (val: T) => val is V): (stream: flyd.Stream<T>) => flyd.Stream<V>; | ||
<T>(predicate: (val: T) => boolean, stream: flyd.Stream<T>): flyd.Stream<T>; | ||
<T>(predicate: (val: T) => boolean): (stream: flyd.Stream<T>) => flyd.Stream<T>; | ||
} | ||
@@ -132,12 +134,2 @@ const _Filter: Filter; | ||
declare module 'flyd/module/flatmap' { | ||
type projection<T, V> = (val: T) => flyd.Stream<V>; | ||
interface flatMap { | ||
<T, V>(project: projection<T, V>, source: flyd.Stream<T>): flyd.Stream<V>; | ||
<T, V>(project: projection<T, V>): (source: flyd.Stream<T>) => flyd.Stream<V>; | ||
} | ||
const _flatMap: flatMap; | ||
export = _flatMap; | ||
} | ||
declare module 'flyd/module/forwardto' { | ||
@@ -195,3 +187,4 @@ interface ForwardTo { | ||
interface ObjModule { | ||
streamProps<T>(obj: T): {[P in keyof T]: flyd.Stream<T[P]> }; | ||
streamProps<T>(obj: T): { [P in keyof T]: flyd.Stream<T[P]> }; | ||
stream<T extends { [key: string]: flyd.Stream<any> }>(obj: T): flyd.Stream<{ [P in keyof T]: T[P]['val'] }>; | ||
extractProps(obj: any): any; | ||
@@ -205,4 +198,4 @@ } | ||
declare module 'flyd/module/previous' { | ||
type previous<T> = (stream: flyd.Stream<T>) => flyd.Stream<T>; | ||
const _previous: previous;; | ||
type previous = <T>(stream: flyd.Stream<T>) => flyd.Stream<T>; | ||
const _previous: previous; | ||
export = _previous; | ||
@@ -209,0 +202,0 @@ } |
@@ -441,3 +441,2 @@ 'use strict'; | ||
/* istanbul ignore next */ | ||
flyd.flattenPromise = function flattenPromise(s) { | ||
@@ -599,3 +598,10 @@ return combine(function(s, self) { | ||
if ((s.depsMet !== true && initialDepsNotMet(s)) || | ||
(s.end !== undefined && s.end.val === true)) return; | ||
(s.end !== undefined && s.end.val === true)) { | ||
if (toUpdate.length > 0 && inStream !== undefined) { | ||
toUpdate.push(function() { | ||
updateStream(s); | ||
}); | ||
} | ||
return; | ||
} | ||
if (inStream !== undefined) { | ||
@@ -681,8 +687,2 @@ toUpdate.push(function() { | ||
function updateStreamValue(s, n) { | ||
/* istanbul ignore if */ | ||
if (n !== undefined && n !== null && isFunction(n.then)) { | ||
console.warn('flyd: Promise swallowing has been deprecated, please see https://github.com/paldepind/flyd#promises for more info'); | ||
n.then(s); | ||
return; | ||
} | ||
s.val = n; | ||
@@ -689,0 +689,0 @@ s.hasVal = true; |
{ | ||
"name": "flyd", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "The less is more, modular, functional reactive programming library", | ||
@@ -23,4 +23,7 @@ "main": "lib/index.js", | ||
"np": "^2.19.0", | ||
"transducers.js": "0.3.x", | ||
"uglifyjs": "^2.4.10" | ||
"rollup": "^0.56.2", | ||
"rollup-plugin-commonjs": "^8.3.0", | ||
"rollup-plugin-node-resolve": "^3.0.3", | ||
"rollup-plugin-uglify": "^3.0.0", | ||
"transducers.js": "0.3.x" | ||
}, | ||
@@ -34,3 +37,3 @@ "scripts": { | ||
"post-to-coveralls-io": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage", | ||
"build": "browserify -s flyd lib/index.js > flyd.js && uglifyjs flyd.js -o flyd.min.js", | ||
"build": "rollup -c rollup.config.dev.js && rollup -c rollup.config.js", | ||
"release": "np" | ||
@@ -37,0 +40,0 @@ }, |
@@ -49,2 +49,3 @@ # Flyd | ||
[Ramda](http://ramdajs.com/) and [transducers.js](https://github.com/jlongster/transducers.js). | ||
* Conforms to the fantasy land [monad](https://github.com/fantasyland/fantasy-land#monad) specification | ||
* [Atomic updates](#atomic-updates). | ||
@@ -517,3 +518,3 @@ | ||
`(a -> b -> a) -> a -> Stream b -> Stream a` | ||
`((a, b) -> a) -> a -> Stream b -> Stream a` | ||
@@ -652,3 +653,3 @@ __Example__ | ||
### stream.map(f) __Deprecated__ | ||
### stream.map(f) | ||
@@ -672,3 +673,3 @@ Returns a new stream identical to the original except every | ||
### stream1.ap(stream2) __Deprecated__ | ||
### stream1.ap(stream2) | ||
@@ -740,2 +741,8 @@ `stream1` must be a stream of functions. | ||
| [**flyd-withLatestFrom**](https://github.com/bertofer/flyd-withLatestFrom) | When the source observable emits, the value also contains the latest value from withLatestFrom parameter stream. | | ||
| [**flyd-zip**](https://github.com/jayrbolton/flyd-zip) | Zip streams together into arrays of values | | ||
| [**flyd-undo**](https://github.com/jayrbolton/flyd-undo) | An undo/redo utility for saving and restoring state in flyd | | ||
| [**flyd-ajax**](https://github.com/jayrbolton/flyd-ajax) | An ajax utility that returns flyd streams | | ||
| [**flyd-xstate**](https://github.com/jayrbolton/flyd-xstate) | Integration of flyd with xstate Harel Statecharts | | ||
| [**flyd-windowresize**](https://github.com/jayrbolton/flyd-windowresize) | Get a stream for the window size | | ||
| [**flyd-stream-querystring**](https://github.com/jayrbolton/flyd-stream-querystring) | Manage the URL query params using flyd streams | | ||
| **Time related** | | ||
@@ -742,0 +749,0 @@ | [flyd/module/**every**](module/every) | Takes a number of milliseconds t and creates a stream of the current time updated every t. | |
@@ -279,3 +279,20 @@ var assert = require('assert'); | ||
}); | ||
}) | ||
it('can create multi-level dependent streams inside a stream body', function() { | ||
var result = 0; | ||
var externalStream = stream(0); | ||
stream(1).map(function() { | ||
externalStream | ||
.map(function() { | ||
result += 1; | ||
return 0; | ||
}) | ||
.map(function() { | ||
result += 2; | ||
return 0; | ||
}); | ||
return; | ||
}); | ||
assert.equal(result, 3); | ||
}); | ||
}); | ||
@@ -373,22 +390,82 @@ describe('ending a stream', function() { | ||
describe('promise swallowing', function() { | ||
it('pushes result of promise down the stream', function(done) { | ||
var s = flyd.fromPromise(Promise.resolve(12)); | ||
combine(function(s) { | ||
assert.equal(s(), 12); | ||
done(); | ||
}, [s]); | ||
describe('Promises', function() { | ||
describe('fromPromise', function() { | ||
it('pushes result of promise down the stream', function(done) { | ||
var s = flyd.fromPromise(Promise.resolve(12)); | ||
combine(function(s) { | ||
assert.equal(s(), 12); | ||
done(); | ||
}, [s]); | ||
}); | ||
it('recursively unpacks promise', function(done) { | ||
var s = flyd.fromPromise(new Promise(function(res) { | ||
setTimeout(function() { | ||
res(new Promise(function(res) { | ||
setTimeout(res.bind(null, 12)); | ||
})); | ||
}, 20); | ||
})); | ||
combine(function(s) { | ||
assert.equal(s(), 12); | ||
done(); | ||
}, [s]); | ||
}); | ||
it('does not process out of order promises', function(done) { | ||
var promises = []; | ||
var delay = function(ms, val) { | ||
var p = new Promise(function(res) { | ||
setTimeout(function() { | ||
res(val); | ||
}, ms) | ||
}); | ||
promises.push(p); | ||
return p; | ||
}; | ||
var s = stream(); | ||
var res = s.chain(function(val) { | ||
return flyd.fromPromise(delay(val, val)); | ||
}) | ||
.pipe(flyd.scan(function(acc, v) { | ||
return acc + v; | ||
}, 0)); | ||
s(100)(50)(70)(200); | ||
Promise.all(promises).then(function() { | ||
assert.equal(res(), 200); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('recursively unpacks promise', function(done) { | ||
var s = flyd.fromPromise(new Promise(function(res) { | ||
setTimeout(function() { | ||
res(new Promise(function(res) { | ||
setTimeout(res.bind(null, 12)); | ||
})); | ||
}, 20); | ||
})); | ||
combine(function(s) { | ||
assert.equal(s(), 12); | ||
done(); | ||
}, [s]); | ||
describe('flattenPromise', function() { | ||
it('processes out of order promises', function(done) { | ||
var promises = []; | ||
var delay = function(ms, val) { | ||
var p = new Promise(function(res) { | ||
setTimeout(function() { | ||
res(val); | ||
}, ms) | ||
}); | ||
promises.push(p); | ||
return p; | ||
}; | ||
var s = stream(); | ||
var res = s.map(function(val) { | ||
return delay(val, val); | ||
}) | ||
.pipe(flyd.flattenPromise) | ||
.pipe(flyd.scan(function(acc, v) { | ||
return acc + v; | ||
}, 0)); | ||
s(100)(50)(70)(200); | ||
Promise.all(promises).then(function() { | ||
assert.equal(res(), 420); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
@@ -395,0 +472,0 @@ }); |
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
249427
91
6000
1
822
8
14