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


TypeScript react-mixout.default函数代码示例

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


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

示例1: it

  it('should properly listen on window events as default', () => {
    let clicks = 0;
    const Test = buildClass(() => clicks++);
    const Mixout = mixout(listen('click', 'onClick'))(Test);
    mount(React.createElement(Mixout));

    document.body.click();
    expect(clicks).to.be.equals(1);
    document.body.click();
    document.body.click();
    expect(clicks).to.be.equals(3);
  });
开发者ID:alitaheri,项目名称:react-mixout,代码行数:12,代码来源:main.spec.ts

示例2: onClick

  it('should properly pass down useCapture', () => {
    const calls: string[] = [];
    let b: any;

    class Test extends React.Component<any, any> {
      public onClick() {
        calls.push('test');
      }

      public render() {
        return React.createElement('button', {
          onClick: () => calls.push('button'),
          ref: (i: any) => b = i,
        });
      }
    }

    const element = document.createElement('div');
    document.body.appendChild(element);

    const Mixout = mixout(listen('click', 'onClick', { target: 'document', useCapture: true }))(Test);
    mount(React.createElement(Mixout), { attachTo: element });

    expect(calls).to.deep.equal([]);
    b.click();
    expect(calls).to.deep.equal(['test', 'button']);
  });
开发者ID:alitaheri,项目名称:react-mixout,代码行数:27,代码来源:main.spec.ts

示例3: it

  it('should call resolver only when selectors return a different value', () => {
    let called = 0;
    const memo = memoize(
      'result',
      (_p, context) => context.pocket.cash,
      (_p, context) => context.pocket.coins,
      props => props.accounting.credit,
      props => props.accounting.debt,
      (cash, coins, credit, debt) => { called++; return cash + coins + credit - debt; },
    );

    const Mixout = mixout(memo)(Test);
    const wrapper = mount(
      React.createElement(Mixout, { accounting: { credit: 100, debt: 50 } }),
      {
        childContextTypes: { pocket: () => null },
        context: { pocket: { cash: 1, coins: 10 } },
      },
    );

    expect(wrapper.find(Test).at(0).prop('result')).to.be.equals(61);
    expect(called).to.be.equals(1);

    wrapper.setProps({ accounting: { credit: 100, debt: 50 } });
    wrapper.setContext({ pocket: { cash: 1, coins: 10 } });

    expect(wrapper.find(Test).at(0).prop('result')).to.be.equals(61);
    expect(called).to.be.equals(1);

    wrapper.setContext({ pocket: { cash: 2, coins: 10 } });

    expect(wrapper.find(Test).at(0).prop('result')).to.be.equals(62);
    expect(called).to.be.equals(2);

    wrapper.setProps({ accounting: { credit: 100, debt: 60 } });
    wrapper.setContext({ pocket: { cash: 2, coins: 10 } });

    expect(wrapper.find(Test).at(0).prop('result')).to.be.equals(52);
    expect(called).to.be.equals(3);

    wrapper.setProps({ accounting: { credit: 100, debt: 50 } });
    wrapper.setContext({ pocket: { cash: 2, coins: 20 } });

    expect(wrapper.find(Test).at(0).prop('result')).to.be.equals(72);
    expect(called).to.be.equals(5);

    wrapper.setProps({ accounting: { credit: 100, debt: 50 } });
    wrapper.setContext({ pocket: { cash: 2, coins: 20 } });

    expect(wrapper.find(Test).at(0).prop('result')).to.be.equals(72);
    expect(called).to.be.equals(5);

  });
开发者ID:alitaheri,项目名称:react-mixout,代码行数:53,代码来源:main.spec.ts

示例4: it

  it('should not re-render if previous and next props are shallowly equal', () => {
    let renders = 0;
    const Component = () => { renders++; return null!; };
    const Mixout = mixout(pure)(Component);

    const wrapper = mount(React.createElement(Mixout, { prop: 'foo' }));
    expect(renders).to.be.equals(1);

    wrapper.setProps({ prop: 'bar' });
    expect(renders).to.be.equals(2);

    wrapper.setProps({ prop: 'foo' });
    expect(renders).to.be.equals(3);

    wrapper.setProps({ prop: 'foo' });
    wrapper.setProps({ prop: 'foo' });
    expect(renders).to.be.equals(3);
  });
开发者ID:alitaheri,项目名称:react-mixout,代码行数:18,代码来源:main.spec.ts


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