當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript rx.Subject類代碼示例

本文整理匯總了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);
}
開發者ID:duncanmak,項目名稱:experiments,代碼行數:8,代碼來源:model.ts

示例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]);
        });
開發者ID:lazyoft,項目名稱:ninjagoat,代碼行數:11,代碼來源:ObservableFactorySpec.ts

示例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
}
開發者ID:hungdluit,項目名稱:luxor,代碼行數:14,代碼來源:action.ts

示例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
}
開發者ID:hungdluit,項目名稱:luxor,代碼行數:15,代碼來源:action.ts

示例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();
    });
開發者ID:guardian,項目名稱:video-dashboard,代碼行數:7,代碼來源:app.ts

示例6: function

 request<any>(options, function(err, response) {
   if(err) {
     observable.onError(err);
   } else {
     observable.onNext(response.body);        
   }
 })
開發者ID:dghijben,項目名稱:dashboard,代碼行數:7,代碼來源:Api.ts

示例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}`);
			}
		});
開發者ID:omochi,項目名稱:national-economy,代碼行數:9,代碼來源:SocketImpl.ts

示例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)
開發者ID:christyharagan,項目名稱:uservices-socket.io-server,代碼行數:9,代碼來源:remoteProxy.ts


注:本文中的rx.Subject類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。