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