@cycle/run
Advanced tools
Comparing version 4.3.0 to 4.4.0
@@ -0,1 +1,11 @@ | ||
<a name="4.4.0"></a> | ||
# 4.4.0 (2018-06-28) | ||
### Bug Fixes | ||
* **run:** add two kinds of dispose() for setupReusable() ([ca20dc9](https://github.com/cyclejs/cyclejs/commit/ca20dc9)) | ||
<a name="4.3.0"></a> | ||
@@ -2,0 +12,0 @@ # 4.3.0 (2018-06-27) |
@@ -257,6 +257,4 @@ (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.Cycle = 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){ | ||
} | ||
var sinkProxies = internals_1.makeSinkProxies(drivers); | ||
var sources = internals_1.callDrivers(drivers, sinkProxies); | ||
var adaptedSources = internals_1.adaptSources(sources); | ||
var sinks = main(adaptedSources); | ||
var engine = setupReusable(drivers); | ||
var sinks = main(engine.sources); | ||
if (typeof window !== 'undefined') { | ||
@@ -267,9 +265,9 @@ window.Cyclejs = window.Cyclejs || {}; | ||
function _run() { | ||
var disposeReplication = internals_1.replicateMany(sinks, sinkProxies); | ||
var disposeRun = engine.run(sinks); | ||
return function dispose() { | ||
internals_1.disposeSources(sources); | ||
disposeReplication(); | ||
disposeRun(); | ||
engine.dispose(); | ||
}; | ||
} | ||
return { sinks: sinks, sources: sources, run: _run }; | ||
return { sinks: sinks, sources: engine.sources, run: _run }; | ||
} | ||
@@ -290,8 +288,10 @@ exports.setup = setup; | ||
* import {setupReusable} from '@cycle/run'; | ||
* const {sources, run} = setupReusable(drivers); | ||
* const {sources, run, dispose} = setupReusable(drivers); | ||
* // ... | ||
* const sinks = main(sources); | ||
* const dispose = run(sinks); | ||
* const disposeRun = run(sinks); | ||
* // ... | ||
* dispose(); | ||
* disposeRun(); | ||
* // ... | ||
* dispose(); // ends the reusability of drivers | ||
* ``` | ||
@@ -301,6 +301,9 @@ * | ||
* are driver functions. | ||
* @return {Object} an object with two properties: `sources` and | ||
* `run`. `sources` is the collection of driver sources, `run` | ||
* is the function that once called with 'sinks' as argument, will execute the | ||
* application, tying together sources with sinks. | ||
* @return {Object} an object with three properties: `sources`, `run` and | ||
* `dispose`. `sources` is the collection of driver sources, `run` is the | ||
* function that once called with 'sinks' as argument, will execute the | ||
* application, tying together sources with sinks. `dispose` terminates the | ||
* reusable resources used by the drivers. Note also that `run` returns a | ||
* dispose function which terminates resources that are specific (not reusable) | ||
* to that run. | ||
* @function setupReusable | ||
@@ -321,9 +324,9 @@ */ | ||
function _run(sinks) { | ||
var disposeReplication = internals_1.replicateMany(sinks, sinkProxies); | ||
return function dispose() { | ||
internals_1.disposeSources(sources); | ||
disposeReplication(); | ||
}; | ||
return internals_1.replicateMany(sinks, sinkProxies); | ||
} | ||
return { sources: sources, run: _run }; | ||
function disposeEngine() { | ||
internals_1.disposeSources(sources); | ||
internals_1.disposeSinkProxies(sinkProxies); | ||
} | ||
return { sources: sources, run: _run, dispose: disposeEngine }; | ||
} | ||
@@ -450,6 +453,9 @@ exports.setupReusable = setupReusable; | ||
subscriptions.forEach(function (s) { return s.unsubscribe(); }); | ||
sinkNames.forEach(function (name) { return sinkProxies[name]._c(); }); | ||
}; | ||
} | ||
exports.replicateMany = replicateMany; | ||
function disposeSinkProxies(sinkProxies) { | ||
Object.keys(sinkProxies).forEach(function (name) { return sinkProxies[name]._c(); }); | ||
} | ||
exports.disposeSinkProxies = disposeSinkProxies; | ||
function disposeSources(sources) { | ||
@@ -456,0 +462,0 @@ for (var k in sources) { |
@@ -1,13 +0,13 @@ | ||
(function(u){"object"===typeof exports&&"undefined"!==typeof module?module.exports=u():"function"===typeof define&&define.amd?define([],u):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).Cycle=u()})(function(){return function b(l,e,h){function k(a,d){if(!e[a]){if(!l[a]){var g="function"==typeof require&&require;if(!d&&g)return g(a,!0);if(c)return c(a,!0);d=Error("Cannot find module '"+a+"'");throw d.code="MODULE_NOT_FOUND",d;}d=e[a]={exports:{}}; | ||
l[a][0].call(d.exports,function(d){var c=l[a][1][d];return k(c?c:d)},d,d.exports,b,l,e,h)}return e[a].exports}for(var c="function"==typeof require&&require,g=0;g<h.length;g++)k(h[g]);return k}({1:[function(b,l,e){function h(){throw Error("setTimeout has not been defined");}function k(){throw Error("clearTimeout has not been defined");}function c(a){if(n===setTimeout)return setTimeout(a,0);if((n===h||!n)&&setTimeout)return n=setTimeout,setTimeout(a,0);try{return n(a,0)}catch(x){try{return n.call(null, | ||
a,0)}catch(y){return n.call(this,a,0)}}}function g(a){if(p===clearTimeout)return clearTimeout(a);if((p===k||!p)&&clearTimeout)return p=clearTimeout,clearTimeout(a);try{return p(a)}catch(x){try{return p.call(null,a)}catch(y){return p.call(this,a)}}}function a(){r&&q&&(r=!1,q.length?m=q.concat(m):t=-1,m.length&&d())}function d(){if(!r){var d=c(a);r=!0;for(var f=m.length;f;){q=m;for(m=[];++t<f;)q&&q[t].run();t=-1;f=m.length}q=null;r=!1;g(d)}}function v(a,d){this.fun=a;this.array=d}function f(){}b=l.exports= | ||
{};try{var n="function"===typeof setTimeout?setTimeout:h}catch(w){n=h}try{var p="function"===typeof clearTimeout?clearTimeout:k}catch(w){p=k}var m=[],r=!1,q,t=-1;b.nextTick=function(a){var f=Array(arguments.length-1);if(1<arguments.length)for(var g=1;g<arguments.length;g++)f[g-1]=arguments[g];m.push(new v(a,f));1!==m.length||r||c(d)};v.prototype.run=function(){this.fun.apply(null,this.array)};b.title="browser";b.browser=!0;b.env={};b.argv=[];b.version="";b.versions={};b.on=f;b.addListener=f;b.once= | ||
f;b.off=f;b.removeListener=f;b.removeAllListeners=f;b.emit=f;b.binding=function(a){throw Error("process.binding is not supported");};b.cwd=function(){return"/"};b.chdir=function(a){throw Error("process.chdir is not supported");};b.umask=function(){return 0}},{}],2:[function(b,l,e){(function(b){function k(){var c="undefined"!==typeof window?window:"undefined"!==typeof b?b:this;c.Cyclejs=c.Cyclejs||{};c=c.Cyclejs;c.adaptStream=c.adaptStream||function(c){return c};return c}Object.defineProperty(e,"__esModule", | ||
{value:!0});e.setAdapt=function(c){k().adaptStream=c};e.adapt=function(c){return k().adaptStream(c)}}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{}],3:[function(b,l,e){function h(g,a){if("function"!==typeof g)throw Error("First argument given to Cycle must be the 'main' function.");if("object"!==typeof a||null===a)throw Error("Second argument given to Cycle must be an object with driver functions as properties.");if(c.isObjectEmpty(a))throw Error("Second argument given to Cycle must be an object with at least one driver function declared as a property."); | ||
var d=c.makeSinkProxies(a),b=c.callDrivers(a,d);a=c.adaptSources(b);var f=g(a);"undefined"!==typeof window&&(window.Cyclejs=window.Cyclejs||{},window.Cyclejs.sinks=f);return{sinks:f,sources:b,run:function(){var a=c.replicateMany(f,d);return function(){c.disposeSources(b);a()}}}}function k(c,a){c=h(c,a);"undefined"!==typeof window&&window.CyclejsDevTool_startGraphSerializer&&window.CyclejsDevTool_startGraphSerializer(c.sinks);return c.run()}Object.defineProperty(e,"__esModule",{value:!0});var c=b("./internals"); | ||
e.setup=h;e.setupReusable=function(b){if("object"!==typeof b||null===b)throw Error("Argument given to setupReusable must be an object with driver functions as properties.");if(c.isObjectEmpty(b))throw Error("Argument given to setupReusable must be an object with at least one driver function declared as a property.");var a=c.makeSinkProxies(b);b=c.callDrivers(b,a);var d=c.adaptSources(b);return{sources:d,run:function(b){var f=c.replicateMany(b,a);return function(){c.disposeSources(d);f()}}}};e.run= | ||
k;e.default=k},{"./internals":4}],4:[function(b,l,e){(function(h){Object.defineProperty(e,"__esModule",{value:!0});var k="undefined"!==typeof window?window.xstream:"undefined"!==typeof h?h.xstream:null;h=b("quicktask");var c=b("./adapt"),g=h.default();e.makeSinkProxies=function(a){var b={},c;for(c in a)a.hasOwnProperty(c)&&(b[c]=k.default.create());return b};e.callDrivers=function(a,c){var b={},d;for(d in a)a.hasOwnProperty(d)&&(b[d]=a[d](c[d],d),b[d]&&"object"===typeof b[d]&&(b[d]._isCycleSource= | ||
d));return b};e.adaptSources=function(a){for(var b in a)a.hasOwnProperty(b)&&a[b]&&"function"===typeof a[b].shamefullySendNext&&(a[b]=c.adapt(a[b]));return a};e.replicateMany=function(a,b){var c=Object.keys(a).filter(function(a){return!!b[a]}),d={},e={};c.forEach(function(a){d[a]={_n:[],_e:[]};e[a]={next:function(b){return d[a]._n.push(b)},error:function(b){return d[a]._e.push(b)},complete:function(){}}});var h=c.map(function(b){return k.default.fromObservable(a[b]).subscribe(e[b])});c.forEach(function(a){var c= | ||
b[a],h=function(a){g(function(){return c._n(a)})},f=function(a){g(function(){(console.error||console.log)(a);c._e(a)})};d[a]._n.forEach(h);d[a]._e.forEach(f);e[a].next=h;e[a].error=f;e[a]._n=h;e[a]._e=f});d=null;return function(){h.forEach(function(a){return a.unsubscribe()});c.forEach(function(a){return b[a]._c()})}};e.disposeSources=function(a){for(var b in a)a.hasOwnProperty(b)&&a[b]&&a[b].dispose&&a[b].dispose()};e.isObjectEmpty=function(a){return 0===Object.keys(a).length}}).call(this,"undefined"!== | ||
typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{"./adapt":2,quicktask:5}],5:[function(b,l,e){(function(b){Object.defineProperty(e,"__esModule",{value:!0});e.default=function(){if("undefined"!==typeof MutationObserver){var e=document.createTextNode(""),c=[],g=0;(new MutationObserver(function(){for(;c.length;)c.shift()()})).observe(e,{characterData:!0});return function(a){c.push(a);e.data=g=1-g}}return"undefined"!==typeof setImmediate?setImmediate:"undefined"!== | ||
typeof b?b.nextTick:setTimeout}}).call(this,b("_process"))},{_process:1}]},{},[3])(3)}); | ||
(function(v){"object"===typeof exports&&"undefined"!==typeof module?module.exports=v():"function"===typeof define&&define.amd?define([],v):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).Cycle=v()})(function(){return function b(l,c,e){function g(a,d){if(!c[a]){if(!l[a]){var t="function"==typeof require&&require;if(!d&&t)return t(a,!0);if(k)return k(a,!0);d=Error("Cannot find module '"+a+"'");throw d.code="MODULE_NOT_FOUND",d;}d=c[a]={exports:{}}; | ||
l[a][0].call(d.exports,function(d){var f=l[a][1][d];return g(f?f:d)},d,d.exports,b,l,c,e)}return c[a].exports}for(var k="function"==typeof require&&require,h=0;h<e.length;h++)g(e[h]);return g}({1:[function(b,l,c){function e(){throw Error("setTimeout has not been defined");}function g(){throw Error("clearTimeout has not been defined");}function k(a){if(n===setTimeout)return setTimeout(a,0);if((n===e||!n)&&setTimeout)return n=setTimeout,setTimeout(a,0);try{return n(a,0)}catch(x){try{return n.call(null, | ||
a,0)}catch(y){return n.call(this,a,0)}}}function h(a){if(p===clearTimeout)return clearTimeout(a);if((p===g||!p)&&clearTimeout)return p=clearTimeout,clearTimeout(a);try{return p(a)}catch(x){try{return p.call(null,a)}catch(y){return p.call(this,a)}}}function a(){r&&q&&(r=!1,q.length?m=q.concat(m):u=-1,m.length&&d())}function d(){if(!r){var d=k(a);r=!0;for(var f=m.length;f;){q=m;for(m=[];++u<f;)q&&q[u].run();u=-1;f=m.length}q=null;r=!1;h(d)}}function t(a,d){this.fun=a;this.array=d}function f(){}b=l.exports= | ||
{};try{var n="function"===typeof setTimeout?setTimeout:e}catch(w){n=e}try{var p="function"===typeof clearTimeout?clearTimeout:g}catch(w){p=g}var m=[],r=!1,q,u=-1;b.nextTick=function(a){var f=Array(arguments.length-1);if(1<arguments.length)for(var b=1;b<arguments.length;b++)f[b-1]=arguments[b];m.push(new t(a,f));1!==m.length||r||k(d)};t.prototype.run=function(){this.fun.apply(null,this.array)};b.title="browser";b.browser=!0;b.env={};b.argv=[];b.version="";b.versions={};b.on=f;b.addListener=f;b.once= | ||
f;b.off=f;b.removeListener=f;b.removeAllListeners=f;b.emit=f;b.binding=function(a){throw Error("process.binding is not supported");};b.cwd=function(){return"/"};b.chdir=function(a){throw Error("process.chdir is not supported");};b.umask=function(){return 0}},{}],2:[function(b,l,c){(function(b){function g(){var c="undefined"!==typeof window?window:"undefined"!==typeof b?b:this;c.Cyclejs=c.Cyclejs||{};c=c.Cyclejs;c.adaptStream=c.adaptStream||function(b){return b};return c}Object.defineProperty(c,"__esModule", | ||
{value:!0});c.setAdapt=function(b){g().adaptStream=b};c.adapt=function(b){return g().adaptStream(b)}}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self?self:"undefined"!==typeof window?window:{})},{}],3:[function(b,l,c){function e(a,d){if("function"!==typeof a)throw Error("First argument given to Cycle must be the 'main' function.");if("object"!==typeof d||null===d)throw Error("Second argument given to Cycle must be an object with driver functions as properties.");if(h.isObjectEmpty(d))throw Error("Second argument given to Cycle must be an object with at least one driver function declared as a property."); | ||
var b=g(d),f=a(b.sources);"undefined"!==typeof window&&(window.Cyclejs=window.Cyclejs||{},window.Cyclejs.sinks=f);return{sinks:f,sources:b.sources,run:function(){var a=b.run(f);return function(){a();b.dispose()}}}}function g(a){if("object"!==typeof a||null===a)throw Error("Argument given to setupReusable must be an object with driver functions as properties.");if(h.isObjectEmpty(a))throw Error("Argument given to setupReusable must be an object with at least one driver function declared as a property."); | ||
var d=h.makeSinkProxies(a);a=h.callDrivers(a,d);var b=h.adaptSources(a);return{sources:b,run:function(a){return h.replicateMany(a,d)},dispose:function(){h.disposeSources(b);h.disposeSinkProxies(d)}}}function k(a,b){a=e(a,b);"undefined"!==typeof window&&window.CyclejsDevTool_startGraphSerializer&&window.CyclejsDevTool_startGraphSerializer(a.sinks);return a.run()}Object.defineProperty(c,"__esModule",{value:!0});var h=b("./internals");c.setup=e;c.setupReusable=g;c.run=k;c.default=k},{"./internals":4}], | ||
4:[function(b,l,c){(function(e){Object.defineProperty(c,"__esModule",{value:!0});var g="undefined"!==typeof window?window.xstream:"undefined"!==typeof e?e.xstream:null;e=b("quicktask");var k=b("./adapt"),h=e.default();c.makeSinkProxies=function(a){var b={},c;for(c in a)a.hasOwnProperty(c)&&(b[c]=g.default.create());return b};c.callDrivers=function(a,b){var d={},c;for(c in a)a.hasOwnProperty(c)&&(d[c]=a[c](b[c],c),d[c]&&"object"===typeof d[c]&&(d[c]._isCycleSource=c));return d};c.adaptSources=function(a){for(var b in a)a.hasOwnProperty(b)&& | ||
a[b]&&"function"===typeof a[b].shamefullySendNext&&(a[b]=k.adapt(a[b]));return a};c.replicateMany=function(a,b){var c=Object.keys(a).filter(function(a){return!!b[a]}),d={},e={};c.forEach(function(a){d[a]={_n:[],_e:[]};e[a]={next:function(b){return d[a]._n.push(b)},error:function(b){return d[a]._e.push(b)},complete:function(){}}});var k=c.map(function(b){return g.default.fromObservable(a[b]).subscribe(e[b])});c.forEach(function(a){var c=b[a],f=function(a){h(function(){return c._n(a)})},g=function(a){h(function(){(console.error|| | ||
console.log)(a);c._e(a)})};d[a]._n.forEach(f);d[a]._e.forEach(g);e[a].next=f;e[a].error=g;e[a]._n=f;e[a]._e=g});d=null;return function(){k.forEach(function(a){return a.unsubscribe()})}};c.disposeSinkProxies=function(a){Object.keys(a).forEach(function(b){return a[b]._c()})};c.disposeSources=function(a){for(var b in a)a.hasOwnProperty(b)&&a[b]&&a[b].dispose&&a[b].dispose()};c.isObjectEmpty=function(a){return 0===Object.keys(a).length}}).call(this,"undefined"!==typeof global?global:"undefined"!==typeof self? | ||
self:"undefined"!==typeof window?window:{})},{"./adapt":2,quicktask:5}],5:[function(b,l,c){(function(b){Object.defineProperty(c,"__esModule",{value:!0});c.default=function(){if("undefined"!==typeof MutationObserver){var c=document.createTextNode(""),e=[],h=0;(new MutationObserver(function(){for(;e.length;)e.shift()()})).observe(c,{characterData:!0});return function(a){e.push(a);c.data=h=1-h}}return"undefined"!==typeof setImmediate?setImmediate:"undefined"!==typeof b?b.nextTick:setTimeout}}).call(this, | ||
b("_process"))},{_process:1}]},{},[3])(3)}); |
@@ -45,8 +45,10 @@ import { CycleProgram, DisposeFunction, Drivers, Sources, FantasySinks, Engine } from './types'; | ||
* import {setupReusable} from '@cycle/run'; | ||
* const {sources, run} = setupReusable(drivers); | ||
* const {sources, run, dispose} = setupReusable(drivers); | ||
* // ... | ||
* const sinks = main(sources); | ||
* const dispose = run(sinks); | ||
* const disposeRun = run(sinks); | ||
* // ... | ||
* dispose(); | ||
* disposeRun(); | ||
* // ... | ||
* dispose(); // ends the reusability of drivers | ||
* ``` | ||
@@ -56,6 +58,9 @@ * | ||
* are driver functions. | ||
* @return {Object} an object with two properties: `sources` and | ||
* `run`. `sources` is the collection of driver sources, `run` | ||
* is the function that once called with 'sinks' as argument, will execute the | ||
* application, tying together sources with sinks. | ||
* @return {Object} an object with three properties: `sources`, `run` and | ||
* `dispose`. `sources` is the collection of driver sources, `run` is the | ||
* function that once called with 'sinks' as argument, will execute the | ||
* application, tying together sources with sinks. `dispose` terminates the | ||
* reusable resources used by the drivers. Note also that `run` returns a | ||
* dispose function which terminates resources that are specific (not reusable) | ||
* to that run. | ||
* @function setupReusable | ||
@@ -62,0 +67,0 @@ */ |
@@ -44,6 +44,4 @@ "use strict"; | ||
} | ||
var sinkProxies = internals_1.makeSinkProxies(drivers); | ||
var sources = internals_1.callDrivers(drivers, sinkProxies); | ||
var adaptedSources = internals_1.adaptSources(sources); | ||
var sinks = main(adaptedSources); | ||
var engine = setupReusable(drivers); | ||
var sinks = main(engine.sources); | ||
if (typeof window !== 'undefined') { | ||
@@ -54,9 +52,9 @@ window.Cyclejs = window.Cyclejs || {}; | ||
function _run() { | ||
var disposeReplication = internals_1.replicateMany(sinks, sinkProxies); | ||
var disposeRun = engine.run(sinks); | ||
return function dispose() { | ||
internals_1.disposeSources(sources); | ||
disposeReplication(); | ||
disposeRun(); | ||
engine.dispose(); | ||
}; | ||
} | ||
return { sinks: sinks, sources: sources, run: _run }; | ||
return { sinks: sinks, sources: engine.sources, run: _run }; | ||
} | ||
@@ -77,8 +75,10 @@ exports.setup = setup; | ||
* import {setupReusable} from '@cycle/run'; | ||
* const {sources, run} = setupReusable(drivers); | ||
* const {sources, run, dispose} = setupReusable(drivers); | ||
* // ... | ||
* const sinks = main(sources); | ||
* const dispose = run(sinks); | ||
* const disposeRun = run(sinks); | ||
* // ... | ||
* dispose(); | ||
* disposeRun(); | ||
* // ... | ||
* dispose(); // ends the reusability of drivers | ||
* ``` | ||
@@ -88,6 +88,9 @@ * | ||
* are driver functions. | ||
* @return {Object} an object with two properties: `sources` and | ||
* `run`. `sources` is the collection of driver sources, `run` | ||
* is the function that once called with 'sinks' as argument, will execute the | ||
* application, tying together sources with sinks. | ||
* @return {Object} an object with three properties: `sources`, `run` and | ||
* `dispose`. `sources` is the collection of driver sources, `run` is the | ||
* function that once called with 'sinks' as argument, will execute the | ||
* application, tying together sources with sinks. `dispose` terminates the | ||
* reusable resources used by the drivers. Note also that `run` returns a | ||
* dispose function which terminates resources that are specific (not reusable) | ||
* to that run. | ||
* @function setupReusable | ||
@@ -108,9 +111,9 @@ */ | ||
function _run(sinks) { | ||
var disposeReplication = internals_1.replicateMany(sinks, sinkProxies); | ||
return function dispose() { | ||
internals_1.disposeSources(sources); | ||
disposeReplication(); | ||
}; | ||
return internals_1.replicateMany(sinks, sinkProxies); | ||
} | ||
return { sources: sources, run: _run }; | ||
function disposeEngine() { | ||
internals_1.disposeSources(sources); | ||
internals_1.disposeSinkProxies(sinkProxies); | ||
} | ||
return { sources: sources, run: _run, dispose: disposeEngine }; | ||
} | ||
@@ -117,0 +120,0 @@ exports.setupReusable = setupReusable; |
@@ -6,3 +6,4 @@ import { DisposeFunction, Drivers, SinkProxies, Sources, Sinks } from './types'; | ||
export declare function replicateMany<Si extends Sinks>(sinks: Si, sinkProxies: SinkProxies<Si>): DisposeFunction; | ||
export declare function disposeSinkProxies<Si extends Sinks>(sinkProxies: SinkProxies<Si>): void; | ||
export declare function disposeSources<So extends Sources>(sources: So): void; | ||
export declare function isObjectEmpty(obj: any): boolean; |
@@ -80,6 +80,9 @@ "use strict"; | ||
subscriptions.forEach(function (s) { return s.unsubscribe(); }); | ||
sinkNames.forEach(function (name) { return sinkProxies[name]._c(); }); | ||
}; | ||
} | ||
exports.replicateMany = replicateMany; | ||
function disposeSinkProxies(sinkProxies) { | ||
Object.keys(sinkProxies).forEach(function (name) { return sinkProxies[name]._c(); }); | ||
} | ||
exports.disposeSinkProxies = disposeSinkProxies; | ||
function disposeSources(sources) { | ||
@@ -86,0 +89,0 @@ for (var k in sources) { |
@@ -43,2 +43,3 @@ import { Stream } from 'xstream'; | ||
run(sinks: Si): DisposeFunction; | ||
dispose(): void; | ||
} |
@@ -45,8 +45,10 @@ import { CycleProgram, DisposeFunction, Drivers, Sources, FantasySinks, Engine } from './types'; | ||
* import {setupReusable} from '@cycle/run'; | ||
* const {sources, run} = setupReusable(drivers); | ||
* const {sources, run, dispose} = setupReusable(drivers); | ||
* // ... | ||
* const sinks = main(sources); | ||
* const dispose = run(sinks); | ||
* const disposeRun = run(sinks); | ||
* // ... | ||
* dispose(); | ||
* disposeRun(); | ||
* // ... | ||
* dispose(); // ends the reusability of drivers | ||
* ``` | ||
@@ -56,6 +58,9 @@ * | ||
* are driver functions. | ||
* @return {Object} an object with two properties: `sources` and | ||
* `run`. `sources` is the collection of driver sources, `run` | ||
* is the function that once called with 'sinks' as argument, will execute the | ||
* application, tying together sources with sinks. | ||
* @return {Object} an object with three properties: `sources`, `run` and | ||
* `dispose`. `sources` is the collection of driver sources, `run` is the | ||
* function that once called with 'sinks' as argument, will execute the | ||
* application, tying together sources with sinks. `dispose` terminates the | ||
* reusable resources used by the drivers. Note also that `run` returns a | ||
* dispose function which terminates resources that are specific (not reusable) | ||
* to that run. | ||
* @function setupReusable | ||
@@ -62,0 +67,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
import { adaptSources, callDrivers, makeSinkProxies, disposeSources, isObjectEmpty, replicateMany, } from './internals'; | ||
import { adaptSources, callDrivers, makeSinkProxies, disposeSources, disposeSinkProxies, isObjectEmpty, replicateMany, } from './internals'; | ||
/** | ||
@@ -42,6 +42,4 @@ * A function that prepares the Cycle application to be executed. Takes a `main` | ||
} | ||
var sinkProxies = makeSinkProxies(drivers); | ||
var sources = callDrivers(drivers, sinkProxies); | ||
var adaptedSources = adaptSources(sources); | ||
var sinks = main(adaptedSources); | ||
var engine = setupReusable(drivers); | ||
var sinks = main(engine.sources); | ||
if (typeof window !== 'undefined') { | ||
@@ -52,9 +50,9 @@ window.Cyclejs = window.Cyclejs || {}; | ||
function _run() { | ||
var disposeReplication = replicateMany(sinks, sinkProxies); | ||
var disposeRun = engine.run(sinks); | ||
return function dispose() { | ||
disposeSources(sources); | ||
disposeReplication(); | ||
disposeRun(); | ||
engine.dispose(); | ||
}; | ||
} | ||
return { sinks: sinks, sources: sources, run: _run }; | ||
return { sinks: sinks, sources: engine.sources, run: _run }; | ||
} | ||
@@ -74,8 +72,10 @@ /** | ||
* import {setupReusable} from '@cycle/run'; | ||
* const {sources, run} = setupReusable(drivers); | ||
* const {sources, run, dispose} = setupReusable(drivers); | ||
* // ... | ||
* const sinks = main(sources); | ||
* const dispose = run(sinks); | ||
* const disposeRun = run(sinks); | ||
* // ... | ||
* dispose(); | ||
* disposeRun(); | ||
* // ... | ||
* dispose(); // ends the reusability of drivers | ||
* ``` | ||
@@ -85,6 +85,9 @@ * | ||
* are driver functions. | ||
* @return {Object} an object with two properties: `sources` and | ||
* `run`. `sources` is the collection of driver sources, `run` | ||
* is the function that once called with 'sinks' as argument, will execute the | ||
* application, tying together sources with sinks. | ||
* @return {Object} an object with three properties: `sources`, `run` and | ||
* `dispose`. `sources` is the collection of driver sources, `run` is the | ||
* function that once called with 'sinks' as argument, will execute the | ||
* application, tying together sources with sinks. `dispose` terminates the | ||
* reusable resources used by the drivers. Note also that `run` returns a | ||
* dispose function which terminates resources that are specific (not reusable) | ||
* to that run. | ||
* @function setupReusable | ||
@@ -105,9 +108,9 @@ */ | ||
function _run(sinks) { | ||
var disposeReplication = replicateMany(sinks, sinkProxies); | ||
return function dispose() { | ||
disposeSources(sources); | ||
disposeReplication(); | ||
}; | ||
return replicateMany(sinks, sinkProxies); | ||
} | ||
return { sources: sources, run: _run }; | ||
function disposeEngine() { | ||
disposeSources(sources); | ||
disposeSinkProxies(sinkProxies); | ||
} | ||
return { sources: sources, run: _run, dispose: disposeEngine }; | ||
} | ||
@@ -114,0 +117,0 @@ /** |
@@ -6,3 +6,4 @@ import { DisposeFunction, Drivers, SinkProxies, Sources, Sinks } from './types'; | ||
export declare function replicateMany<Si extends Sinks>(sinks: Si, sinkProxies: SinkProxies<Si>): DisposeFunction; | ||
export declare function disposeSinkProxies<Si extends Sinks>(sinkProxies: SinkProxies<Si>): void; | ||
export declare function disposeSources<So extends Sources>(sources: So): void; | ||
export declare function isObjectEmpty(obj: any): boolean; |
@@ -75,5 +75,7 @@ import xs from 'xstream'; | ||
subscriptions.forEach(function (s) { return s.unsubscribe(); }); | ||
sinkNames.forEach(function (name) { return sinkProxies[name]._c(); }); | ||
}; | ||
} | ||
export function disposeSinkProxies(sinkProxies) { | ||
Object.keys(sinkProxies).forEach(function (name) { return sinkProxies[name]._c(); }); | ||
} | ||
export function disposeSources(sources) { | ||
@@ -80,0 +82,0 @@ for (var k in sources) { |
@@ -43,2 +43,3 @@ import { Stream } from 'xstream'; | ||
run(sinks: Si): DisposeFunction; | ||
dispose(): void; | ||
} |
{ | ||
"name": "@cycle/run", | ||
"version": "4.3.0", | ||
"version": "4.4.0", | ||
"description": "The Cycle.js run() function to use with xstream", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -19,2 +19,3 @@ import xs, {Stream} from 'xstream'; | ||
disposeSources, | ||
disposeSinkProxies, | ||
isObjectEmpty, | ||
@@ -90,6 +91,4 @@ replicateMany, | ||
const sinkProxies = makeSinkProxies<So, Si>(drivers); | ||
const sources = callDrivers<So, Si>(drivers, sinkProxies); | ||
const adaptedSources = adaptSources(sources); | ||
const sinks = main(adaptedSources); | ||
const engine = setupReusable(drivers); | ||
const sinks = main(engine.sources); | ||
if (typeof window !== 'undefined') { | ||
@@ -100,9 +99,9 @@ (window as any).Cyclejs = (window as any).Cyclejs || {}; | ||
function _run(): DisposeFunction { | ||
const disposeReplication = replicateMany(sinks, sinkProxies); | ||
const disposeRun = engine.run(sinks); | ||
return function dispose() { | ||
disposeSources(sources); | ||
disposeReplication(); | ||
disposeRun(); | ||
engine.dispose(); | ||
}; | ||
} | ||
return {sinks, sources, run: _run}; | ||
return {sinks, sources: engine.sources, run: _run}; | ||
} | ||
@@ -123,8 +122,10 @@ | ||
* import {setupReusable} from '@cycle/run'; | ||
* const {sources, run} = setupReusable(drivers); | ||
* const {sources, run, dispose} = setupReusable(drivers); | ||
* // ... | ||
* const sinks = main(sources); | ||
* const dispose = run(sinks); | ||
* const disposeRun = run(sinks); | ||
* // ... | ||
* dispose(); | ||
* disposeRun(); | ||
* // ... | ||
* dispose(); // ends the reusability of drivers | ||
* ``` | ||
@@ -134,6 +135,9 @@ * | ||
* are driver functions. | ||
* @return {Object} an object with two properties: `sources` and | ||
* `run`. `sources` is the collection of driver sources, `run` | ||
* is the function that once called with 'sinks' as argument, will execute the | ||
* application, tying together sources with sinks. | ||
* @return {Object} an object with three properties: `sources`, `run` and | ||
* `dispose`. `sources` is the collection of driver sources, `run` is the | ||
* function that once called with 'sinks' as argument, will execute the | ||
* application, tying together sources with sinks. `dispose` terminates the | ||
* reusable resources used by the drivers. Note also that `run` returns a | ||
* dispose function which terminates resources that are specific (not reusable) | ||
* to that run. | ||
* @function setupReusable | ||
@@ -161,9 +165,9 @@ */ | ||
function _run(sinks: Si): DisposeFunction { | ||
const disposeReplication = replicateMany(sinks, sinkProxies); | ||
return function dispose() { | ||
disposeSources(sources); | ||
disposeReplication(); | ||
}; | ||
return replicateMany(sinks, sinkProxies); | ||
} | ||
return {sources, run: _run}; | ||
function disposeEngine() { | ||
disposeSources(sources); | ||
disposeSinkProxies(sinkProxies); | ||
} | ||
return {sources, run: _run, dispose: disposeEngine}; | ||
} | ||
@@ -170,0 +174,0 @@ |
@@ -127,6 +127,11 @@ import xs, {Stream} from 'xstream'; | ||
subscriptions.forEach(s => s.unsubscribe()); | ||
sinkNames.forEach(name => sinkProxies[name]._c()); | ||
}; | ||
} | ||
export function disposeSinkProxies<Si extends Sinks>( | ||
sinkProxies: SinkProxies<Si>, | ||
) { | ||
Object.keys(sinkProxies).forEach(name => sinkProxies[name]._c()); | ||
} | ||
export function disposeSources<So extends Sources>(sources: So) { | ||
@@ -133,0 +138,0 @@ for (const k in sources) { |
@@ -52,2 +52,3 @@ import {Stream} from 'xstream'; | ||
run(sinks: Si): DisposeFunction; | ||
dispose(): void; | ||
} |
@@ -70,3 +70,3 @@ import 'mocha'; | ||
it('should allow reusing drivers for many apps', function() { | ||
it('should allow reusing drivers for many apps', function(done) { | ||
let sandbox = sinon.sandbox.create(); | ||
@@ -85,6 +85,3 @@ const spy1 = sandbox.spy(); | ||
return { | ||
other: sources.other | ||
.startWith('a') | ||
.take(1) | ||
.debug(spy1), | ||
other: sources.other.mapTo('a').debug(spy1), | ||
}; | ||
@@ -95,10 +92,16 @@ } | ||
return { | ||
other: sources.other | ||
.startWith('x') | ||
.take(1) | ||
.debug(spy2), | ||
other: sources.other.mapTo('x').debug(spy2), | ||
}; | ||
} | ||
let sinkCompleted = 0; | ||
function driver(sink: Stream<string>) { | ||
sink.addListener({ | ||
complete: () => { | ||
sinkCompleted++; | ||
done( | ||
new Error('complete should not be called before engine is before'), | ||
); | ||
}, | ||
}); | ||
return xs.of('b'); | ||
@@ -119,4 +122,44 @@ } | ||
dispose2(); | ||
assert.strictEqual(sinkCompleted, 0); | ||
done(); | ||
}); | ||
it('should allow disposing the engine, stopping reusability', function(done) { | ||
let sandbox = sinon.sandbox.create(); | ||
const spy = sandbox.spy(); | ||
type NiceSources = { | ||
other: Stream<string>; | ||
}; | ||
type NiceSinks = { | ||
other: Stream<string>; | ||
}; | ||
function app(sources: NiceSources): NiceSinks { | ||
return { | ||
other: sources.other.mapTo('a').debug(spy), | ||
}; | ||
} | ||
let sinkCompleted = 0; | ||
function driver(sink: Stream<string>) { | ||
sink.addListener({ | ||
complete: () => { | ||
sinkCompleted++; | ||
}, | ||
}); | ||
return xs.of('b'); | ||
} | ||
const engine = setupReusable<NiceSources, NiceSinks>({other: driver}); | ||
engine.run(app(engine.sources)); | ||
sinon.assert.calledOnce(spy); | ||
sinon.assert.calledWithExactly(spy, 'a'); | ||
sandbox.restore(); | ||
engine.dispose(); | ||
assert.strictEqual(sinkCompleted, 1); | ||
done(); | ||
}); | ||
it('should report errors from main() in the console', function(done) { | ||
@@ -123,0 +166,0 @@ const sandbox = sinon.sandbox.create(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
114370
2469
0