本文整理汇总了TypeScript中xstream.periodic函数的典型用法代码示例。如果您正苦于以下问题:TypeScript periodic函数的具体用法?TypeScript periodic怎么用?TypeScript periodic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了periodic函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test
test('xstream: proxy$ should stop emitting when proxied$ unsubscribed', (t) => {
let target$ = xs.periodic(0)
let proxy$ = proxy()
let proxied$ = proxy$.proxy(target$)
let emitted = 0
proxy$.addListener({
next: () => {
emitted++
},
error: () => { },
complete: () => { }
})
let listener = {
next: () => {
if (emitted === 2) {
proxied$.removeListener(listener)
}
},
error: () => { },
complete: () => { }
}
proxied$.addListener(listener)
// target may still be subscribed
target$.addListener(emptyListener)
setTimeout(() => {
t.equal(emitted, 3)
t.end()
}, 50)
})
示例2: child
function child(sources: {DOM: MainDOMSource}) {
const visible$ = xs.periodic(50).take(1).fold((acc, _) => !acc, true);
const vdom$ = visible$.map(visible => (visible ? h4('child') : null));
return {
DOM: vdom$,
};
}
示例3: app
function app() {
return {
html: xs
.periodic(150)
.take(3)
.map(i => div('.test-element', ['Foobar' + i])),
};
}
示例4: main
function main(sources: {DOM: MainDOMSource}) {
const child = isolate(Child, 'child')(sources);
// change parent key, causing it to be recreated
const x$ = xs.periodic(120).map(x => x + 1).startWith(0).take(4);
const innerDOM$ = xs.combine(x$, child.DOM)
.map(([x, childVDOM]) =>
div(`.parent${x}`, {key: `key${x}`}, [childVDOM, `${x}`]),
);
return {
DOM: innerDOM$,
};
}
示例5: main
function main(sources: {history: Stream<Location>}) {
return {
history: xs.periodic(100).take(6).map(i => [
'/test',
'/other',
{type: 'go', amount: -1},
{type: 'go', amount: +1},
{type: 'goBack'},
{type: 'goForward'},
][i]),
};
}
示例6: mainDOMThenHTTP
function mainDOMThenHTTP(sources: any) {
const sinks$ = xs
.periodic(100)
.take(6)
.map(i => {
if (i % 2 === 1) {
return child(sources, i);
} else {
return {
HTTP: xs.empty(),
DOM: xs.of(''),
};
}
});
// order of sinks is important to reproduce the bug
return {
DOM: sinks$.map(sinks => sinks.DOM).flatten(),
HTTP: sinks$.map(sinks => sinks.HTTP).flatten(),
};
}
示例7: app
function app(sources: MySources) {
return {other: xs.periodic(100).map(i => i + 1)};
}
示例8: main
function main() {
const sinks = {
DOM: xs.periodic(1000).map(i => h1('' + i + " seconds elapsed"))
};
return sinks;
}