当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript run.setup函数代码示例

本文整理汇总了TypeScript中@cycle/run.setup函数的典型用法代码示例。如果您正苦于以下问题:TypeScript setup函数的具体用法?TypeScript setup怎么用?TypeScript setup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了setup函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

  it('should create a location from pathname', function(done) {
    function main(_sources: {history: Stream<Location>}) {
      return {
        history: xs.of('/test'),
      };
    }

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

    sources.history.drop(1).subscribe({
      next(location: Location) {
        assert.strictEqual(location.pathname, '/test');
        done();
      },
      error: done,
      complete: () => {
        done('complete should not be called');
      },
    });
    dispose = run();
  });
开发者ID:ntilwalli,项目名称:cyclejs,代码行数:21,代码来源:xstream.ts

示例2: it

  it('should setup click detection on a ready DOM element (e.g. from server)', function(
    done,
  ) {
    function app(sources: {DOM: DOMSource}) {
      return {
        DOM: xs.never(),
      };
    }

    const containerElement = createRenderTarget();
    const headerElement = document.createElement('H3');
    headerElement.className = 'myelementclass';
    headerElement.textContent = 'Foobar';
    containerElement.appendChild(headerElement);

    const {sinks, sources, run} = setup(app, {
      DOM: makeDOMDriver(containerElement),
    });
    const dispose = run();
    sources.DOM.select('.myelementclass').events('click').addListener({
      next: (ev: Event) => {
        assert.strictEqual(ev.type, 'click');
        assert.strictEqual((ev.target as HTMLElement).textContent, 'Foobar');
        dispose();
        done();
      },
    });
    // Make assertions
    setTimeout(() => {
      const myElement = containerElement.querySelector(
        '.myelementclass',
      ) as HTMLElement;
      assert.notStrictEqual(myElement, null);
      assert.notStrictEqual(typeof myElement, 'undefined');
      assert.strictEqual(myElement.tagName, 'H3');
      assert.doesNotThrow(function() {
        setTimeout(() => myElement.click());
      });
    }, 200);
  });
开发者ID:joeldentici,项目名称:cyclejs,代码行数:40,代码来源:events.ts

示例3: it

  it('should catch interaction events without prior select()', function(done) {
    function app(_sources: {DOM: DOMSource}) {
      return {
        DOM: xs.of(div('.parent', [h3('.myelementclass', 'Foobar')])),
      };
    }

    const {sinks, sources, run} = setup(app, {
      DOM: makeDOMDriver(createRenderTarget()),
    });

    let dispose: any;
    sources.DOM.events('click').addListener({
      next: (ev: Event) => {
        assert.strictEqual(ev.type, 'click');
        assert.strictEqual((ev.target as HTMLElement).textContent, 'Foobar');
        dispose();
        done();
      },
    });

    sources.DOM.select(':root')
      .element()
      .drop(1)
      .take(1)
      .addListener({
        next: (root: Element) => {
          const myElement = root.querySelector(
            '.myelementclass'
          ) as HTMLElement;
          assert.notStrictEqual(myElement, null);
          assert.notStrictEqual(typeof myElement, 'undefined');
          assert.strictEqual(myElement.tagName, 'H3');
          assert.doesNotThrow(function() {
            setTimeout(() => myElement.click());
          });
        },
      });
    dispose = run();
  });
开发者ID:ntilwalli,项目名称:cyclejs,代码行数:40,代码来源:events.ts

