我无法在地面使用RxJS获得最小的Angular 2应用程序.我正在使用Typescript(tsc 1.6.2)和systemjs进行模块加载.如何让systemjs正确加载Rx模块?我已经没有想法尝试,我会欣赏任何指向我做错的指针.模块加载对我来说有点神奇.很沮丧.
index.html:
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<script src="../node_modules/es6-shim/es6-shim.js"></script>
<script src="../node_modules/systemjs/dist/system.src.js"></script>
<script src="../node_modules/rx/dist/rx.lite.js"></script>
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
</head>
<body>
<app>App loading...</app>
<script>
System.config({
packages: { 'app': { defaultExtension: 'js' } }
});
System.import('app/app');
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
app.ts:
/// <reference path="../../node_modules/rx/ts/rx.all.d.ts" />
import { bootstrap, Component, View } from 'angular2/angular2';
import * as Rx from 'rx';
@Component({
selector: 'app'
})
@View({
template: `Rx Test`
})
export class App {
subject: Rx.Subject<any> = new Rx.Subject<any>();
}
bootstrap(App);
Run Code Online (Sandbox Code Playgroud)
SystemJS尝试加载不存在的文件:
一旦我在上面的代码中注释掉主题 …
是否可以对一段时间内的事件进行计数并在 RxJS 中每秒产生一次总和?我有一个连续的永无止境的事件流。每 1 秒我想获得过去 5 分钟窗口中的事件总数。这个想法是使用它来填充实时图形。
我知道如何以传统方式做到这一点,但真的很想了解它是如何通过反应式编程完成的。