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