本文整理匯總了TypeScript中rxjs/BehaviorSubject.BehaviorSubject類的典型用法代碼示例。如果您正苦於以下問題:TypeScript BehaviorSubject類的具體用法?TypeScript BehaviorSubject怎麽用?TypeScript BehaviorSubject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了BehaviorSubject類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
export default function(options: CanvasOptions) {
const write = new Subject<DragDeltaLog>();
const clear = new Subject<any>();
const scale = new BehaviorSubject<any>(true);
const toggle = new Subject<any>();
const canvas = options.canvasElement as HTMLCanvasElement;
const context = canvas.getContext("2d");
if (context === null) {
throw new TypeError('unreachable: canvas should be not `null`');
}
write.subscribe(writeCanvasTo(context, options.color));
clear.subscribe(clearCanvasTo(context));
scale
.map(() => window.innerWidth)
.subscribe(attributeAssignOf(canvas, 'width'));
scale
.map(() => window.innerHeight)
.subscribe(attributeAssignOf(canvas, 'height'));
toggle
.scan((acc) => !acc, false)
.map((bool) => bool ? 'false' : 'true')
.subscribe(attributeAssignOf(canvas, 'aria-hidden'));
return {
cvWrite : write,
cvClear : clear,
cvToggle : toggle,
cvScale : scale
};
}
示例2: beforeEach
beforeEach(() => {
addProviders([
{ provide: Platform, useClass: MockClass },
{ provide: Http, useClass: HttpMock },
{ provide: NavController, useClass: NavMock },
{ provide: DataService, useClass: MockDataService },
]);
platform = new MockClass();
navMock = new NavMock();
window.localStorage.setItem('project_data', JSON.stringify(platform.getData()));
data = platform.getData();
var _data = JSON.stringify(data);
//Set Initial State
window.localStorage.setItem('project_data', _data);
window.localStorage.setItem('project_id', '5');
observable = new BehaviorSubject(data);
observable.next(data);
dataService = new DataService(httpMock);
spyOn(dataService, 'fetchData').and.returnValue(observable);
chart = new Chart(dataService);
netattraction = new Netattraction();
});
示例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: it
it('should handle dynamic queries that return empty sets', async (done) => {
const ITEMS = 10;
let count = 0;
let firstIndex = 0;
let pricefilter$ = new BehaviorSubject<number|null>(null);
const randomCollectionName = randomName(afs.firestore);
const ref = afs.firestore.collection(`${randomCollectionName}`);
let names = await createRandomStocks(afs.firestore, ref, ITEMS);
const sub = pricefilter$.switchMap(price => {
return afs.collection(randomCollectionName, ref => price ? ref.where('price', '==', price) : ref).valueChanges()
}).subscribe(data => {
count = count + 1;
// the first time should all be 'added'
if(count === 1) {
expect(data.length).toEqual(ITEMS);
pricefilter$.next(-1);
}
// on the second round, we should have filtered out everything
if(count === 2) {
expect(data.length).toEqual(0);
sub.unsubscribe();
deleteThemAll(names, ref).then(done).catch(done.fail);
}
});
});
示例5: 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();
}));
示例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: 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);
}
示例8: 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);
});
示例9:
this.textInput.valueChanges.debounceTime(500).subscribe((value)=>{
if(this._validate(value)) {
this.textInput.setValue(value);
this.value.next(value);
} else {
this.textInput.setValue(this._currentValue);
this.value.next(this._currentValue);
}
})
示例10: destroy
destroy() {
this._date.unsubscribe()
this._first.unsubscribe()
this._helloMessageSubject.unsubscribe()
this._helloMessageConnect.unsubscribe()
this._paramsSubject.unsubscribe()
this._last.unsubscribe()
}