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


TypeScript Subject.subscribe方法代碼示例

本文整理匯總了TypeScript中rxjs.Subject.subscribe方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Subject.subscribe方法的具體用法?TypeScript Subject.subscribe怎麽用?TypeScript Subject.subscribe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rxjs.Subject的用法示例。


在下文中一共展示了Subject.subscribe方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

  it("should translate Observable implementation not from RxJS into RxJS Observables", (done) => {
  /* tslint:enable:max-line-length */

    const sub1 = new Subject<number>();
    const sub2 = new Subject<number>();
    const myObs1 = {
      subscribe(a : () => void, b : () => void, c : () => {}) {
        sub1.subscribe(a, b, c);
        return null;
      },
    };
    const myObs2 = {
      subscribe(a : () => void, b : () => void, c : () => {}) {
        sub2.subscribe(a, b, c);
        return null;
      },
    };

    const rxObs1 = castToObservable(myObs1);
    const rxObs2 = castToObservable(myObs2);
    let itemFromObs1 = 0;
    let itemFromObs2 = 0;
    rxObs1.subscribe(
      (num) => {
        switch (itemFromObs1++) {
          case 0:
            expect(num).toBe(1);
            break;
          case 1:
            expect(num).toBe(12);
            break;
          case 2:
            expect(num).toBe(5);
            break;
          default:
            throw new Error("Invalid item received");
        }
      },

      (err : Error) => {
        expect(err.message).toBe("ffob");
        expect(itemFromObs1).toBe(3);
        rxObs2.subscribe(
          () => { itemFromObs2++; },
          noop,
          () => {
            expect(itemFromObs2).toBe(0);
            done();
          }
        );
      }
    );
    sub1.next(1);
    sub1.next(12);
    sub1.next(5);
    sub2.complete();
    sub1.error(new Error("ffob"));
  });
開發者ID:canalplus,項目名稱:rx-player,代碼行數:58,代碼來源:cast_to_observable.test.ts

示例2: it

 it('should create a request command with message-id', () => {
   service.connect();
   mockObs.subscribe(value => {
     expect(value).toEqual({ 'message-id': '2', 'request-type': 'test' });
   });
   service.requestCommand(service.requestTask('test'));
 });
開發者ID:chgc,項目名稱:stream-tools,代碼行數:7,代碼來源:obs.service.spec.ts

示例3: Subscription

export const initWorker = (provisioning: Provisioning) => {
  const subject = new Subject<WorkerPayload>();
  const subscription = new Subscription();

  const post = process.env.RMVI_TEST
    ? ({ type, payload }: { type: string; payload: any }) => {
        global['RECEIVE_WORKER_MESSAGE']({ type, payload });
      }
    : typeof postMessage === 'function'
      ? ({ type, payload }: { type: string; payload: any }) => {
          postMessage({ type, payload });
        }
      : () => {};

  if (typeof Worker === 'function') {
    onmessage = e => {
      const { data } = e;
      subject.next(data);
    };
  }

  const publisher = provisioning.getPublisher();
  subscription.add(
    subject.subscribe(({ type, payload }) => {
      switch (type) {
        case WorkerReceiveEventType.DISPATCH:
          publisher(payload.type, payload.payload);
          provisioning.emitAsync(() =>
            post({ type: WorkerPostEventType.DISPATCHED, payload }),
          );
          break;
        case WorkerReceiveEventType.INITIALIZE:
          provisioning.prepare(payload);
          provisioning.subscribe((state, isInitial) => {
            if (isInitial) {
              post({
                type: WorkerPostEventType.INITIALIZED,
                payload: state.view,
              });
            } else {
              post({ type: WorkerPostEventType.UPDATE, payload: state.view });
            }
          }, true);
          break;
        case WorkerReceiveEventType.EXIT:
          publisher.unsubscribe();
          provisioning.dispose();
          subscription.unsubscribe();
          break;
        default:
          return;
      }
    }),
  );

  return subject;
};
開發者ID:brn,項目名稱:react-mvi,代碼行數:57,代碼來源:worker.ts

