本文整理汇总了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();
});
示例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);
})
);
});
示例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$];
}
示例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();
}
示例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();
}
示例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();
});
示例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();
});
示例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,
});
}
示例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();
}));
示例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;
});