Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cycle/run

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cycle/run - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

21

CHANGELOG.md

@@ -0,1 +1,22 @@

<a name="2.0.0"></a>
# 2.0.0 (2017-03-05)
### Bug Fixes
* **run:** type check keyof drivers and main with TypeScript 2.2 ([da528c7](https://github.com/cyclejs/cyclejs/tree/master/run/commit/da528c7))
### BREAKING CHANGES
* run: If you are using JavaScript, literally nothing has changed, and this is not a breaking release.
However, if you are using TypeScript, this version may catch errors and typos that previous Cycle
Run versions didnt. Also, this version expects that if Sinks of main() are typed, they must be a
type alias, not an interface. Usually you should leave the Sinks object implicitly typed, but we
also support type aliases if you want to explicitly type them.
ISSUES CLOSED: 538
<a name="1.0.0"></a>

@@ -2,0 +23,0 @@ # 1.0.0 (2017-02-22)

3

dist/cycle-run.js
(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";
Object.defineProperty(exports, "__esModule", { value: true });
var adaptStream = function (x) { return x; };

@@ -16,2 +17,3 @@ function setAdapt(f) {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var xstream_1 = (typeof window !== "undefined" ? window['xstream'] : typeof global !== "undefined" ? global['xstream'] : null);

@@ -198,3 +200,2 @@ var adapt_1 = require("./adapt");

exports.run = run;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = run;

@@ -201,0 +202,0 @@

@@ -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.createWithMemory()}}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)&&sources[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:[]};replicators[name]={next:function(x){return buffers[name]._n.push(x)},error:function(err){return buffers[name]._e.push(err)},complete:function(){}}});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)};buffers[name]._n.forEach(next);buffers[name]._e.forEach(error);replicators[name].next=next;replicators[name].error=error;replicators[name]._n=next;replicators[name]._e=error});buffers=null;return function disposeReplication(){subscriptions.forEach(function(s){return s.unsubscribe()});sinkNames.forEach(function(name){return sinkProxies[name]._c()})}}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)});
(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";Object.defineProperty(exports,"__esModule",{value:true});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";Object.defineProperty(exports,"__esModule",{value:true});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.createWithMemory()}}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)&&sources[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:[]};replicators[name]={next:function(x){return buffers[name]._n.push(x)},error:function(err){return buffers[name]._e.push(err)},complete:function(){}}});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)};buffers[name]._n.forEach(next);buffers[name]._e.forEach(error);replicators[name].next=next;replicators[name].error=error;replicators[name]._n=next;replicators[name]._e=error});buffers=null;return function disposeReplication(){subscriptions.forEach(function(s){return s.unsubscribe()});sinkNames.forEach(function(name){return sinkProxies[name]._c()})}}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;exports.default=run}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./adapt":1}]},{},[2])(2)});
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var adaptStream = function (x) { return x; };