示例4: constructor

    constructor(cookie: CookieDriver, signoutAction: Subject<void>) {
        this._cookie = cookie;

        const disposer = new Subscription();
        this._disposer = disposer;

        disposer.add(signoutAction.subscribe(() => {
            this.removeToken();
        }));
    }
開發者ID:karen-irc,項目名稱:karen,代碼行數:10,代碼來源:AuthRepository.ts

示例5: subject

 subject() {
     let subject$ = new Subject();
     interval(300).pipe(
         take(5)
     ).subscribe(subject$); // Now subject behaves as observable
     // Every time the interval send values to the Subject, the Subject send this values to all his observers
     subject$.subscribe(val => console.log(`First subject: ${val}`)); // 0, 1, 2, 3, 4
     setTimeout(() => {
         subject$.subscribe(val => console.log(`Second subject: ${val}`)) // 3, 4
     }, 1000);
 }
開發者ID:mr-Deviant,項目名稱:sandbox,代碼行數:11,代碼來源:subjects.component.ts

示例6: ngOnInit

    public ngOnInit(): void {
        this.addBlock$.subscribe(block => {
            this.editor.runCommand(
                insertImage({
                    src: "https://media.giphy.com/media/sIIhZliB2McAo/giphy.gif",
                }),
            )
        })

        this.editor.updateState(this.doc)
        this.editor.stateChange.subscribe(this.save)
    }
開發者ID:zodiac-team,項目名稱:zodiac-ui,代碼行數:12,代碼來源:designer.component.ts

示例7: Observable

 return new Observable(observer => {
     subject.subscribe(observer).add(() => {
         if (
             !isUnsubscribed() &&
             responseObserver &&
             !responseObserver.complete &&
             !responseObserver.observer.closed
         ) {
             sendNotification(ABORT_REQUEST_METHOD, [id])
         }
     })
 })
開發者ID:JoYiRis,項目名稱:sourcegraph,代碼行數:12,代碼來源:connection.ts

示例8: constructor

    protected constructor(config: DynamicFormValueControlModelConfig<T>, layout?: DynamicFormControlLayout) {

        super(config, layout);

        this.additional = typeof config.additional === "object" && config.additional !== null ? config.additional : null;
        this.hint = config.hint || null;
        this.required = typeof config.required === "boolean" ? config.required : false;
        this.tabIndex = config.tabIndex || null;

        this.value = config.value !== null && config.value !== undefined ? config.value : null;
        this.valueUpdates = new Subject<T>();
        this.valueUpdates.subscribe((value: T) => this.value = value);
    }
開發者ID:thanhdevapp,項目名稱:ng-dynamic-forms,代碼行數:13,代碼來源:dynamic-form-value-control.model.ts

示例9: test

  test('Handle bowlingLine with Delete', function() {
    const  testDeleter = { type: 'DELETE', payload: 7 };
    function mockMakeBowlingLine(id, name) {
      return {DOM: O.of(div()), Delete: O.of(testDeleter)};
    }
    const mockLineAction$ = new Subject();
    mockLineAction$.subscribe(
      x => expect(x).toEqual(testDeleter)
    );

    model(O.from([
      {type: 'ADD ITEM', payload: 'Andrew'}
    ]), mockMakeBowlingLine, mockLineAction$);
  });
開發者ID:wizardwerdna,項目名稱:FRPBowlingKata,代碼行數:14,代碼來源:model.spec.ts

示例10: openLogin

    /**
     * Opens a dialog to choose a file to upload.
     * @param actionName Name of the action to show in the title
     * @param title Title for the dialog
     * @returns Information about the chosen file(s)
     */
    openLogin(actionName: string, title: string): Observable<string> {
        const logged = new Subject<string>();
        logged.subscribe({
            complete: this.close.bind(this)
        });

        const data: LoginDialogComponentData = {
            title,
            actionName,
            logged
        };

        this.openLoginDialog(data, 'adf-login-dialog', '630px');
        return logged;
    }
開發者ID:Alfresco,項目名稱:alfresco-ng2-components,代碼行數:21,代碼來源:login-dialog.service.ts


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