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


TypeScript Subject.asObservable方法代碼示例

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


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

示例1: beforeEach

  beforeEach(() => {
    service = jasmine.createSpyObj<SpreadsheetService>('SpreadsheetService', ['getCellUpdates', 'updateCellValue', 'evaluate']);
    service.getCellUpdates.and.returnValue(update$.asObservable());

    component = new CellComponent(service as SpreadsheetService);
    component.ngOnInit();
  });
開發者ID:cvuorinen,項目名稱:angular2-excel,代碼行數:7,代碼來源:cell.component.spec.ts

示例2: describe

describe('TaskManagerService', () => {
  let taskManagerService: TaskManagerService;
  let called: boolean;

  const summaryDataSource = new Subject();
  const fakeService = {
    summaryData$: summaryDataSource.asObservable()
  };

  const summary = {
    executing_tasks: [],
    health_status: 'HEALTH_OK',
    mgr_id: 'x',
    rbd_mirroring: { errors: 0, warnings: 0 },
    rbd_pools: [],
    have_mon_connection: true,
    finished_tasks: [{ name: 'foo', metadata: {} }],
    filesystems: [{ id: 1, name: 'cephfs_a' }]
  };

  configureTestBed({
    providers: [TaskManagerService, { provide: SummaryService, useValue: fakeService }]
  }, true);

  beforeEach(() => {
    taskManagerService = TestBed.get(TaskManagerService);
    called = false;
    taskManagerService.subscribe('foo', {}, () => (called = true));
  });

  it('should be created', () => {
    expect(taskManagerService).toBeTruthy();
  });

  it(
    'should subscribe and be notified when task is finished',
    fakeAsync(() => {
      expect(taskManagerService.subscriptions.length).toBe(1);
      summaryDataSource.next(summary);
      tick();
      expect(called).toEqual(true);
      expect(taskManagerService.subscriptions).toEqual([]);
    })
  );

  it(
    'should subscribe and process executing taks',
    fakeAsync(() => {
      const original_subscriptions = _.cloneDeep(taskManagerService.subscriptions);
      _.assign(summary, {
        executing_tasks: [{ name: 'foo', metadata: {} }],
        finished_tasks: []
      });
      summaryDataSource.next(summary);
      tick();
      expect(taskManagerService.subscriptions).toEqual(original_subscriptions);
    })
  );
});
開發者ID:fghaas,項目名稱:ceph,代碼行數:59,代碼來源:task-manager.service.spec.ts

示例3:

export function splitSubject<T>(
  subj: Subject<T> = new Subject<T>()): [Observer<T>, Observable<T>] {

  const emitter = subj as Observer<T>;
  const stream$ = subj.asObservable();

  return [emitter, stream$];
}
開發者ID:BrainCrumbz,項目名稱:ng2-autocomplete-words-example,代碼行數:8,代碼來源:rx-utils.ts

示例4:

export function addEventObserver<T>(type: string): Observable<T> {
    if (observers.has(type)) {
        const subject = observers.get(type) as Subject<T>;
        return subject.asObservable();
    }
    const subject = new Subject<T>();
    observers.set(type, subject);
    return subject.asObservable();
}
開發者ID:chevtche,項目名稱:Brayns,代碼行數:9,代碼來源:pubsub.ts

示例5: constructor

  /**
   * @param tree The node which contains the tree to update.
   */
  constructor(protected readonly tree: Element | Document) {
    const root = findRoot(tree);
    if (root === undefined) {
      throw new Error("the tree must have a DLocRoot");
    }

    this.dlocRoot = root;
    this._events = new Subject();

    this.events = this._events.asObservable();
  }
開發者ID:lddubeau,項目名稱:wed,代碼行數:14,代碼來源:tree-updater.ts

示例6: it

        it('should call set theme update when form control value changes.', () => {
            const setTheme = new Subject<any>();
            const callback = jasmine.createSpy('callback');
            const subscription = setTheme.asObservable().subscribe(callback);

            (theme as any).setTheme = setTheme;

            fixture.detectChanges();

            const buttonToggle = getThemeButtonToggles().find(toggle => toggle.value === Themes.BASIC_LIGHT_THEME);
            buttonToggle._onButtonClick();

            expect(callback).toHaveBeenCalledWith(Themes.BASIC_LIGHT_THEME);
            subscription.unsubscribe();
        });
