本文整理匯總了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);
});