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


TypeScript rxjs-run.setup函數代碼示例

本文整理匯總了TypeScript中@cycle/rxjs-run.setup函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript setup函數的具體用法?TypeScript setup怎麽用?TypeScript setup使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了setup函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: it

  it('should create a location from PushHistoryInput', done => {
    function main(_sources: {history: Observable<Location>}) {
      return {
        history: of<PushHistoryInput>({type: 'push', pathname: '/test'}),
      };
    }

    const {sources, run} = setup(main, {
      history: makeServerHistoryDriver(),
    });

    sources.history.pipe(skip(1)).subscribe({
      next(location: Location) {
        assert.strictEqual(location.pathname, '/test');
        done();
      },
      error: done,
      complete: () => {
        done('complete should not be called');
      },
    });
    run();
  });
開發者ID:,項目名稱:,代碼行數:23,代碼來源:

示例2: it

  it('should not auto-execute lazy request without listening to response stream', function(
    done,
  ) {
    function main(sources: {HTTP: HTTPSource}) {
      return {
        HTTP: Rx.Observable.of({
          url: uri + '/pet',
          method: 'POST',
          send: {name: 'Woof', species: 'Dog'},
          lazy: true,
        }),
      };
    }

    const {sources, run} = Cycle.setup(main, {HTTP: makeHTTPDriver()});
    globalSandbox.petPOSTResponse = null;
    run();

    setTimeout(function() {
      assert.strictEqual(globalSandbox.petPOSTResponse, null);
      done();
    }, 250);
  });
開發者ID:nlarche,項目名稱:cyclejs,代碼行數:23,代碼來源:node.ts

示例3: it

  it('should allow going back/forwards with `go`, `goBack`, `goForward`', function(done) {
    function main(_sources: {history: Observable<Location>}) {
      return {
        history: Observable.interval(100)
          .take(6)
          .map(
            i =>
              [
                '/test',
                '/other',
                {type: 'go', amount: -1},
                {type: 'go', amount: +1},
                {type: 'goBack'},
                {type: 'goForward'},
              ][i]
          ),
      };
    }

    const {sources, run} = setup(main, {history: makeHistoryDriver()});

    const expected = ['/test', '/other', '/test', '/other', '/test', '/other'];

    sources.history.skip(1).subscribe({
      next(location: Location) {
        assert.strictEqual(location.pathname, expected.shift());
        if (expected.length === 0) {
          done();
        }
      },
      error: done,
      complete: () => {
        done('complete should not be called');
      },
    });
    dispose = run();
  });
開發者ID:ntilwalli,項目名稱:cyclejs,代碼行數:37,代碼來源:rxjs.ts

示例4: it

  it('should add request options object to each response', function(done) {
    function main(_sources: {HTTP: HTTPSource}) {
      return {
        HTTP: Rx.Observable.of({
          url: uri + '/pet',
          method: 'POST',
          send: {name: 'Woof', species: 'Dog'},
          _id: 'petRequest',
        }),
      };
    }

    const {sources, run} = Cycle.setup(main, {HTTP: makeHTTPDriver()});

    sources.HTTP.select()
      .mergeAll()
      .subscribe(function(r: any) {
        assert.ok(r.request);
        assert.strictEqual(r.request._id, 'petRequest');
        done();
      });

    run();
  });
開發者ID:ntilwalli,項目名稱:cyclejs,代碼行數:24,代碼來源:node.ts

示例5: it

  it('should return binary response when responseType option is blob', function(done) {
    function main(_sources: {HTTP: HTTPSource}) {
      return {
        HTTP: Rx.Observable.of({
          url: uri + '/binary',
          method: 'GET',
          responseType: 'blob',
        }),
      };
    }

    const {sources, run} = Cycle.setup(main, {HTTP: makeHTTPDriver()});

    const response$$ = sources.HTTP.select();
    response$$.subscribe(function(response$) {
      assert.strictEqual(response$.request.url, uri + '/binary');
      assert.strictEqual(response$.request.method, 'GET');
      assert.strictEqual(response$.request.responseType, 'blob');
      response$.subscribe(function(response) {
        assert.strictEqual(response.status, 200);
        const fr = new FileReader();
        fr.onload = ev => {
          assert.deepStrictEqual(
            new Uint8Array(fr.result),
            new Uint8Array([1, 2, 3])
          );
          done();
        };
        fr.onerror = ev => {
          done('should not be called');
        };
        fr.readAsArrayBuffer(response.body);
      });
    });
    run();
  });
開發者ID:ntilwalli,項目名稱:cyclejs,代碼行數:36,代碼來源:index.ts


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