開發者ID:suiruiw,項目名稱:geeks-diary,代碼行數:15,代碼來源:general-settings.component.spec.ts

示例7: beforeEach

    beforeEach(() => {
        store = TestBed.get(Store);
        editorViewModeMenu = TestBed.get(NoteEditorViewModeMenu);
        menu = TestBed.get(MenuService);
        mockDialog = TestBed.get(Dialog);
        collection = TestBed.get(NoteCollectionService);

        spyOn(store, 'dispatch').and.callThrough();
        spyOn(menu, 'onMessage').and.callFake(() => menuStream.asObservable());
        collection.provideVcsFileChanges(vcsFileChangesStream.asObservable());

        fixture = TestBed.createComponent(NoteHeaderComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
    });
開發者ID:suiruiw,項目名稱:geeks-diary,代碼行數:15,代碼來源:note-header.component.spec.ts

示例8: constructor

  constructor(params: Params) {
    const {
      rootDomElement,
      browserSupportsCsp,
      injectedMetadata,
      requireLegacyFiles,
      useLegacyTestHarness,
    } = params;

    this.rootDomElement = rootDomElement;

    this.i18n = new I18nService();

    this.capabilities = new CapabilitiesService();

    this.injectedMetadata = new InjectedMetadataService({
      injectedMetadata,
    });

    this.fatalErrors = new FatalErrorsService({
      rootDomElement,
      injectedMetadata: this.injectedMetadata,
      stopCoreSystem: () => {
        this.stop();
      },
    });

    this.notificationsTargetDomElement$ = new Subject();
    this.notifications = new NotificationsService({
      targetDomElement$: this.notificationsTargetDomElement$.asObservable(),
    });
    this.http = new HttpService();
    this.basePath = new BasePathService();
    this.uiSettings = new UiSettingsService();
    this.overlayTargetDomElement = document.createElement('div');
    this.overlay = new OverlayService(this.overlayTargetDomElement);
    this.chrome = new ChromeService({ browserSupportsCsp });

    const core: CoreContext = {};
    this.plugins = new PluginsService(core);

    this.legacyPlatformTargetDomElement = document.createElement('div');
    this.legacyPlatform = new LegacyPlatformService({
      targetDomElement: this.legacyPlatformTargetDomElement,
      requireLegacyFiles,
      useLegacyTestHarness,
    });
  }
開發者ID:spalger,項目名稱:kibana,代碼行數:48,代碼來源:core_system.ts

示例9: beforeEach

  beforeEach(async(() => {
    events$ = new Subject<RouterEvent>();

    const fakeRouter = {
      events: events$.asObservable()
    } as Router;

    TestBed.configureTestingModule({
      declarations: [ NavigationProgressComponent ],
      imports: [ GlobeNgbModule.forRoot() ],
      providers: [
        { provide: Router, useValue: fakeRouter }
      ]
    });

    tester = new NavigationProgressComponentTester();
    tester.detectChanges();
  }));
開發者ID:Ninja-Squad,項目名稱:globe42,代碼行數:18,代碼來源:navigation-progress.component.spec.ts

示例10: beforeEach

    beforeEach(() => {
        store = TestBed.get(Store);
        listManager = TestBed.get(NoteSnippetListManager);
        mockDialog = TestBed.get(Dialog);
        nativeDialog = TestBed.get(NativeDialog);
        noteEditor = TestBed.get(NoteEditorService);
        stackViewer = TestBed.get(StackViewer);

        menuMessages = new Subject<MenuEvent>();
        selectedNoteStream = new ReplaySubject<NoteItem>(1);

        (menu.onMessage as Spy).and.returnValue(menuMessages.asObservable());
        spyOn(listManager, 'handleSnippetRefEvent').and.callThrough();
        (collection.getSelectedNote as Spy).and.callFake(() => selectedNoteStream.asObservable());

        fixture = TestBed.createComponent(NoteEditorComponent);
        component = fixture.componentInstance;
    });
開發者ID:suiruiw,項目名稱:geeks-diary,代碼行數:18,代碼來源:note-editor.component.spec.ts


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