本文整理匯總了TypeScript中rxjs/operators.bufferCount函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript bufferCount函數的具體用法?TypeScript bufferCount怎麽用?TypeScript bufferCount使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了bufferCount函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should convert observable obeject to ordinal object', done => {
const aValue = new Subject();
const bValue = new Subject();
const BUFFER_COUNT = 4;
const values = createObject(
aValue.pipe(startWith('')),
bValue.pipe(startWith('')),
);
subscription.add(
combineTemplate(values)
.pipe(bufferCount(BUFFER_COUNT))
.subscribe(v => {
/*tslint:disable:no-magic-numbers*/
expect(v[0]).to.be.deep.eq(createObject('', ''));
expect(v[1]).to.be.deep.eq(createObject('200', ''));
expect(v[2]).to.be.deep.eq(createObject('200', '300'));
expect(v[3]).to.be.deep.eq(createObject('OK', '300'));
/*tslint:enable:no-magic-numbers*/
done();
}),
);
aValue.next('200');
bValue.next('300');
aValue.next('OK');
});
示例2: updatebyPlacements
updatebyPlacements(placementIDs: string): void {
const source = Observable.create((observer) => {
let placementIDsArray = lo_.uniq(placementIDs.split(','))
const next = () => {
const placementID = parseInt(placementIDsArray.shift(), 10)
if (!placementID) {
placementIDsArray.length > 0 && next() || observer.complete()
return
}
this.sizmekApiClient.getMultipleResult<any>(this.sizmekApiClient.getAdsByPlacement, placementID)
.subscribe((data) => {
lo_.forEach(data.result, value => observer.next(value))
next()
}, (error) => {
this.notifications.notify('error', error.message, !0)
})
}
next()
})
source
.pipe(bufferCount(10))
.subscribe((value) => {
this.sizmekApiClient.updateAds({entities: value}).subscribe(() => {
this.notifications.notify('success', `Calling updateAds for adIds ${ reduceFrom<number, any, 'id'>(value, 'id').join(', ') } success`, !0)
}, (error) => {
this.notifications.notify('error', error.message, !0)
})
})
}
示例3: bufferCount2
bufferCount2() {
// Create an observable that emits a value every second
const source = interval(1000);
/*
bufferCount also takes second argument, when to start the next buffer
for instance, if we have a bufferCount of 3 but second argument (startBufferEvery) of 1:
1st interval value:
buffer 1: [0]
2nd interval value:
buffer 1: [0,1]
buffer 2: [1]
3rd interval value:
buffer 1: [0,1,2] Buffer of 3, emit buffer
buffer 2: [1,2]
buffer 3: [2]
4th interval value:
buffer 2: [1,2,3] Buffer of 3, emit buffer
buffer 3: [2, 3]
buffer 4: [3]
*/
const bufferEveryOne = source.pipe(bufferCount(3, 1));
// Print values to console
const subscribe = bufferEveryOne.subscribe(val =>
console.log('Start Buffer Every 1:', val)
);
}
示例4: it
it('observe request with multiple observable emissions', async () => {
const [serverTransports, clientTransports] = createMessageTransports()
const server = createConnection(serverTransports)
server.onRequest(
'm',
(params: number[]) =>
new Observable<number>(observer => {
for (const v of params) {
observer.next(v + 1)
}
observer.complete()
})
)
server.listen()
const client = createConnection(clientTransports)
client.listen()
assert.deepStrictEqual(
await client
.observeRequest<number>('m', [1, 2, 3, 4])
.pipe(bufferCount(4))
.toPromise(),
[2, 3, 4, 5]
)
})
示例5: it
it('should raise error if source raise error before reaching specified buffer count', () => {
const e1 = hot('--a--b--c--d--#');
const e1subs = '^ !';
const expected = '--------------#';
expectObservable(e1.pipe(bufferCount(5))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
示例6: getCoordinates
getCoordinates(): Observable<{first: Coordinates; second: Coordinates}> {
return this.asObservable().pipe(
bufferCount(2),
map(buffer => {
return {first: buffer[0], second: buffer[1]};
}),
);
}
示例7: bufferCount1
bufferCount1() {
// Create an observable that emits a value every second
const source = interval(1000);
// After three values are emitted, pass on as an array of buffered values
const bufferThree = source.pipe(bufferCount(3));
// Print values to console
// ex. output [0,1,2]...[3,4,5]
const subscribe = bufferThree.subscribe(val =>
console.log('Buffered Values:', val)
);
}