本文整理汇总了TypeScript中rx.Subject类的典型用法代码示例。如果您正苦于以下问题:TypeScript Subject类的具体用法?TypeScript Subject怎么用?TypeScript Subject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Subject类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: model
export function model(action$: Rx.Observable<Action>, initialState: any) {
let state$ = new Subject();
action$
//.scan(initialState, (state: any, actions: Action[]) => actions.reduce((s, action) => action.update(s), state))
.scan(initialState, (s, action) => action.update(s))
.subscribe(state$);
return state$.startWith(initialState);
}
示例2: it
it("should construct the right observable", () => {
let dataSubject = new Rx.Subject<number>();
dataSubject.subscribe(data => dataEmitted.push(data));
subject.register<number>("Foo", parameters => {
dataSubject.onNext(parameters.counter);
return dataSubject;
});
subject.get<number>("Foo", { counter: 20 });
expect(dataEmitted).to.eql([20]);
});
示例3: oldFn
export function action < T extends Function, Return > (target: T & ICallable<Return>): T & ICallable<Return> & IAction<Return> {
var oldFn = target
var rx_action = new Rx.Subject<Return>()
var newFn = (function (...args) {
var retval = oldFn(...args)
rx_action.onNext(retval)
return retval
} as any) as T & ICallable<Return> & IAction<Return>
newFn.rx_action = rx_action.asObservable()
return newFn
}
示例4: return
export function asyncAction < T extends Function, Return > (target: T & ICallable<Promise<Return>>): T & ICallable<Promise<Return>> & IAction<Return> {
var oldFn = target
var rx_action = new Rx.Subject<Return>()
var newFn = (function (...args) {
return (oldFn(...args) as any).then(val => {
rx_action.onNext(val as any)
return val
})
} as any) as T & ICallable<Promise<Return>> & IAction<Return>
newFn.rx_action = rx_action.asObservable()
return newFn
}
示例5: addMediaEvents
const sub$ = Rx.Observable.combineLatest(...days).subscribe(data => {
const totals = addMediaEvents(data.map(d => d.mediaEvent));
data$.onNext(data);
totals$.onNext(totals);
sub$.dispose();
});
示例6: function
request<any>(options, function(err, response) {
if(err) {
observable.onError(err);
} else {
observable.onNext(response.body);
}
})
示例7: Error
connection.on("message", (message: WebSocketMessage) => {
if (message.type == "utf8") {
this.onMessage_.onNext({ string: message.utf8Data });
} else if (message.type == "binary") {
this.onMessage_.onNext({ data: bufferToData(message.binaryData) });
} else {
throw new Error(`invalid message ${message.type}`);
}
});
示例8: function
socket.on(name + id, function([value, error, completed]) {
if (completed) {
observer.onCompleted()
} else if (error) {
observer.onError(error)
} else {
observer.onNext(value)
}
}).emit(name + id, true)