当前位置: 首页>>代码示例>>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;未经允许,请勿转载。