@@ -3,0 +4,0 @@ function setAdapt(f) {

@@ -13,5 +13,15 @@ import { MemoryStream } from 'xstream';

}
export interface Sinks {
[driverName: string]: FantasyObservable;
export declare type DisposeFunction = () => void;
export interface DevToolEnabledSource {
_isCycleSource: string;
}
export declare type Drivers<So extends Sources, Si extends Sinks> = {
[P in keyof (So & Si)]: (stream: FantasyObservable, driverName: string) => any;
};
export declare type Sources = {
[name: string]: any;
};
export declare type Sinks = {
[name: string]: FantasyObservable;
};
/**

@@ -32,16 +42,6 @@ * Sink proxies should be MemoryStreams in order to fix race conditions for

*/
export interface SinkProxies extends Sinks {
[driverName: string]: MemoryStream<any>;
}
export declare type DisposeFunction = () => void;
export interface DevToolEnabledSource {
_isCycleSource: string;
}
export interface DriverFunction {
(stream: FantasyObservable, driverName: string): any;
}
export interface DriversDefinition {
[driverName: string]: DriverFunction;
}
export interface CycleProgram<So, Si> {
export declare type SinkProxies<Si extends Sinks> = {
[P in keyof Si]: MemoryStream<any>;
};
export interface CycleProgram<So extends Sources, Si extends Sinks> {
sources: So;

@@ -79,3 +79,3 @@ sinks: Si;

*/
export declare function setup<So, Si>(main: (sources: So) => Si, drivers: DriversDefinition): CycleProgram<So, Si>;
export declare function setup<So extends Sources, Si extends Sinks>(main: (sources: So) => Si, drivers: Drivers<So, Si>): CycleProgram<So, Si>;
/**

@@ -108,3 +108,3 @@ * Takes a `main` function and circularly connects it to the given collection

*/
export declare function run<So, Si>(main: (sources: So) => Si, drivers: DriversDefinition): DisposeFunction;
export declare function run<So extends Sources, Si extends Sinks>(main: (sources: So) => Si, drivers: Drivers<So, Si>): DisposeFunction;
export default run;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var xstream_1 = require("xstream");

@@ -183,4 +184,3 @@ var adapt_1 = require("./adapt");

exports.run = run;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = run;
//# sourceMappingURL=index.js.map
{
"name": "@cycle/run",
"version": "1.0.0",
"version": "2.0.0",
"description": "The Cycle.js run() function to use with xstream",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -18,6 +18,20 @@ import xs, {Stream, MemoryStream} from 'xstream';

export interface Sinks {
[driverName: string]: FantasyObservable;
export type DisposeFunction = () => void;
export interface DevToolEnabledSource {
_isCycleSource: string;
}
export type Drivers<So extends Sources, Si extends Sinks> = {
[P in keyof (So & Si)]: (stream: FantasyObservable, driverName: string) => any;
};
export type Sources = {
[name: string]: any;
};
export type Sinks = {
[name: string]: FantasyObservable;
};
/**

@@ -38,21 +52,7 @@ * Sink proxies should be MemoryStreams in order to fix race conditions for

*/
export interface SinkProxies extends Sinks {
[driverName: string]: MemoryStream<any>;
}
export type SinkProxies<Si extends Sinks> = {
[P in keyof Si]: MemoryStream<any>;
};
export type DisposeFunction = () => void;
export interface DevToolEnabledSource {
_isCycleSource: string;
}
export interface DriverFunction {
(stream: FantasyObservable, driverName: string): any;
}
export interface DriversDefinition {
[driverName: string]: DriverFunction;
}
export interface CycleProgram<So, Si> {
export interface CycleProgram<So extends Sources, Si extends Sinks> {
sources: So;

@@ -72,4 +72,5 @@ sinks: Si;

function makeSinkProxies(drivers: DriversDefinition): SinkProxies {
const sinkProxies: SinkProxies = {};
function makeSinkProxies<So extends Sources, Si extends Sinks>(
drivers: Drivers<So, Si>): SinkProxies<Si> {
const sinkProxies: SinkProxies<Si> = {} as SinkProxies<Si>;
for (const name in drivers) {

@@ -83,9 +84,11 @@ if (drivers.hasOwnProperty(name)) {

function callDrivers(drivers: DriversDefinition, sinkProxies: SinkProxies): any {
const sources = {};
function callDrivers<So extends Sources, Si extends Sinks>(
drivers: Drivers<So, Si>,
sinkProxies: SinkProxies<Si>): So {
const sources: So = {} as So;
for (const name in drivers) {
if (drivers.hasOwnProperty(name)) {
sources[name] = drivers[name](sinkProxies[name], name);
if (sources[name] && typeof sources[name] === 'object') {
(sources[name] as DevToolEnabledSource)._isCycleSource = name;
sources[name as any] = drivers[name](sinkProxies[name], name);
if (sources[name as any] && typeof sources[name as any] === 'object') {
(sources[name as any] as DevToolEnabledSource)._isCycleSource = name;
}

@@ -98,3 +101,3 @@ }

// NOTE: this will mutate `sources`.
function adaptSources<So extends Object>(sources: So): So {
function adaptSources<So extends Sources>(sources: So): So {
for (const name in sources) {

@@ -116,4 +119,4 @@ if (sources.hasOwnProperty(name)

*/
interface SinkReplicators {
[name: string]: {
type SinkReplicators<Si extends Sinks> = {
[P in keyof Si]: {
next(x: any): void;

@@ -125,16 +128,18 @@ _n?(x: any): void;

};
}
};
interface ReplicationBuffers {
[name: string]: {
type ReplicationBuffers<Si extends Sinks> = {
[P in keyof Si]: {
_n: Array<any>;
_e: Array<any>;
};
}
};
function replicateMany(sinks: Sinks, sinkProxies: SinkProxies): DisposeFunction {
const sinkNames = Object.keys(sinks).filter(name => !!sinkProxies[name]);
function replicateMany<So extends Sources, Si extends Sinks>(
sinks: Si,
sinkProxies: SinkProxies<Si>): DisposeFunction {
const sinkNames: Array<keyof Si> = Object.keys(sinks).filter(name => !!sinkProxies[name]);
let buffers: ReplicationBuffers = {};
const replicators: SinkReplicators = {};
let buffers: ReplicationBuffers<Si> = {} as ReplicationBuffers<Si>;
const replicators: SinkReplicators<Si> = {} as SinkReplicators<Si>;
sinkNames.forEach((name) => {

@@ -150,3 +155,3 @@ buffers[name] = {_n: [], _e: []};

const subscriptions = sinkNames
.map(name => xs.fromObservable<any>(sinks[name]).subscribe(replicators[name]));
.map(name => xs.fromObservable(sinks[name] as any).subscribe(replicators[name]));

@@ -174,3 +179,3 @@ sinkNames.forEach((name) => {

function disposeSources<So>(sources: So) {
function disposeSources<So extends Sources>(sources: So) {
for (const k in sources) {

@@ -215,4 +220,5 @@ if (sources.hasOwnProperty(k) && sources[k] && (sources[k] as any).dispose) {

*/
export function setup<So, Si>(main: (sources: So) => Si,
drivers: DriversDefinition): CycleProgram<So, Si> {
export function setup<So extends Sources, Si extends Sinks>(
main: (sources: So) => Si,
drivers: Drivers<So, Si>): CycleProgram<So, Si> {
if (typeof main !== `function`) {

@@ -232,5 +238,5 @@ throw new Error(`First argument given to Cycle must be the 'main' ` +

const sinkProxies = makeSinkProxies(drivers);
const sources: So = callDrivers(drivers, sinkProxies);
const adaptedSources: So = adaptSources(sources);
const sinks: Si = main(adaptedSources);
const sources = callDrivers(drivers, sinkProxies);
const adaptedSources = adaptSources(sources);
const sinks = main(adaptedSources);
if (typeof window !== 'undefined') {

@@ -241,3 +247,3 @@ (window as any).Cyclejs = (window as any).Cyclejs || {};

function run(): DisposeFunction {
const disposeReplication = replicateMany(sinks as any as Sinks, sinkProxies);
const disposeReplication = replicateMany(sinks, sinkProxies);
return function dispose() {

@@ -278,4 +284,5 @@ disposeSources(sources);

*/
export function run<So, Si>(main: (sources: So) => Si,
drivers: DriversDefinition): DisposeFunction {
export function run<So extends Sources, Si extends Sinks>(
main: (sources: So) => Si,
drivers: Drivers<So, Si>): DisposeFunction {
const {run, sinks} = setup(main, drivers);

@@ -282,0 +289,0 @@ if (typeof window !== 'undefined' && window['CyclejsDevTool_startGraphSerializer']) {

@@ -57,2 +57,16 @@ import 'mocha';

it('should type-check keyof sources and sinks in main and drivers', function () {
function app(ext: {other: Stream<string>}) {
return {
other: ext.other.take(1).startWith('a'),
};
}
function driver() {
return xs.of('b');
}
setup(app, {other: driver});
});
it('should call DevTool internal function to pass sinks', function () {

@@ -77,10 +91,7 @@ let sandbox = sinon.sandbox.create();

it('should return a run() which in turn returns a dispose()', function (done) {
interface TestSources {
type TestSources = {
other: Stream<number>;
}
interface TestSinks {
other: Stream<string>;
}
};
function app(sources: TestSources): TestSinks {
function app(sources: TestSources) {
return {

@@ -93,6 +104,9 @@ other: concat(

}
function driver(sink: Stream<string>) {
return sink.map(x => x.charCodeAt(0)).compose(delay(1));
}
let {sources, run} = setup<TestSources, TestSinks>(app, {other: driver});
const {sources, run} = setup(app, {other: driver});
let dispose: any;

@@ -178,10 +192,7 @@ sources.other.addListener({

it('should not work after has been disposed', function (done) {
interface MySources {
type MySources = {
other: Stream<string>;
}
interface MySinks {
other: Stream<number>;
}
};
function app(sources: MySources): MySinks {
function app(sources: MySources) {
return {other: xs.periodic(100).map(i => i + 1)};

@@ -193,3 +204,3 @@ }

const {sources, run} = setup<MySources, MySinks>(app, {
const {sources, run} = setup(app, {
other: driver,

@@ -240,8 +251,8 @@ });

interface NiceSources {
type NiceSources = {
other: Stream<string>;
}
interface NiceSinks {
};
type NiceSinks = {
other: Stream<string>;
}
};

@@ -258,3 +269,3 @@ function app(sources: NiceSources): NiceSinks {

let dispose = run<NiceSources, NiceSinks>(app, {other: driver});
let dispose = run(app, {other: driver});
assert.strictEqual(typeof dispose, 'function');

@@ -261,0 +272,0 @@ sinon.assert.calledOnce(spy);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc