@cycle/run
Advanced tools
Comparing version 1.0.0-rc.5 to 1.0.0-rc.6
@@ -0,1 +1,11 @@ | ||
<a name="1.0.0-rc.6"></a> | ||
# 1.0.0-rc.6 (2016-12-14) | ||
### Bug Fixes | ||
* **run:** adapt() sources, do not adapt() sinks ([0fd15ed](https://github.com/cyclejs/cyclejs/tree/master/run/commit/0fd15ed)) | ||
<a name="1.0.0-rc.5"></a> | ||
@@ -2,0 +12,0 @@ # 1.0.0-rc.5 (2016-12-12) |
@@ -40,3 +40,3 @@ (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){ | ||
if (drivers.hasOwnProperty(name_2)) { | ||
sources[name_2] = drivers[name_2](adapt_1.adapt(sinkProxies[name_2]), name_2); | ||
sources[name_2] = drivers[name_2](sinkProxies[name_2], name_2); | ||
if (sources[name_2] && typeof sources[name_2] === 'object') { | ||
@@ -49,2 +49,12 @@ sources[name_2]._isCycleSource = name_2; | ||
} | ||
// NOTE: this will mutate `sources`. | ||
function adaptSources(sources) { | ||
for (var name_3 in sources) { | ||
if (sources.hasOwnProperty(name_3) | ||
&& typeof sources[name_3]['shamefullySendNext'] === 'function') { | ||
sources[name_3] = adapt_1.adapt(sources[name_3]); | ||
} | ||
} | ||
return sources; | ||
} | ||
function replicateMany(sinks, sinkProxies) { | ||
@@ -137,3 +147,4 @@ var sinkNames = Object.keys(sinks).filter(function (name) { return !!sinkProxies[name]; }); | ||
var sources = callDrivers(drivers, sinkProxies); | ||
var sinks = main(sources); | ||
var adaptedSources = adaptSources(sources); | ||
var sinks = main(adaptedSources); | ||
if (typeof window !== 'undefined') { | ||
@@ -140,0 +151,0 @@ window.Cyclejs = window.Cyclejs || {}; |
@@ -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.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){"use strict";var adaptStream=function(x){return x};function setAdapt(f){adaptStream=f}exports.setAdapt=setAdapt;function adapt(stream){return adaptStream(stream)}exports.adapt=adapt},{}],2:[function(require,module,exports){(function(global){"use strict";var xstream_1=typeof window!=="undefined"?window["xstream"]:typeof global!=="undefined"?global["xstream"]:null;var adapt_1=require("./adapt");function logToConsoleError(err){var target=err.stack||err;if(console&&console.error){console.error(target)}else if(console&&console.log){console.log(target)}}function makeSinkProxies(drivers){var sinkProxies={};for(var name_1 in drivers){if(drivers.hasOwnProperty(name_1)){sinkProxies[name_1]=xstream_1.default.create()}}return sinkProxies}function callDrivers(drivers,sinkProxies){var sources={};for(var name_2 in drivers){if(drivers.hasOwnProperty(name_2)){sources[name_2]=drivers[name_2](adapt_1.adapt(sinkProxies[name_2]),name_2);if(sources[name_2]&&typeof sources[name_2]==="object"){sources[name_2]._isCycleSource=name_2}}}return sources}function replicateMany(sinks,sinkProxies){var sinkNames=Object.keys(sinks).filter(function(name){return!!sinkProxies[name]});var buffers={};var replicators={};sinkNames.forEach(function(name){buffers[name]={_n:[],_e:[],_c:[]};replicators[name]={next:function(x){return buffers[name]._n.push(x)},error:function(err){return buffers[name]._e.push(err)},complete:function(){return buffers[name]._c.push(null)}}});var subscriptions=sinkNames.map(function(name){return xstream_1.default.fromObservable(sinks[name]).subscribe(replicators[name])});sinkNames.forEach(function(name){var listener=sinkProxies[name];var next=function(x){listener._n(x)};var error=function(err){logToConsoleError(err);listener._e(err)};var complete=function(){return listener._c()};buffers[name]._n.forEach(next);buffers[name]._e.forEach(error);buffers[name]._c.forEach(complete);replicators[name].next=next;replicators[name].error=error;replicators[name].complete=complete;replicators[name]._n=next;replicators[name]._e=error;replicators[name]._c=complete});buffers=null;return function disposeReplication(){subscriptions.forEach(function(s){return s.unsubscribe()})}}function disposeSources(sources){for(var k in sources){if(sources.hasOwnProperty(k)&&sources[k]&&sources[k].dispose){sources[k].dispose()}}}function isObjectEmpty(obj){return Object.keys(obj).length===0}function setup(main,drivers){if(typeof main!=="function"){throw new Error("First argument given to Cycle must be the 'main' "+"function.")}if(typeof drivers!=="object"||drivers===null){throw new Error("Second argument given to Cycle must be an object "+"with driver functions as properties.")}if(isObjectEmpty(drivers)){throw new Error("Second argument given to Cycle must be an object "+"with at least one driver function declared as a property.")}var sinkProxies=makeSinkProxies(drivers);var sources=callDrivers(drivers,sinkProxies);var sinks=main(sources);if(typeof window!=="undefined"){window.Cyclejs=window.Cyclejs||{};window.Cyclejs.sinks=sinks}function run(){var disposeReplication=replicateMany(sinks,sinkProxies);return function dispose(){disposeSources(sources);disposeReplication()}}return{sinks:sinks,sources:sources,run:run}}exports.setup=setup;function run(main,drivers){var _a=setup(main,drivers),run=_a.run,sinks=_a.sinks;if(typeof window!=="undefined"&&window["CyclejsDevTool_startGraphSerializer"]){window["CyclejsDevTool_startGraphSerializer"](sinks)}return run()}exports.run=run;Object.defineProperty(exports,"__esModule",{value:true});exports.default=run}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./adapt":1}]},{},[2])(2)}); | ||
(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){"use strict";var adaptStream=function(x){return x};function setAdapt(f){adaptStream=f}exports.setAdapt=setAdapt;function adapt(stream){return adaptStream(stream)}exports.adapt=adapt},{}],2:[function(require,module,exports){(function(global){"use strict";var xstream_1=typeof window!=="undefined"?window["xstream"]:typeof global!=="undefined"?global["xstream"]:null;var adapt_1=require("./adapt");function logToConsoleError(err){var target=err.stack||err;if(console&&console.error){console.error(target)}else if(console&&console.log){console.log(target)}}function makeSinkProxies(drivers){var sinkProxies={};for(var name_1 in drivers){if(drivers.hasOwnProperty(name_1)){sinkProxies[name_1]=xstream_1.default.create()}}return sinkProxies}function callDrivers(drivers,sinkProxies){var sources={};for(var name_2 in drivers){if(drivers.hasOwnProperty(name_2)){sources[name_2]=drivers[name_2](sinkProxies[name_2],name_2);if(sources[name_2]&&typeof sources[name_2]==="object"){sources[name_2]._isCycleSource=name_2}}}return sources}function adaptSources(sources){for(var name_3 in sources){if(sources.hasOwnProperty(name_3)&&typeof sources[name_3]["shamefullySendNext"]==="function"){sources[name_3]=adapt_1.adapt(sources[name_3])}}return sources}function replicateMany(sinks,sinkProxies){var sinkNames=Object.keys(sinks).filter(function(name){return!!sinkProxies[name]});var buffers={};var replicators={};sinkNames.forEach(function(name){buffers[name]={_n:[],_e:[],_c:[]};replicators[name]={next:function(x){return buffers[name]._n.push(x)},error:function(err){return buffers[name]._e.push(err)},complete:function(){return buffers[name]._c.push(null)}}});var subscriptions=sinkNames.map(function(name){return xstream_1.default.fromObservable(sinks[name]).subscribe(replicators[name])});sinkNames.forEach(function(name){var listener=sinkProxies[name];var next=function(x){listener._n(x)};var error=function(err){logToConsoleError(err);listener._e(err)};var complete=function(){return listener._c()};buffers[name]._n.forEach(next);buffers[name]._e.forEach(error);buffers[name]._c.forEach(complete);replicators[name].next=next;replicators[name].error=error;replicators[name].complete=complete;replicators[name]._n=next;replicators[name]._e=error;replicators[name]._c=complete});buffers=null;return function disposeReplication(){subscriptions.forEach(function(s){return s.unsubscribe()})}}function disposeSources(sources){for(var k in sources){if(sources.hasOwnProperty(k)&&sources[k]&&sources[k].dispose){sources[k].dispose()}}}function isObjectEmpty(obj){return Object.keys(obj).length===0}function setup(main,drivers){if(typeof main!=="function"){throw new Error("First argument given to Cycle must be the 'main' "+"function.")}if(typeof drivers!=="object"||drivers===null){throw new Error("Second argument given to Cycle must be an object "+"with driver functions as properties.")}if(isObjectEmpty(drivers)){throw new Error("Second argument given to Cycle must be an object "+"with at least one driver function declared as a property.")}var sinkProxies=makeSinkProxies(drivers);var sources=callDrivers(drivers,sinkProxies);var adaptedSources=adaptSources(sources);var sinks=main(adaptedSources);if(typeof window!=="undefined"){window.Cyclejs=window.Cyclejs||{};window.Cyclejs.sinks=sinks}function run(){var disposeReplication=replicateMany(sinks,sinkProxies);return function dispose(){disposeSources(sources);disposeReplication()}}return{sinks:sinks,sources:sources,run:run}}exports.setup=setup;function run(main,drivers){var _a=setup(main,drivers),run=_a.run,sinks=_a.sinks;if(typeof window!=="undefined"&&window["CyclejsDevTool_startGraphSerializer"]){window["CyclejsDevTool_startGraphSerializer"](sinks)}return run()}exports.run=run;Object.defineProperty(exports,"__esModule",{value:true});exports.default=run}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./adapt":1}]},{},[2])(2)}); |
@@ -26,3 +26,3 @@ "use strict"; | ||
if (drivers.hasOwnProperty(name_2)) { | ||
sources[name_2] = drivers[name_2](adapt_1.adapt(sinkProxies[name_2]), name_2); | ||
sources[name_2] = drivers[name_2](sinkProxies[name_2], name_2); | ||
if (sources[name_2] && typeof sources[name_2] === 'object') { | ||
@@ -35,2 +35,12 @@ sources[name_2]._isCycleSource = name_2; | ||
} | ||
// NOTE: this will mutate `sources`. | ||
function adaptSources(sources) { | ||
for (var name_3 in sources) { | ||
if (sources.hasOwnProperty(name_3) | ||
&& typeof sources[name_3]['shamefullySendNext'] === 'function') { | ||
sources[name_3] = adapt_1.adapt(sources[name_3]); | ||
} | ||
} | ||
return sources; | ||
} | ||
function replicateMany(sinks, sinkProxies) { | ||
@@ -123,3 +133,4 @@ var sinkNames = Object.keys(sinks).filter(function (name) { return !!sinkProxies[name]; }); | ||
var sources = callDrivers(drivers, sinkProxies); | ||
var sinks = main(sources); | ||
var adaptedSources = adaptSources(sources); | ||
var sinks = main(adaptedSources); | ||
if (typeof window !== 'undefined') { | ||
@@ -126,0 +137,0 @@ window.Cyclejs = window.Cyclejs || {}; |
{ | ||
"name": "@cycle/run", | ||
"version": "1.0.0-rc.5", | ||
"version": "1.0.0-rc.6", | ||
"description": "The Cycle.js run() function to use with xstream", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -69,3 +69,3 @@ import xs, {Stream} from 'xstream'; | ||
if (drivers.hasOwnProperty(name)) { | ||
sources[name] = drivers[name](adapt(sinkProxies[name]), name); | ||
sources[name] = drivers[name](sinkProxies[name], name); | ||
if (sources[name] && typeof sources[name] === 'object') { | ||
@@ -79,2 +79,13 @@ (sources[name] as DevToolEnabledSource)._isCycleSource = name; | ||
// NOTE: this will mutate `sources`. | ||
function adaptSources<So extends Object>(sources: So): So { | ||
for (let name in sources) { | ||
if (sources.hasOwnProperty(name) | ||
&& typeof sources[name]['shamefullySendNext'] === 'function') { | ||
sources[name] = adapt(sources[name] as any as Stream<any>); | ||
} | ||
} | ||
return sources; | ||
} | ||
interface SinkReplicators { | ||
@@ -195,3 +206,4 @@ [name: string]: { | ||
const sources: So = callDrivers(drivers, sinkProxies); | ||
const sinks: Si = main(sources); | ||
const adaptedSources: So = adaptSources(sources); | ||
const sinks: Si = main(adaptedSources); | ||
if (typeof window !== 'undefined') { | ||
@@ -198,0 +210,0 @@ (window as any).Cyclejs = (window as any).Cyclejs || {}; |
@@ -5,2 +5,3 @@ import 'mocha'; | ||
import {run, setup} from '../lib'; | ||
import {setAdapt} from '../lib/adapt'; | ||
import xs, {Stream} from 'xstream'; | ||
@@ -108,2 +109,49 @@ import concat from 'xstream/extra/concat'; | ||
it('should not adapt() sinks', function (done) { | ||
function app(sources: any): any { | ||
return { | ||
other: xs.of(1, 2, 3), | ||
}; | ||
} | ||
let driverCalled = false; | ||
function driver(sink: Stream<string>) { | ||
assert.strictEqual(typeof sink, 'object'); | ||
assert.strictEqual(typeof sink.fold, 'function'); | ||
driverCalled = true; | ||
return xs.of(10, 20, 30); | ||
} | ||
setAdapt(stream => 'this not a stream'); | ||
run(app, {other: driver}); | ||
setAdapt(x => x); | ||
assert.strictEqual(driverCalled, true); | ||
done(); | ||
}); | ||
it('should adapt() a simple source (stream)', function (done) { | ||
let appCalled = false; | ||
function app(sources: any): any { | ||
assert.strictEqual(typeof sources.other, 'string'); | ||
assert.strictEqual(sources.other, 'this is adapted'); | ||
appCalled = true; | ||
return { | ||
other: xs.of(1, 2, 3), | ||
}; | ||
} | ||
function driver(sink: Stream<string>) { | ||
return xs.of(10, 20, 30); | ||
} | ||
setAdapt(stream => 'this is adapted'); | ||
run(app, {other: driver}); | ||
setAdapt(x => x); | ||
assert.strictEqual(appCalled, true); | ||
done(); | ||
}); | ||
it('should not work after has been disposed', function (done) { | ||
@@ -232,3 +280,7 @@ interface MySources { | ||
} | ||
function driver() { | ||
function driver(sink: Stream<any>) { | ||
sink.addListener({ | ||
next: () => {}, | ||
error: (err: any) => {}, | ||
}); | ||
return xs.of('b'); | ||
@@ -247,4 +299,7 @@ } | ||
sinon.assert.calledWithExactly(console.error as any, sinon.match('malfunction')); | ||
assert.strictEqual(caught, true); | ||
// Should be false because the error was already reported in the console. | ||
// Otherwise we would have double reporting of the error. | ||
assert.strictEqual(caught, false); | ||
sandbox.restore(); | ||
@@ -251,0 +306,0 @@ done(); |
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
52642
1020