本文整理汇总了TypeScript中@cycle/rxjs-run.run函数的典型用法代码示例。如果您正苦于以下问题:TypeScript run函数的具体用法?TypeScript run怎么用?TypeScript run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: it
it('should allow effect to see one or many HTML outputs', function (done) {
function app() {
return {
html: Rx.Observable.interval(150).take(3).map(i =>
div('.test-element', ['Foobar' + i]),
),
};
}
const expected = [
'<div class="test-element">Foobar0</div>',
'<div class="test-element">Foobar1</div>',
'<div class="test-element">Foobar2</div>',
];
function effect(html: string): void {
assert.strictEqual(html, expected.shift());
if (expected.length === 0) {
done();
}
}
run(app, {
html: makeHTMLDriver(effect),
});
});
示例2: it
it('should allow going back a route with type `go`', done => {
function main(sources: {history: Observable<Location>}) {
return {
history: Observable.of<HistoryInput | string>('/test', '/other', {
type: 'go',
amount: -1,
}),
};
}
const {sources, run} = setup(main, {
history: makeServerHistoryDriver(),
});
const expected = ['/test', '/other', '/test'];
sources.history.skip(1).subscribe({
next(location: Location) {
assert.strictEqual(location.pathname, expected.shift());
if (expected.length === 0) {
done();
}
},
error: done,
complete: () => {
done('complete should not be called');
},
});
run();
});
示例3: setTimeout
setTimeout(() => {
assert.strictEqual(expectedDOMSinks.length, 4);
// DOM then HTTP:
Cycle.run(mainDOMThenHTTP, {
HTTP: makeHTTPDriver(),
DOM: domDriver,
});
setTimeout(() => {
assert.strictEqual(expectedDOMSinks.length, 0);
done();
}, 4000);
}, 4000);
示例4: it
it('should create a location from ReplaceHistoryInput', (done) => {
function main(sources: {history: Observable<Location>}) {
return {
history: Observable.of({type: 'replace', pathname: '/test'}),
};
}
const {sources, run} = setup(main, { history: makeServerHistoryDriver() });
sources.history.skip(1).subscribe({
next (location: Location) {
assert.strictEqual(location.pathname, '/test');
done();
},
error: done,
complete: () => { done('complete should not be called'); },
});
run();
});
示例5: main
it('should not remember past responses when selecting', function(done) {
this.timeout(4000);
function main(_sources: any) {
const test$ = of(null).pipe(
delay(1000),
mergeMap(() =>
_sources.HTTP.select('cat').pipe(
mergeAll(),
map((res: any) => 'I should not show this, ' + res.text)
)
)
);
const request$ = of({
category: 'cat',
url: uri + '/hello',
});
return {
HTTP: request$,
Test: test$,
};
}
function testDriver(sink: any) {
sink.addListener({
next: (s: any) => {
console.log(s);
done('No data should come through the Test sink');
},
error: (err: any) => {
done(err);
},
});
}
globalRun(main, {
HTTP: makeHTTPDriver(),
Test: testDriver,
});
setTimeout(() => {
done();
}, 2000);
});