@cycle/run
Advanced tools
Comparing version 4.4.0 to 5.0.0-rc.0
@@ -1,3 +0,3 @@ | ||
import { CycleProgram, DisposeFunction, Drivers, Sources, FantasySinks, Engine } from './types'; | ||
export { FantasyObserver, FantasySubscription, FantasyObservable, DevToolEnabledSource, Sources, Sinks, SinkProxies, FantasySinks, Driver, Drivers, DisposeFunction, CycleProgram, Engine } from './types'; | ||
import { CycleProgram, DisposeFunction, Drivers, MatchingDrivers, MatchingMain, Engine } from './types'; | ||
export { FantasyObserver, FantasySubscription, FantasyObservable, DevToolEnabledSource, Sources, Sinks, SinkProxies, Driver, Drivers, DisposeFunction, MatchingDrivers, MatchingMain, Main, CycleProgram, Engine, } from './types'; | ||
/** | ||
@@ -31,3 +31,3 @@ * A function that prepares the Cycle application to be executed. Takes a `main` | ||
*/ | ||
export declare function setup<So extends Sources, Si extends FantasySinks<Si>>(main: (sources: So) => Si, drivers: Drivers<So, Si>): CycleProgram<So, Si>; | ||
export declare function setup<D extends MatchingDrivers<D, M>, M extends MatchingMain<D, M>>(main: M, drivers: D): CycleProgram<D, M>; | ||
/** | ||
@@ -67,3 +67,3 @@ * A partially-applied variant of setup() which accepts only the drivers, and | ||
*/ | ||
export declare function setupReusable<So extends Sources, Si extends FantasySinks<Si>>(drivers: Drivers<So, Si>): Engine<So, Si>; | ||
export declare function setupReusable<D extends Drivers>(drivers: D): Engine<D>; | ||
/** | ||
@@ -96,3 +96,3 @@ * Takes a `main` function and circularly connects it to the given collection | ||
*/ | ||
export declare function run<So extends Sources, Si extends FantasySinks<Si>>(main: (sources: So) => Si, drivers: Drivers<So, Si>): DisposeFunction; | ||
export declare function run<D extends MatchingDrivers<D, M>, M extends MatchingMain<D, M>>(main: M, drivers: D): DisposeFunction; | ||
export default run; |
@@ -146,4 +146,4 @@ "use strict"; | ||
if (typeof window !== 'undefined' && | ||
window['CyclejsDevTool_startGraphSerializer']) { | ||
window['CyclejsDevTool_startGraphSerializer'](program.sinks); | ||
window.CyclejsDevTool_startGraphSerializer) { | ||
window.CyclejsDevTool_startGraphSerializer(program.sinks); | ||
} | ||
@@ -150,0 +150,0 @@ return program.run(); |
@@ -1,8 +0,8 @@ | ||
import { DisposeFunction, Drivers, SinkProxies, Sources, Sinks } from './types'; | ||
export declare function makeSinkProxies<So extends Sources, Si extends Sinks>(drivers: Drivers<So, Si>): SinkProxies<Si>; | ||
export declare function callDrivers<So extends Sources, Si extends Sinks>(drivers: Drivers<So, Si>, sinkProxies: SinkProxies<Si>): So; | ||
export declare function adaptSources<So extends Sources>(sources: So): So; | ||
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; | ||
import { DisposeFunction, Drivers, SinkProxies, Sources } from './types'; | ||
export declare function makeSinkProxies<D extends Drivers>(drivers: D): SinkProxies<D>; | ||
export declare function callDrivers<D extends Drivers>(drivers: D, sinkProxies: SinkProxies<D>): Sources<D>; | ||
export declare function adaptSources<So>(sources: So): So; | ||
export declare function replicateMany<Si extends any>(sinks: Si, sinkProxies: SinkProxies<Si>): DisposeFunction; | ||
export declare function disposeSinkProxies<Si>(sinkProxies: SinkProxies<Si>): void; | ||
export declare function disposeSources<So>(sources: So): void; | ||
export declare function isObjectEmpty(obj: any): boolean; |
@@ -35,3 +35,4 @@ "use strict"; | ||
sources[name_3] && | ||
typeof sources[name_3]['shamefullySendNext'] === 'function') { | ||
typeof sources[name_3].shamefullySendNext === | ||
'function') { | ||
sources[name_3] = adapt_1.adapt(sources[name_3]); | ||
@@ -38,0 +39,0 @@ } |
@@ -16,30 +16,34 @@ import { Stream } from 'xstream'; | ||
} | ||
export declare type Sources = { | ||
[name: string]: any; | ||
export declare type SinkProxies<Si> = { | ||
[P in keyof Si]: Stream<any>; | ||
}; | ||
export declare type Sinks = { | ||
[name: string]: any; | ||
export declare type Driver<Si, So> = { | ||
(stream?: Si, driverName?: string): So; | ||
}; | ||
export declare type SinkProxies<Si extends Sinks> = { | ||
[P in keyof Si]: Stream<any>; | ||
export declare type DisposeFunction = () => void; | ||
export declare type Drivers = { | ||
[name: string]: Driver<FantasyObservable | undefined | void | null, any>; | ||
}; | ||
export declare type FantasySinks<Si> = { | ||
[S in keyof Si]: FantasyObservable; | ||
export declare type Main = (...args: Array<any>) => any; | ||
export declare type Sources<D extends Drivers> = { | ||
[k in keyof D]: ReturnType<D[k]>; | ||
}; | ||
export interface Driver<Sink, Source> { | ||
(stream: Sink, driverName?: string): Source; | ||
} | ||
export declare type Drivers<So extends Sources, Si extends Sinks> = { | ||
[P in keyof (So & Si)]: Driver<Si[P], So[P]>; | ||
export declare type Sinks<M extends Main> = { | ||
[k in (string & keyof ReturnType<M>)]: ReturnType<M>[k] & FantasyObservable; | ||
}; | ||
export declare type DisposeFunction = () => void; | ||
export interface CycleProgram<So extends Sources, Si extends Sinks> { | ||
sources: So; | ||
sinks: Si; | ||
export declare type MatchingMain<D extends Drivers, M extends Main> = Main & { | ||
(so?: Partial<Sources<D>>): Sinks<M>; | ||
}; | ||
export declare type MatchingDrivers<D extends Drivers, M extends Main> = Drivers & { | ||
[k in (string & keyof Sinks<M>)]: ((si?: Sinks<M>[k]) => Sources<D>[k]) | ((si: Sinks<M>[k]) => Sources<D>[k]); | ||
}; | ||
export interface CycleProgram<D extends MatchingDrivers<D, M>, M extends MatchingMain<D, M>> { | ||
sources: Sources<D>; | ||
sinks: Sinks<M>; | ||
run(): DisposeFunction; | ||
} | ||
export interface Engine<So extends Sources, Si extends Sinks> { | ||
sources: So; | ||
run(sinks: Si): DisposeFunction; | ||
export interface Engine<D extends Drivers> { | ||
sources: Sources<D>; | ||
run<M extends MatchingMain<D, M>>(sinks: Sinks<M>): DisposeFunction; | ||
dispose(): void; | ||
} |
@@ -1,3 +0,3 @@ | ||
import { CycleProgram, DisposeFunction, Drivers, Sources, FantasySinks, Engine } from './types'; | ||
export { FantasyObserver, FantasySubscription, FantasyObservable, DevToolEnabledSource, Sources, Sinks, SinkProxies, FantasySinks, Driver, Drivers, DisposeFunction, CycleProgram, Engine } from './types'; | ||
import { CycleProgram, DisposeFunction, Drivers, MatchingDrivers, MatchingMain, Engine } from './types'; | ||
export { FantasyObserver, FantasySubscription, FantasyObservable, DevToolEnabledSource, Sources, Sinks, SinkProxies, Driver, Drivers, DisposeFunction, MatchingDrivers, MatchingMain, Main, CycleProgram, Engine, } from './types'; | ||
/** | ||
@@ -31,3 +31,3 @@ * A function that prepares the Cycle application to be executed. Takes a `main` | ||
*/ | ||
export declare function setup<So extends Sources, Si extends FantasySinks<Si>>(main: (sources: So) => Si, drivers: Drivers<So, Si>): CycleProgram<So, Si>; | ||
export declare function setup<D extends MatchingDrivers<D, M>, M extends MatchingMain<D, M>>(main: M, drivers: D): CycleProgram<D, M>; | ||
/** | ||
@@ -67,3 +67,3 @@ * A partially-applied variant of setup() which accepts only the drivers, and | ||
*/ | ||
export declare function setupReusable<So extends Sources, Si extends FantasySinks<Si>>(drivers: Drivers<So, Si>): Engine<So, Si>; | ||
export declare function setupReusable<D extends Drivers>(drivers: D): Engine<D>; | ||
/** | ||
@@ -96,3 +96,3 @@ * Takes a `main` function and circularly connects it to the given collection | ||
*/ | ||
export declare function run<So extends Sources, Si extends FantasySinks<Si>>(main: (sources: So) => Si, drivers: Drivers<So, Si>): DisposeFunction; | ||
export declare function run<D extends MatchingDrivers<D, M>, M extends MatchingMain<D, M>>(main: M, drivers: D): DisposeFunction; | ||
export default run; |
@@ -142,4 +142,4 @@ import { adaptSources, callDrivers, makeSinkProxies, disposeSources, disposeSinkProxies, isObjectEmpty, replicateMany, } from './internals'; | ||
if (typeof window !== 'undefined' && | ||
window['CyclejsDevTool_startGraphSerializer']) { | ||
window['CyclejsDevTool_startGraphSerializer'](program.sinks); | ||
window.CyclejsDevTool_startGraphSerializer) { | ||
window.CyclejsDevTool_startGraphSerializer(program.sinks); | ||
} | ||
@@ -146,0 +146,0 @@ return program.run(); |
@@ -1,8 +0,8 @@ | ||
import { DisposeFunction, Drivers, SinkProxies, Sources, Sinks } from './types'; | ||
export declare function makeSinkProxies<So extends Sources, Si extends Sinks>(drivers: Drivers<So, Si>): SinkProxies<Si>; | ||
export declare function callDrivers<So extends Sources, Si extends Sinks>(drivers: Drivers<So, Si>, sinkProxies: SinkProxies<Si>): So; | ||
export declare function adaptSources<So extends Sources>(sources: So): So; | ||
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; | ||
import { DisposeFunction, Drivers, SinkProxies, Sources } from './types'; | ||
export declare function makeSinkProxies<D extends Drivers>(drivers: D): SinkProxies<D>; | ||
export declare function callDrivers<D extends Drivers>(drivers: D, sinkProxies: SinkProxies<D>): Sources<D>; | ||
export declare function adaptSources<So>(sources: So): So; | ||
export declare function replicateMany<Si extends any>(sinks: Si, sinkProxies: SinkProxies<Si>): DisposeFunction; | ||
export declare function disposeSinkProxies<Si>(sinkProxies: SinkProxies<Si>): void; | ||
export declare function disposeSources<So>(sources: So): void; | ||
export declare function isObjectEmpty(obj: any): boolean; |
@@ -31,3 +31,4 @@ import xs from 'xstream'; | ||
sources[name_3] && | ||
typeof sources[name_3]['shamefullySendNext'] === 'function') { | ||
typeof sources[name_3].shamefullySendNext === | ||
'function') { | ||
sources[name_3] = adapt(sources[name_3]); | ||
@@ -34,0 +35,0 @@ } |
@@ -16,30 +16,34 @@ import { Stream } from 'xstream'; | ||
} | ||
export declare type Sources = { | ||
[name: string]: any; | ||
export declare type SinkProxies<Si> = { | ||
[P in keyof Si]: Stream<any>; | ||
}; | ||
export declare type Sinks = { | ||
[name: string]: any; | ||
export declare type Driver<Si, So> = { | ||
(stream?: Si, driverName?: string): So; | ||
}; | ||
export declare type SinkProxies<Si extends Sinks> = { | ||
[P in keyof Si]: Stream<any>; | ||
export declare type DisposeFunction = () => void; | ||
export declare type Drivers = { | ||
[name: string]: Driver<FantasyObservable | undefined | void | null, any>; | ||
}; | ||
export declare type FantasySinks<Si> = { | ||
[S in keyof Si]: FantasyObservable; | ||
export declare type Main = (...args: Array<any>) => any; | ||
export declare type Sources<D extends Drivers> = { | ||
[k in keyof D]: ReturnType<D[k]>; | ||
}; | ||
export interface Driver<Sink, Source> { | ||
(stream: Sink, driverName?: string): Source; | ||
} | ||
export declare type Drivers<So extends Sources, Si extends Sinks> = { | ||
[P in keyof (So & Si)]: Driver<Si[P], So[P]>; | ||
export declare type Sinks<M extends Main> = { | ||
[k in (string & keyof ReturnType<M>)]: ReturnType<M>[k] & FantasyObservable; | ||
}; | ||
export declare type DisposeFunction = () => void; | ||
export interface CycleProgram<So extends Sources, Si extends Sinks> { | ||
sources: So; | ||
sinks: Si; | ||
export declare type MatchingMain<D extends Drivers, M extends Main> = Main & { | ||
(so?: Partial<Sources<D>>): Sinks<M>; | ||
}; | ||
export declare type MatchingDrivers<D extends Drivers, M extends Main> = Drivers & { | ||
[k in (string & keyof Sinks<M>)]: ((si?: Sinks<M>[k]) => Sources<D>[k]) | ((si: Sinks<M>[k]) => Sources<D>[k]); | ||
}; | ||
export interface CycleProgram<D extends MatchingDrivers<D, M>, M extends MatchingMain<D, M>> { | ||
sources: Sources<D>; | ||
sinks: Sinks<M>; | ||
run(): DisposeFunction; | ||
} | ||
export interface Engine<So extends Sources, Si extends Sinks> { | ||
sources: So; | ||
run(sinks: Si): DisposeFunction; | ||
export interface Engine<D extends Drivers> { | ||
sources: Sources<D>; | ||
run<M extends MatchingMain<D, M>>(sinks: Sinks<M>): DisposeFunction; | ||
dispose(): void; | ||
} |
{ | ||
"name": "@cycle/run", | ||
"version": "4.4.0", | ||
"version": "5.0.0-rc.0", | ||
"description": "The Cycle.js run() function to use with xstream", | ||
@@ -33,10 +33,14 @@ "license": "MIT", | ||
"dependencies": { | ||
"xstream": "10.x || 11.x", | ||
"quicktask": "1.1.0" | ||
"quicktask": "1.1.0", | ||
"xstream": "10.x || 11.x" | ||
}, | ||
"devDependencies": { | ||
"@types/es6-promise": "0.0.x", | ||
"@types/mocha": "2.2.x", | ||
"@types/node": "7.0.x", | ||
"@types/sinon": "1.16.x", | ||
"@types/mocha": "5.2.x", | ||
"@types/node": "10.5.x", | ||
"@types/sinon": "5.0.x", | ||
"mocha": "^5.2.0", | ||
"sinon": "^6.1.4", | ||
"ts-node": "^7.0.0", | ||
"tslint": "^5.11.0", | ||
"typescript": "3.0.x", | ||
"xstream": "11.x" | ||
@@ -47,12 +51,13 @@ }, | ||
}, | ||
"browserify-shim": { | ||
"xstream": "global:xstream" | ||
}, | ||
"scripts": { | ||
"mocha": "../node_modules/.bin/mocha test/*.ts --require ts-node/register --exit", | ||
"test": "npm run mocha", | ||
"test-ci": "npm run test", | ||
"browserify": "../node_modules/.bin/browserify lib/cjs/index.js --global-transform=browserify-shim --standalone Cycle --exclude xstream -o dist/cycle-run.js", | ||
"minify": "node ../.scripts/minify.js dist/cycle-run.js dist/cycle-run.min.js", | ||
"postlib": "cp lib/cjs/adapt.* lib/" | ||
"build": "pnpm run build-cjs && pnpm run build-es6", | ||
"build-cjs": "tsc --module commonjs --outDir ./lib/cjs", | ||
"build-es6": "tsc --module es6 --outDir ./lib/es6", | ||
"lint": "tslint --project tsconfig.lint.json --config ../tslint.json", | ||
"docs": "cd .. && node .scripts/make-api-docs.js run", | ||
"changelog": "cd .. && node .scripts/update-changelogs.js run", | ||
"test": "mocha test/*.ts --require ts-node/register --exit", | ||
"test-ci": "pnpm run test", | ||
"postbuild": "cp lib/cjs/adapt.* lib/", | ||
"prepublishOnly": "pnpm run build && pnpm run test" | ||
}, | ||
@@ -59,0 +64,0 @@ "publishConfig": { |
@@ -1,12 +0,8 @@ | ||
import xs, {Stream} from 'xstream'; | ||
import {adapt} from './adapt'; | ||
import { | ||
CycleProgram, | ||
DevToolEnabledSource, | ||
DisposeFunction, | ||
Drivers, | ||
SinkProxies, | ||
Sources, | ||
Sinks, | ||
FantasySinks, | ||
MatchingDrivers, | ||
MatchingMain, | ||
Engine, | ||
@@ -32,6 +28,8 @@ } from './types'; | ||
SinkProxies, | ||
FantasySinks, | ||
Driver, | ||
Drivers, | ||
DisposeFunction, | ||
MatchingDrivers, | ||
MatchingMain, | ||
Main, | ||
CycleProgram, | ||
@@ -69,9 +67,9 @@ Engine, | ||
*/ | ||
export function setup<So extends Sources, Si extends FantasySinks<Si>>( | ||
main: (sources: So) => Si, | ||
drivers: Drivers<So, Si>, | ||
): CycleProgram<So, Si> { | ||
export function setup< | ||
D extends MatchingDrivers<D, M>, | ||
M extends MatchingMain<D, M> | ||
>(main: M, drivers: D): CycleProgram<D, M> { | ||
if (typeof main !== `function`) { | ||
throw new Error( | ||
`First argument given to Cycle must be the 'main' ` + `function.`, | ||
`First argument given to Cycle must be the 'main' ` + `function.` | ||
); | ||
@@ -82,3 +80,3 @@ } | ||
`Second argument given to Cycle must be an object ` + | ||
`with driver functions as properties.`, | ||
`with driver functions as properties.` | ||
); | ||
@@ -89,3 +87,3 @@ } | ||
`Second argument given to Cycle must be an object ` + | ||
`with at least one driver function declared as a property.`, | ||
`with at least one driver function declared as a property.` | ||
); | ||
@@ -144,9 +142,7 @@ } | ||
*/ | ||
export function setupReusable<So extends Sources, Si extends FantasySinks<Si>>( | ||
drivers: Drivers<So, Si>, | ||
): Engine<So, Si> { | ||
export function setupReusable<D extends Drivers>(drivers: D): Engine<D> { | ||
if (typeof drivers !== `object` || drivers === null) { | ||
throw new Error( | ||
`Argument given to setupReusable must be an object ` + | ||
`with driver functions as properties.`, | ||
`with driver functions as properties.` | ||
); | ||
@@ -157,3 +153,3 @@ } | ||
`Argument given to setupReusable must be an object ` + | ||
`with at least one driver function declared as a property.`, | ||
`with at least one driver function declared as a property.` | ||
); | ||
@@ -165,4 +161,6 @@ } | ||
const sources = adaptSources(rawSources); | ||
function _run(sinks: Si): DisposeFunction { | ||
return replicateMany(sinks, sinkProxies); | ||
function _run<M extends MatchingMain<D, M>>( | ||
sinks: Sinks<M> | ||
): DisposeFunction { | ||
return replicateMany(sinks, sinkProxies as any); | ||
} | ||
@@ -203,12 +201,12 @@ function disposeEngine() { | ||
*/ | ||
export function run<So extends Sources, Si extends FantasySinks<Si>>( | ||
main: (sources: So) => Si, | ||
drivers: Drivers<So, Si>, | ||
): DisposeFunction { | ||
export function run< | ||
D extends MatchingDrivers<D, M>, | ||
M extends MatchingMain<D, M> | ||
>(main: M, drivers: D): DisposeFunction { | ||
const program = setup(main, drivers); | ||
if ( | ||
typeof window !== 'undefined' && | ||
window['CyclejsDevTool_startGraphSerializer'] | ||
(window as any).CyclejsDevTool_startGraphSerializer | ||
) { | ||
window['CyclejsDevTool_startGraphSerializer'](program.sinks); | ||
(window as any).CyclejsDevTool_startGraphSerializer(program.sinks); | ||
} | ||
@@ -215,0 +213,0 @@ return program.run(); |
@@ -10,3 +10,2 @@ import xs, {Stream} from 'xstream'; | ||
Sources, | ||
Sinks, | ||
} from './types'; | ||
@@ -16,6 +15,4 @@ | ||
export function makeSinkProxies<So extends Sources, Si extends Sinks>( | ||
drivers: Drivers<So, Si>, | ||
): SinkProxies<Si> { | ||
const sinkProxies: SinkProxies<Si> = {} as SinkProxies<Si>; | ||
export function makeSinkProxies<D extends Drivers>(drivers: D): SinkProxies<D> { | ||
const sinkProxies: SinkProxies<D> = {} as SinkProxies<D>; | ||
for (const name in drivers) { | ||
@@ -29,7 +26,7 @@ if (drivers.hasOwnProperty(name)) { | ||
export function callDrivers<So extends Sources, Si extends Sinks>( | ||
drivers: Drivers<So, Si>, | ||
sinkProxies: SinkProxies<Si>, | ||
): So { | ||
const sources: So = {} as So; | ||
export function callDrivers<D extends Drivers>( | ||
drivers: D, | ||
sinkProxies: SinkProxies<D> | ||
): Sources<D> { | ||
const sources: Sources<D> = {} as Sources<D>; | ||
for (const name in drivers) { | ||
@@ -47,3 +44,3 @@ if (drivers.hasOwnProperty(name)) { | ||
// NOTE: this will mutate `sources`. | ||
export function adaptSources<So extends Sources>(sources: So): So { | ||
export function adaptSources<So>(sources: So): So { | ||
for (const name in sources) { | ||
@@ -53,3 +50,4 @@ if ( | ||
sources[name] && | ||
typeof sources[name]['shamefullySendNext'] === 'function' | ||
typeof ((sources[name] as any) as Stream<any>).shamefullySendNext === | ||
'function' | ||
) { | ||
@@ -68,3 +66,3 @@ sources[name] = adapt((sources[name] as any) as Stream<any>); | ||
*/ | ||
type SinkReplicators<Si extends Sinks> = { | ||
type SinkReplicators<Si> = { | ||
[P in keyof Si]: { | ||
@@ -79,3 +77,3 @@ next(x: any): void; | ||
type ReplicationBuffers<Si extends Sinks> = { | ||
type ReplicationBuffers<Si> = { | ||
[P in keyof Si]: { | ||
@@ -87,8 +85,8 @@ _n: Array<any>; | ||
export function replicateMany<Si extends Sinks>( | ||
export function replicateMany<Si extends any>( | ||
sinks: Si, | ||
sinkProxies: SinkProxies<Si>, | ||
sinkProxies: SinkProxies<Si> | ||
): DisposeFunction { | ||
const sinkNames: Array<keyof Si> = Object.keys(sinks).filter( | ||
name => !!sinkProxies[name], | ||
name => !!sinkProxies[name] | ||
); | ||
@@ -108,3 +106,3 @@ | ||
const subscriptions = sinkNames.map(name => | ||
xs.fromObservable(sinks[name] as any).subscribe(replicators[name]), | ||
xs.fromObservable(sinks[name] as any).subscribe(replicators[name]) | ||
); | ||
@@ -139,9 +137,7 @@ | ||
export function disposeSinkProxies<Si extends Sinks>( | ||
sinkProxies: SinkProxies<Si>, | ||
) { | ||
export function disposeSinkProxies<Si>(sinkProxies: SinkProxies<Si>) { | ||
Object.keys(sinkProxies).forEach(name => sinkProxies[name]._c()); | ||
} | ||
export function disposeSources<So extends Sources>(sources: So) { | ||
export function disposeSources<So>(sources: So) { | ||
for (const k in sources) { | ||
@@ -148,0 +144,0 @@ if ( |
@@ -21,34 +21,46 @@ import {Stream} from 'xstream'; | ||
export type Sources = { | ||
[name: string]: any; | ||
export type SinkProxies<Si> = {[P in keyof Si]: Stream<any>}; | ||
export type Driver<Si, So> = { | ||
(stream?: Si, driverName?: string): So; | ||
}; | ||
export type Sinks = { | ||
[name: string]: any; | ||
export type DisposeFunction = () => void; | ||
export type Drivers = { | ||
[name: string]: Driver<FantasyObservable | undefined | void | null, any>; | ||
}; | ||
export type SinkProxies<Si extends Sinks> = {[P in keyof Si]: Stream<any>}; | ||
export type Main = (...args: Array<any>) => any; | ||
export type FantasySinks<Si> = {[S in keyof Si]: FantasyObservable}; | ||
export type Sources<D extends Drivers> = {[k in keyof D]: ReturnType<D[k]>}; | ||
export interface Driver<Sink, Source> { | ||
(stream: Sink, driverName?: string): Source; | ||
} | ||
export type Sinks<M extends Main> = { | ||
[k in (string & keyof ReturnType<M>)]: ReturnType<M>[k] & FantasyObservable | ||
}; | ||
export type Drivers<So extends Sources, Si extends Sinks> = { | ||
[P in keyof (So & Si)]: Driver<Si[P], So[P]> | ||
export type MatchingMain<D extends Drivers, M extends Main> = Main & { | ||
(so?: Partial<Sources<D>>): Sinks<M>; | ||
}; | ||
export type DisposeFunction = () => void; | ||
export type MatchingDrivers<D extends Drivers, M extends Main> = Drivers & | ||
{ | ||
[k in (string & keyof Sinks<M>)]: | ||
| ((si?: Sinks<M>[k]) => Sources<D>[k]) | ||
| ((si: Sinks<M>[k]) => Sources<D>[k]) | ||
}; | ||
export interface CycleProgram<So extends Sources, Si extends Sinks> { | ||
sources: So; | ||
sinks: Si; | ||
export interface CycleProgram< | ||
D extends MatchingDrivers<D, M>, | ||
M extends MatchingMain<D, M> | ||
> { | ||
sources: Sources<D>; | ||
sinks: Sinks<M>; | ||
run(): DisposeFunction; | ||
} | ||
export interface Engine<So extends Sources, Si extends Sinks> { | ||
sources: So; | ||
run(sinks: Si): DisposeFunction; | ||
export interface Engine<D extends Drivers> { | ||
sources: Sources<D>; | ||
run<M extends MatchingMain<D, M>>(sinks: Sinks<M>): DisposeFunction; | ||
dispose(): void; | ||
} |
@@ -1,6 +0,5 @@ | ||
import 'mocha'; | ||
import * as assert from 'assert'; | ||
import * as sinon from 'sinon'; | ||
import {run} from '../lib/cjs/index'; | ||
import {setAdapt} from '../lib/adapt'; | ||
import {run} from '../src/index'; | ||
import {setAdapt} from '../src/adapt'; | ||
import xs, {Stream} from 'xstream'; | ||
@@ -32,3 +31,3 @@ | ||
it('should return a dispose function', function() { | ||
let sandbox = sinon.sandbox.create(); | ||
const sandbox = sinon.createSandbox(); | ||
const spy = sandbox.spy(); | ||
@@ -53,3 +52,3 @@ | ||
let dispose = run(app, {other: driver}); | ||
const dispose = run(app, {other: driver}); | ||
assert.strictEqual(typeof dispose, 'function'); | ||
@@ -60,5 +59,3 @@ sinon.assert.calledOnce(spy); | ||
it('should support driver that asynchronously subscribes to sink', function( | ||
done, | ||
) { | ||
it('should support driver that asynchronously subscribes to sink', function(done) { | ||
function app(sources: any): any { | ||
@@ -226,3 +223,3 @@ return { | ||
it('should report errors from main() in the console', function(done) { | ||
const sandbox = sinon.sandbox.create(); | ||
const sandbox = sinon.createSandbox(); | ||
sandbox.stub(console, 'error'); | ||
@@ -258,3 +255,3 @@ | ||
console.error as any, | ||
sinon.match((err: any) => err.message === 'malfunction'), | ||
sinon.match((err: any) => err.message === 'malfunction') | ||
); | ||
@@ -277,5 +274,5 @@ | ||
} | ||
let sandbox = sinon.sandbox.create(); | ||
let spy = sandbox.spy(); | ||
window['CyclejsDevTool_startGraphSerializer'] = spy; | ||
const sandbox = sinon.createSandbox(); | ||
const spy = sandbox.spy(); | ||
window.CyclejsDevTool_startGraphSerializer = spy; | ||
@@ -282,0 +279,0 @@ function app(ext: any): any { |
@@ -0,4 +1,5 @@ | ||
// tslint:disable-next-line | ||
import 'mocha'; | ||
import * as assert from 'assert'; | ||
import {setup, Driver} from '../lib/cjs/index'; | ||
import {setup, Driver} from '../src/index'; | ||
import xs, {Stream} from 'xstream'; | ||
@@ -32,3 +33,3 @@ import concat from 'xstream/extra/concat'; | ||
it('should return sinks object and sources object', function() { | ||
function app(ext: any): any { | ||
function app(ext: {other: Stream<string>}) { | ||
return { | ||
@@ -41,3 +42,3 @@ other: ext.other.take(1).startWith('a'), | ||
} | ||
let {sinks, sources} = setup(app, {other: driver}); | ||
const {sinks, sources} = setup(app, {other: driver}); | ||
assert.strictEqual(typeof sinks, 'object'); | ||
@@ -70,7 +71,7 @@ assert.strictEqual(typeof sinks.other.addListener, 'function'); | ||
const stringDriver: Driver<Stream<string>, Stream<string>> = ( | ||
sink: Stream<string>, | ||
sink: Stream<string> | ||
) => xs.of('b'); | ||
const numberWriteOnlyDriver: Driver<Stream<number>, void> = ( | ||
sink: Stream<number>, | ||
sink: Stream<number> | ||
) => {}; | ||
@@ -111,7 +112,7 @@ | ||
const stringDriver: Driver<Stream<string>, Stream<string>> = ( | ||
sink: Stream<string>, | ||
sink: Stream<string> | ||
) => xs.of('b'); | ||
const numberWriteOnlyDriver: Driver<Stream<number>, void> = ( | ||
sink: Stream<number>, | ||
sink: Stream<number> | ||
) => {}; | ||
@@ -159,10 +160,10 @@ | ||
function app(sources: TestSources) { | ||
function app(_sources: TestSources) { | ||
return { | ||
other: concat( | ||
sources.other | ||
_sources.other | ||
.take(6) | ||
.map(x => String(x)) | ||
.map(String) | ||
.startWith('a'), | ||
xs.never(), | ||
xs.never() | ||
), | ||
@@ -184,4 +185,4 @@ }; | ||
}, | ||
error: err => done(err), | ||
complete: () => done(), | ||
error: done, | ||
complete: done, | ||
}); | ||
@@ -196,3 +197,3 @@ dispose = run(); | ||
function app(sources: MySources) { | ||
function app(_sources: MySources) { | ||
return {other: xs.periodic(100).map(i => i + 1)}; | ||
@@ -216,4 +217,4 @@ } | ||
}, | ||
error: err => done(err), | ||
complete: () => done(), | ||
error: done, | ||
complete: done, | ||
}); | ||
@@ -220,0 +221,0 @@ dispose = run(); |
@@ -0,5 +1,6 @@ | ||
// tslint:disable-next-line | ||
import 'mocha'; | ||
import * as assert from 'assert'; | ||
import * as sinon from 'sinon'; | ||
import {setupReusable} from '../lib/cjs/index'; | ||
import {setupReusable} from '../src/index'; | ||
import xs, {Stream} from 'xstream'; | ||
@@ -33,3 +34,3 @@ | ||
} | ||
let {sources, run} = setupReusable({other: driver}); | ||
const {sources, run} = setupReusable({other: driver}); | ||
assert.strictEqual(typeof sources, 'object'); | ||
@@ -43,3 +44,3 @@ assert.notStrictEqual(typeof sources.other, 'undefined'); | ||
it('should return an engine, which we can run and dispose', function() { | ||
let sandbox = sinon.sandbox.create(); | ||
const sandbox = sinon.createSandbox(); | ||
const spy = sandbox.spy(); | ||
@@ -64,5 +65,5 @@ | ||
const engine = setupReusable<NiceSources, NiceSinks>({other: driver}); | ||
const engine = setupReusable({other: driver}); | ||
const sinks = app(engine.sources); | ||
let dispose = engine.run(sinks); | ||
const dispose = engine.run(sinks); | ||
assert.strictEqual(typeof dispose, 'function'); | ||
@@ -74,3 +75,3 @@ sinon.assert.calledOnce(spy); | ||
it('should allow reusing drivers for many apps', function(done) { | ||
let sandbox = sinon.sandbox.create(); | ||
const sandbox = sinon.createSandbox(); | ||
const spy1 = sandbox.spy(); | ||
@@ -104,3 +105,3 @@ const spy2 = sandbox.spy(); | ||
done( | ||
new Error('complete should not be called before engine is before'), | ||
new Error('complete should not be called before engine is before') | ||
); | ||
@@ -112,3 +113,3 @@ }, | ||
const engine = setupReusable<NiceSources, NiceSinks>({other: driver}); | ||
const engine = setupReusable({other: driver}); | ||
@@ -130,3 +131,3 @@ const dispose1 = engine.run(app1(engine.sources)); | ||
it('should allow disposing the engine, stopping reusability', function(done) { | ||
let sandbox = sinon.sandbox.create(); | ||
const sandbox = sinon.createSandbox(); | ||
const spy = sandbox.spy(); | ||
@@ -157,3 +158,3 @@ | ||
const engine = setupReusable<NiceSources, NiceSinks>({other: driver}); | ||
const engine = setupReusable({other: driver}); | ||
@@ -170,3 +171,3 @@ engine.run(app(engine.sources)); | ||
it('should report errors from main() in the console', function(done) { | ||
const sandbox = sinon.sandbox.create(); | ||
const sandbox = sinon.createSandbox(); | ||
sandbox.stub(console, 'error'); | ||
@@ -204,3 +205,3 @@ | ||
console.error as any, | ||
sinon.match((err: any) => err.message === 'malfunction'), | ||
sinon.match((err: any) => err.message === 'malfunction') | ||
); | ||
@@ -207,0 +208,0 @@ |
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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
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
46
1
108310
9
2074
1