forked from tomasruizr/flyd
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflyd.min.js
1 lines (1 loc) · 4.7 KB
/
flyd.min.js
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";function n(){return!0}var e,t=[],r=[],u=-1,s=!1,i=!1;var o={};function d(e,t){if(!t)return n=>d(e,n);var r,u,s,i,o=C([],n);for(s=[],i=[],r=0;r<t.length;++r)void 0!==t[r]&&(s.push(t[r]),void 0!==t[r].end&&i.push(t[r].end));return(u=C(s,e)).depsChanged=[],u.fnArgs=u.deps.concat([u,u.depsChanged]),u.end=o,o.listeners.push(u),O(i,o),o.deps=i,U(u),u}function a(n,e){return e?d(function(e,t){t(n(e.val))},[e]):e=>a(n,e)}function f(n){return a(n,this)}function c(n){return n(this)}function l(n){return p(n,this)}function p(n,e){if(!e)return e=>p(n,e);var t=o.stream(1),r=o.on(function(){var n=t()-1;t(n),n<=0&&t.end(!0)});r(e.end);var u=o.stream(),s=o.combine(function(e,s){u.end(!0);var i=n(e());t(t()+1),r(i.end),u=a(s,i)},[e]);return o.endsOn(t.end,s),s}function h(n,e){return e?d(function(n,e,t){t(n.val(e.val))},[e,n]):e=>h(n,e)}function v(n){return h(n,this)}function g(n){return h(this,n)}function m(){return"stream("+this.val+")"}function y(){function n(){return n._push.apply(this,arguments)}return n._push=function(s){return 0===arguments.length?n.val:(function n(s,o){o.val=s;o.hasVal=!0;void 0===e?(i=!0,function(n){var e,t,s,i=n.listeners;for(e=0;e<i.length;++e)(s=i[e]).end===n?x(s):(void 0!==s.depsChanged&&s.depsChanged.push(n),s.shouldUpdate=!0,V(s));for(;u>=0;--u)!0===(t=r[u]).shouldUpdate&&U(t),t.queued=!1}(o),t.length>0&&A(),i=!1):e===o?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):x(r)}(o,o.listeners):M(function(e){n(s,e)},o)}(s,n),n)},n.hasVal=!1,n.val=void 0,n.updaters=[],n.listeners=[],n.queued=!1,n.end=void 0,n.ap=v,n["fantasy-land/map"]=n.map=f,n["fantasy-land/ap"]=g,n["fantasy-land/of"]=n.of=o.stream,n["fantasy-land/chain"]=n.chain=l,n.pipe=c,n.constructor=o.stream,n.toJSON=function(){return n.val},n.toString=m,n}function C(n,e){var t=y();return t.fn=e,t.deps=n,t.depsMet=!1,t.depsChanged=n.length>0?[]:void 0,t.shouldUpdate=!1,O(n,t),t}function U(n){var t;if((!(t=n).end||!0!==t.end.val)&&function(n){return!0===n.depsMet||function(n){return n.depsMet=n.deps.every(function(n){return n.hasVal}),n.depsMet}(n)}(n))if(void 0===e){e=n,n.depsChanged&&(n.fnArgs[n.fnArgs.length-1]=n.depsChanged);var r=n.fn.apply(n.fn,n.fnArgs);void 0!==r&&n(r),e=void 0,void 0!==n.depsChanged&&(n.depsChanged=[]),n.shouldUpdate=!1,!1===(s||i)&&A(),function(n){return n.listeners.some(function(n){return n.shouldUpdate})}(n)&&(i?n.listeners.forEach(function(n){n.shouldUpdate&&M(U,n)}):n(n.val))}else M(U,n)}function V(n){var e,t=n.listeners;if(!1===n.queued){for(n.queued=!0,e=0;e<t.length;++e)V(t[e]);r[++u]=n}}function M(n,e){t.push(e),e.updaters.push(n),e.shouldUpdate=!0}function A(){for(s=!0;t.length>0;){var n=t.shift(),e=n.updaters.shift();e&&n.shouldUpdate&&e(n)}s=!1}function O(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 b(n){for(var e=0;e<n.deps.length;++e)q(n,n.deps[e].listeners);n.deps.length=0}function x(n){void 0!==n.deps&&b(n),void 0!==n.end&&b(n.end)}function S(){}return o.stream=function(e){var t=C([],n),r=y();return r.end=t,r.fnArgs=[],t.listeners.push(r),arguments.length>0&&r(e),r},o.stream["fantasy-land/of"]=o.stream.of=o.stream,o.combine=d,o.isStream=function(n){return!!((e=n)&&e.constructor&&e.call&&e.apply)&&"hasVal"in n;var e},o.immediate=function(n){return!1===n.depsMet&&(n.depsMet=!0,U(n)),n},o.endsOn=function(n,e){return b(e.end),n.listeners.push(e.end),e.end.deps.push(n),e},o.map=a,o.chain=p,o.ap=h,o.on=function(n,e){return e?d(function(e){n(e.val)},[e]):e=>o.on(n,e)},o.scan=function(n,e,t){if([null,void 0].includes(e))return function(e,t){return o.scan(n,e,t)};if(!t)return function(t){return o.scan(n,e,t)};var r=d(function(t,r){r(e=n(e,t.val))},[t]);return r.hasVal||r(e),r},o.merge=function(n,e){if(!e)return e=>o.merge(n,e);var t=o.immediate(d(function(n,e,t,r){r[0]?t(r[0]()):n.hasVal?t(n.val):e.hasVal&&t(e.val)},[n,e]));return o.endsOn(d(function(){return!0},[n.end,e.end]),t),t},o.transduce=function(n,e){return e?(n=n(new S),d(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])):e=>o.transduce(n,e)},o.curryN=((n,e)=>(function n(...t){return arguments.length>=e.length?e(...t):(...e)=>n(...t,...e)})),o.fromPromise=function(n){var e=o.stream();return n.then(function(n){e(n),e.end(!0)}),e},o.flattenPromise=function(n){return d(function(n,e){n().then(e)},[n])},S.prototype["@@transducer/init"]=function(){},S.prototype["@@transducer/result"]=function(){},S.prototype["@@transducer/step"]=function(n,e){return e},o});