當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript operators.bufferCount函數代碼示例

本文整理匯總了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');
  });
開發者ID:brn,項目名稱:react-mvi,代碼行數:28,代碼來源:combine-template.spec.ts

示例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)
			})
		})
	}
開發者ID:marsojane,項目名稱:sasutil,代碼行數:29,代碼來源:adsupdate.service.ts

示例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)
   );
 }
開發者ID:zwvista,項目名稱:SampleMisc,代碼行數:26,代碼來源:transforming.service.ts

示例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]
        )
    })
開發者ID:JoYiRis,項目名稱:sourcegraph,代碼行數:25,代碼來源:connection.test.ts

示例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);
  });
開發者ID:DallanQ,項目名稱:rxjs,代碼行數:8,代碼來源:bufferCount-spec.ts

示例6: getCoordinates

 getCoordinates(): Observable<{first: Coordinates; second: Coordinates}> {
   return this.asObservable().pipe(
     bufferCount(2),
     map(buffer => {
       return {first: buffer[0], second: buffer[1]};
     }),
   );
 }
開發者ID:thelgevold,項目名稱:angular-2-samples,代碼行數:8,代碼來源:edge-service.ts

示例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)
   );
 }
開發者ID:zwvista,項目名稱:SampleMisc,代碼行數:11,代碼來源:transforming.service.ts


注:本文中的rxjs/operators.bufferCount函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。