UNPKG

@motorcycle/test

Version:
61 lines 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var stream_1 = require("@motorcycle/stream"); var sinks_1 = require("./sinks"); var disposeSources_1 = require("./disposeSources"); /** * This is nearly identical to the `run` found inside of `@motorcycle/run`. The * only difference is that it makes use of the test scheduler to create the * application's event loop. An additional property is returned with the `tick` * that allows you to control how time progresses. * * @name run<Sources, Sinks>(Main: Component<Sources, Sinks>, IO: IOComponent<Sinks, Sources>) * @example * import { run } from '@motorcycle/test' * import { makeDomComponent, div, button, h2, query, clickEvent } from '@motorcycle/dom' * * function Main(sources) { * const { dom } = sources * * const click$ = clickEvent(query('button', dom)) * * const count$ = scan(x => x + 1, click$) * * const view$ = map(view, count$) * * return { view$ } * } * * function view(count: number) { * return div([ * h2(`Clicked ${count} times`), * button('Click Me'), * ]) * } * * const Dom = fakeDomComponent({ * 'button': { * click: now(fakeEvent()) * } * }) * * const { tick, dispose } = run(UI, Dom) * * tick(500).then(dispose) */ function run(Main, IO) { var endSignal = stream_1.createProxy().stream; var sinkProxies = {}; var proxySinks = sinks_1.createProxySinks(sinkProxies, endSignal); var sources = IO(proxySinks); var sinks = sinks_1.createDisposableSinks(Main(sources), endSignal); var _a = sinks_1.replicateSinks(sinks, sinkProxies), disposable = _a.disposable, tick = _a.tick; function dispose() { endSignal.event(stream_1.scheduler.currentTime(), void 0); disposable.dispose(); disposeSources_1.disposeSources(sources); } return { sinks: sinks, sources: sources, dispose: dispose, tick: tick }; } exports.run = run; //# sourceMappingURL=run.js.map