@cycle/run
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -0,1 +1,21 @@ | ||
<a name="3.0.0"></a> | ||
# 3.0.0 (2017-03-05) | ||
### Bug Fixes | ||
* **run:** check for matching stream types of sinks and drivers ([4b4094c](https://github.com/cyclejs/cyclejs/tree/master/run/commit/4b4094c)) | ||
* **run:** reintroduce Driver function TS type ([1ad62cb](https://github.com/cyclejs/cyclejs/tree/master/run/commit/1ad62cb)) | ||
### BREAKING CHANGES | ||
* run: If you are using JavaScript, literally nothing changes. If you are using TypeScript, this version | ||
may detect more errors than before, and may break (by not compiling) your existing code if your | ||
existing code happened to have a sneaky bug. | ||
ISSUES CLOSED: 541 | ||
<a name="2.0.0"></a> | ||
@@ -2,0 +22,0 @@ # 2.0.0 (2017-03-05) |
@@ -17,4 +17,7 @@ import { MemoryStream } from 'xstream'; | ||
} | ||
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)]: (stream: FantasyObservable, driverName: string) => any; | ||
[P in keyof (So & Si)]: Driver<Si[P], So[P]>; | ||
}; | ||
@@ -21,0 +24,0 @@ export declare type Sources = { |
{ | ||
"name": "@cycle/run", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "The Cycle.js run() function to use with xstream", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -24,4 +24,8 @@ import xs, {Stream, MemoryStream} from 'xstream'; | ||
export interface Driver<Sink, Source> { | ||
(stream: Sink, driverName?: string): Source; | ||
} | ||
export type Drivers<So extends Sources, Si extends Sinks> = { | ||
[P in keyof (So & Si)]: (stream: FantasyObservable, driverName: string) => any; | ||
[P in keyof (So & Si)]: Driver<Si[P], So[P]>; | ||
}; | ||
@@ -228,4 +232,4 @@ | ||
const sinkProxies = makeSinkProxies(drivers); | ||
const sources = callDrivers(drivers, sinkProxies); | ||
const sinkProxies = makeSinkProxies<So, Si>(drivers); | ||
const sources = callDrivers<So, Si>(drivers, sinkProxies); | ||
const adaptedSources = adaptSources(sources); | ||
@@ -232,0 +236,0 @@ const sinks = main(adaptedSources); |
import 'mocha'; | ||
import * as assert from 'assert'; | ||
import * as sinon from 'sinon'; | ||
import {run, setup} from '../lib'; | ||
import {run, setup, Sources, Sinks, Driver} from '../lib'; | ||
import {setAdapt} from '../lib/adapt'; | ||
@@ -58,13 +58,60 @@ import xs, {Stream} from 'xstream'; | ||
it('should type-check keyof sources and sinks in main and drivers', function () { | ||
function app(ext: {other: Stream<string>}) { | ||
type Sources = { | ||
str: Stream<string>; | ||
obj: Stream<object>; | ||
}; | ||
function app(sources: Sources) { | ||
return { | ||
other: ext.other.take(1).startWith('a'), | ||
str: sources.str.take(1).startWith('a'), // good | ||
// str: sources.obj.mapTo('good'), // good | ||
// strTYPO: sources.str.take(1).startWith('a'), // bad | ||
// str: xs.of(123), // bad | ||
num: xs.of(100), // good | ||
// numTYPO: xs.of(100), // bad | ||
// num: xs.of('BAD TYPE'), // bad | ||
}; | ||
} | ||
function driver() { | ||
const stringDriver: Driver<Stream<string>, Stream<string>> = | ||
(sink: Stream<string>) => xs.of('b'); | ||
const numberWriteOnlyDriver: Driver<Stream<number>, void> = | ||
(sink: Stream<number>) => {}; | ||
const objectReadOnlyDriver: Driver<void, Stream<object>> = | ||
() => xs.of({}); | ||
setup(app, { | ||
str: stringDriver, | ||
num: numberWriteOnlyDriver, | ||
obj: objectReadOnlyDriver, | ||
}); | ||
}); | ||
it('should type-check and allow more drivers than sinks', function () { | ||
type Sources = { | ||
str: Stream<string>; | ||
num: Stream<number>; | ||
obj: Stream<object>; | ||
}; | ||
function app(sources: Sources) { | ||
return { | ||
}; | ||
} | ||
function stringDriver(sink: Stream<string>) { | ||
return xs.of('b'); | ||
} | ||
setup(app, {other: driver}); | ||
const numberDriver = (sink: Stream<number>) => xs.of(100); | ||
const objectReadOnlyDriver = () => xs.of({}); | ||
setup(app, { | ||
str: stringDriver, | ||
num: numberDriver, | ||
obj: objectReadOnlyDriver, | ||
}); | ||
}); | ||
@@ -71,0 +118,0 @@ |
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
57095
1137