本文整理匯總了TypeScript中rxjs/BehaviorSubject.BehaviorSubject.asObservable方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript BehaviorSubject.asObservable方法的具體用法?TypeScript BehaviorSubject.asObservable怎麽用?TypeScript BehaviorSubject.asObservable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rxjs/BehaviorSubject.BehaviorSubject
的用法示例。
在下文中一共展示了BehaviorSubject.asObservable方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('#calculateStandings should do nothing if there aren\'t any players', () => {
const playersSubject = new BehaviorSubject<Player[]>([]);
const fakePlayerService = {
players: playersSubject.asObservable()
};
const submittedPairingsSubject = new BehaviorSubject<Pairing[]>([]);
const fakePairingService = {
submittedPairings: submittedPairingsSubject.asObservable()
};
service = new StandingsService(fakePairingService as PairingService, fakePlayerService as PlayerService);
});
示例2: constructor
constructor(
private dataService: BhmcDataService,
private memberService: MemberService,
private configService: ConfigService,
private errorHandler: BhmcErrorHandler
) {
this.config = this.configService.config;
if (!this._currentUser) {
let storedUser = this.getFromStorage('bhmc_user', true);
if (!storedUser) {
this._currentUser = new User();
this.saveToStorage('bhmc_user', JSON.stringify(this._currentUser)); // session storage
} else {
this._rememberUser = true;
this._currentUser = Object.assign(new User(), JSON.parse(storedUser)); // TODO: IE polyfill
if (this._currentUser.member && this._currentUser.member.birthDate) {
this._currentUser.member.birthDate = moment(this._currentUser.member.birthDate);
}
this.errorHandler.setUserContext(this._currentUser);
}
}
this.currentUserSource = new BehaviorSubject(this._currentUser);
this.currentUser$ = this.currentUserSource.asObservable();
this.dataService.lastError$.subscribe(err => this.onError(err));
}
示例3: getWorkItemList
getWorkItemList(idList: Array<number>) : Observable<WorkItemList> {
let returnValue = new WorkItemList();
let subject = new BehaviorSubject<WorkItemList>(null);
if (idList.length > 0) {
let server = this.window.localStorage.getItem('server');
let workItemUrl = server + '/DefaultCollection/_apis/wit/WorkItems?ids=' + idList.join() + '&fields=System.Id,System.WorkItemType,System.Title,System.AssignedTo,System.State&api-version=1.0';
this.oAuthHttp.get(workItemUrl).subscribe(res => {
let result = res.json();
result.value.forEach(workItemJson => {
let workItem = new WorkItem();
workItem.populate(workItemJson);
returnValue.push(workItem);
});
subject.next(returnValue);
});
}
else {
subject.next(returnValue);
}
return subject.asObservable();
}
示例4: beforeEach
beforeEach(async(() => {
dispatcher = new ListStateDispatcher();
state = new ListState(dispatcher);
/* tslint:disable */
let itemsArray = [
{ id: '1', column1: '30', column2: 'Apple',
column3: 1, column4: moment().add(1, 'minute') },
{ id: '2', column1: '01', column2: 'Banana',
column3: 3, column4: moment().add(6, 'minute') },
{ id: '3', column1: '11', column2: 'Banana',
column3: 11, column4: moment().add(4, 'minute') },
{ id: '4', column1: '12', column2: 'Carrot',
column3: 12, column4: moment().add(2, 'minute') },
{ id: '5', column1: '12', column2: 'Edamame',
column3: 12, column4: moment().add(5, 'minute') },
{ id: '6', column1: null, column2: null,
column3: 20, column4: moment().add(3, 'minute') },
{ id: '7', column1: '22', column2: 'Grape',
column3: 21, column4: moment().add(7, 'minute') }
];
bs = new BehaviorSubject<Array<any>>(itemsArray);
items = bs.asObservable();
TestBed.configureTestingModule({
imports: [
ListFixturesModule,
SkyListModule,
SkyListViewGridModule,
SkyListToolbarModule,
FormsModule
],
providers: [
{ provide: 'items', useValue: items }
]
})
.overrideComponent(SkyListComponent, {
set: {
providers: [
{ provide: ListState, useValue: state },
{ provide: ListStateDispatcher, useValue: dispatcher }
]
}
});
fixture = TestBed.createComponent(ListSelectedTestComponent);
nativeElement = fixture.nativeElement as HTMLElement;
element = fixture.debugElement as DebugElement;
component = fixture.componentInstance;
fixture.detectChanges();
// always skip the first update to ListState, when state is ready
// run detectChanges once more then begin tests
state.skip(1).take(1).subscribe(() => fixture.detectChanges());
fixture.detectChanges();
}));
示例5: getSpinnerSource
private getSpinnerSource(name: string): BehaviorSubject<boolean> {
if (this.sources.has(name)) {
return this.sources.get(name);
}
let subject = new BehaviorSubject(false);
this.sources.set(name, subject);
this.spinners.set(name, subject.asObservable());
return this.sources.get(name);
}
示例6: getSpinner
getSpinner(name: string): any {
if (this.spinners.has(name)) {
return this.spinners.get(name);
}
let subject = new BehaviorSubject(false);
this.sources.set(name, subject);
this.spinners.set(name, subject.asObservable());
return this.spinners.get(name);
}
示例7: readMessagesAsStream
// I read the messages collection as a stream. Returns an Observable stream.
public readMessagesAsStream() : Observable<Message[]> {
// Push messages into the BehaviorSubject. This will ensure that the Subject has
// been primed with data by the time the calling context goes to subscribe to the
// stream. Which will, in turn, ensure that the messages collection is pushed to
// the observer upon subscription.
this.emitMessages();
return( this.subject.asObservable() );
}
示例8: constructor
constructor() {
this.sizes = new Map([
['mobile', 168],
['tablet', 192],
['screen', 256],
]);
const firstDims = this.setDims();
this.listDims = new BehaviorSubject(firstDims);
this.listDimensions$ = this.listDims.asObservable();
this.scrollPos = new BehaviorSubject(0);
this.scrollPosition$ = this.scrollPos.asObservable();
this.scrollTo = new BehaviorSubject(0);
this.scrollSetTo$ = this.scrollTo.asObservable();
}
示例9: it
it('#createPairings should give error with 0 players', () => {
const fakeSubject = new BehaviorSubject<Player[]>([]);
const fakePlayerService = {
activePlayers: fakeSubject.asObservable()
};
pairingService = new PairingService(fakePlayerService as PlayerService);
const createPairings = function() {
pairingService.createPairings(1, false);
};
expect(createPairings).toThrowError(Error);
});