示例4: it

  it('should allow going back/forwards with `go`, `goBack`, `goForward`', function(
    done,
  ) {
    function main(sources: {history: Stream<Location>}) {
      return {
        history: xs
          .periodic(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.drop(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:joeldentici,项目名称:cyclejs,代码行数:40,代码来源:xstream.ts

示例5: it

  it('should not select element outside the given scope', function(done) {
    function app(sources: {DOM: MainDOMSource}) {
      return {
        DOM: xs.of(
          h3('.top-most', [
            h2('.bar', 'Wrong'),
            div('.foo', [h4('.bar', 'Correct')]),
          ]),
        ),
      };
    }

    const {sinks, sources, run} = setup(app, {
      DOM: makeDOMDriver(createRenderTarget()),
    });

    let dispose: any;
    // Make assertions
    sources.DOM
      .select('.foo')
      .select('.bar')
      .elements()
      .drop(1)
      .take(1)
      .addListener({
        next: (elements: Array<Element>) => {
          assert.strictEqual(elements.length, 1);
          const element = elements[0];
          assert.notStrictEqual(element, null);
          assert.notStrictEqual(typeof element, 'undefined');
          assert.strictEqual(element.tagName, 'H4');
          assert.strictEqual(element.textContent, 'Correct');
          setTimeout(() => {
            dispose();
            done();
          });
        },
      });
    dispose = run();
  });
开发者ID:joeldentici,项目名称:cyclejs,代码行数:40,代码来源:select.ts

示例6: it

  it('should allow DOM.select()ing its own root without classname or id', function (done) {
    function app(sources: {DOM: MainDOMSource}) {
      const child$ = sources.DOM.isolateSink(xs.of(
        span([
          h4('.bar', 'Wrong'),
        ]),
      ), 'ISOLATION');

      return {
        DOM: child$.map(child =>
          h3('.top-most', [
            child,
          ]),
        ),
      };
    }

    const {sinks, sources, run} = setup(app, {
      DOM: makeDOMDriver(createRenderTarget()),
    });

    const {isolateSource} = sources.DOM;

    isolateSource(sources.DOM, 'ISOLATION')
      .select('span').elements()
      .drop(1).take(1)
      .addListener({
        next: (elements: Array<Element>) => {
          assert.strictEqual(Array.isArray(elements), true);
          assert.strictEqual(elements.length, 1);
          const correctElement = elements[0];
          assert.notStrictEqual(correctElement, null);
          assert.notStrictEqual(typeof correctElement, 'undefined');
          assert.strictEqual(correctElement.tagName, 'SPAN');
          done();
        },
      });

    run();
  });
开发者ID:whitecolor,项目名称:cyclejs,代码行数:40,代码来源:isolation.ts

示例7: it

  it('should catch a blur event by default (no options)', function (done) {
    function app(sources: {DOM: DOMSource}) {
      return {
        DOM: xs.of(div('.parent', [
          input('.correct', {type: 'text'}, []),
          input('.wrong', {type: 'text'}, []),
          input('.dummy', {type: 'text'}),
        ])),
      };
    }

    if (!document.hasFocus()) {
      done();
    } else {
      const {sinks, sources, run} = setup(app, {
        DOM: makeDOMDriver(createRenderTarget()),
      });

      sources.DOM.select('.correct').events('blur').addListener({
        next: (ev: Event) => {
          assert.strictEqual(ev.type, 'blur');
          assert.strictEqual((ev.target as HTMLElement).className, 'correct');
          done();
        },
      });

      sources.DOM.select(':root').elements().drop(1).take(1).addListener({
        next: (root: Element) => {
          const correct = root.querySelector('.correct') as HTMLElement;
          const wrong = root.querySelector('.wrong') as HTMLElement;
          const dummy = root.querySelector('.dummy') as HTMLElement;
          setTimeout(() => wrong.focus(), 50);
          setTimeout(() => dummy.focus(), 100);
          setTimeout(() => correct.focus(), 150);
          setTimeout(() => dummy.focus(), 200);
        },
      });
      run();
    }
  });
开发者ID:whitecolor,项目名称:cyclejs,代码行数:40,代码来源:events.ts

示例8: it

  it('should allow isolatedDOMSource.events() to work without crashing', function(
    done,
  ) {
    function app(sources: {DOM: MainDOMSource}) {
      return {
        DOM: xs.of(
          h3('.top-most', [div({isolate: 'foo'}, [h4('.bar', 'Hello')])]),
        ),
      };
    }

    const {sinks, sources, run} = setup(app, {
      DOM: makeDOMDriver(createRenderTarget()),
    });
    let dispose: any;
    const isolatedDOMSource = sources.DOM.isolateSource(sources.DOM, 'foo');

    isolatedDOMSource.events('click').addListener({
      next: (ev: Event) => {
        dispose();
        done();
      },
    });

    // Make assertions
    isolatedDOMSource.select('div').elements().drop(1).take(1).addListener({
      next: (elements: Array<Element>) => {
        assert.strictEqual(elements.length, 1);
        const correctElement = elements[0] as HTMLElement;
        assert.notStrictEqual(correctElement, null);
        assert.notStrictEqual(typeof correctElement, 'undefined');
        assert.strictEqual(correctElement.tagName, 'DIV');
        assert.strictEqual(correctElement.textContent, 'Hello');
        setTimeout(() => {
          correctElement.click();
        });
      },
    });
    dispose = run();
  });
开发者ID:joeldentici,项目名称:cyclejs,代码行数:40,代码来源:isolation.ts

示例9: it

  it('should output HTMLSource as an adapted stream', function(done) {
    type MySources = {
      html: HTMLSource;
    };
    type MySinks = {
      html: Stream<VNode>;
    };

    function app(sources: MySources): MySinks {
      return {
        html: xs.of(div('.test-element', ['Foobar'])),
      };
    }
    const {sources} = setup(app, {
      html: makeHTMLDriver((html: string) => {}),
    });
    assert.strictEqual(
      typeof (sources.html.elements() as any).imitate,
      'function',
    );
    done();
  });
开发者ID:joeldentici,项目名称:cyclejs,代码行数:22,代码来源:index.ts


注:本文中的@cycle/run.setup函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。