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


TypeScript effects.cps函数代码示例

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


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

示例1: testCps

function* testCps(): SagaIterator {
  // typings:expect-error
  yield cps((a: number) => {});

  yield cps((cb) => {cb(null, 1)});

  // typings:expect-error
  yield cps<string>((cb) => {cb(null, 1)});
  yield cps<number>((cb) => {cb(null, 1)});

  yield cps((cb) => {cb.cancel = () => {}});

  // typings:expect-error
  yield cps((a: 'a', cb) => {});
  // typings:expect-error
  yield cps((a: 'a', cb) => {}, 1);
  yield cps((a: 'a', cb) => {}, 'a');

  // typings:expect-error
  yield cps((a: 'a', b: 'b', cb) => {}, 'a');
  // typings:expect-error
  yield cps((a: 'a', b: 'b', cb) => {}, 'a', 1);
  // typings:expect-error
  yield cps((a: 'a', b: 'b', cb) => {}, 1, 'b');
  yield cps((a: 'a', b: 'b', cb) => {}, 'a', 'b');

  // typings:expect-error
  yield cps(
    (a: 'a', b: 'b', c: 'c', d: 'd', cb) => {},
    1, 'b', 'c', 'd'
  );

  yield cps(
    (a: 'a', b: 'b', c: 'c', d: 'd', cb) => {cb(null, 1)},
    'a', 'b', 'c', 'd'
  );
  yield cps<number, 'a', 'b', 'c', 'd'>(
    (a: 'a', b: 'b', c: 'c', d: 'd', cb) => {cb(null, 1)},
    'a', 'b', 'c', 'd'
  );

  // typings:expect-error
  yield cps(
    (a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb) => {},
    1, 'b', 'c', 'd', 'e', 'f'
  );

  yield cps(
    (a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb) => {cb(null, 1)},
    'a', 'b', 'c', 'd', 'e', 'f'
  );
  yield cps<number, 'a', 'b', 'c', 'd', 'e'>(
    (a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb) => {cb(null, 1)},
    'a', 'b', 'c', 'd', 'e', 'f'
  );

  const obj = {
    foo: 'bar',
    getFoo(arg: string, cb: (error: any, result: string) => void) {
      cb(null, this.foo);
    },
  };

  // typings:expect-error
  yield cps([obj, obj.foo]);
  // typings:expect-error
  yield cps([obj, obj.getFoo]);
  // typings:expect-error
  yield cps([obj, obj.getFoo], 1);
  yield cps([obj, obj.getFoo], 'bar');
  yield cps<string, string>([obj, obj.getFoo], 'bar');

  // typings:expect-error
  yield cps([obj, 'foo']);
  // typings:expect-error
  yield cps([obj, 'getFoo']);
  // typings:expect-error
  yield cps([obj, 'getFoo'], 1);
  yield cps([obj, 'getFoo'], 'bar');
  yield cps<typeof obj, 'getFoo', string, string>([obj, 'getFoo'], 'bar');

  // typings:expect-error
  yield cps({context: obj, fn: obj.foo});
  // typings:expect-error
  yield cps({context: obj, fn: obj.getFoo});
  // typings:expect-error
  yield cps({context: obj, fn: obj.getFoo}, 1);
  yield cps<string, string>({context: obj, fn: obj.getFoo}, 'bar');

  // typings:expect-error
  yield cps({context: obj, fn: 'foo'});
  // typings:expect-error
  yield cps({context: obj, fn: 'getFoo'});
  // typings:expect-error
  yield cps({context: obj, fn: 'getFoo'}, 1);
  yield cps({context: obj, fn: 'getFoo'}, 'bar');
  yield cps<typeof obj, 'getFoo', string, string>({context: obj, fn: 'getFoo'}, 'bar');
}
开发者ID:javarouka,项目名称:redux-saga,代码行数:98,代码来源:effects.ts

示例2: testCps

function* testCps(): SagaIterator {
  type Cb<R> = (error: any, result: R) => void

  // typings:expect-error
  yield cps((a: number) => {})

  yield cps(cb => {
    cb(null, 1)
  })
  yield cps((cb: Cb<number>) => {
    cb(null, 1)
  })

  // typings:expect-error
  yield cps<(cb: Cb<string>) => void>(cb => {
    cb(null, 1)
  })
  yield cps<(cb: Cb<number>) => void>(cb => {
    cb(null, 1)
  })

  yield cps(cb => {
    cb.cancel = () => {}
  })

  // typings:expect-error
  yield cps((a: 'a', cb: Cb<number>) => {})
  // typings:expect-error
  yield cps((a: 'a', cb: Cb<number>) => {}, 1)
  yield cps((a: 'a', cb: Cb<number>) => {}, 'a')

  // typings:expect-error
  yield cps((a: 'a', b: 'b', cb) => {}, 'a')
  // typings:expect-error
  yield cps((a: 'a', b: 'b', cb) => {}, 'a', 1)
  // typings:expect-error
  yield cps((a: 'a', b: 'b', cb: Cb<number>) => {}, 1, 'b')
  yield cps((a: 'a', b: 'b', cb: Cb<number>) => {}, 'a', 'b')

  // typings:expect-error
  yield cps((a: 'a', b: 'b', c: 'c', d: 'd', cb: Cb<number>) => {}, 1, 'b', 'c', 'd')

  yield cps(
    (a: 'a', b: 'b', c: 'c', d: 'd', cb: Cb<number>) => {
      cb(null, 1)
    },
    'a',
    'b',
    'c',
    'd',
  )
  yield cps<(a: 'a', b: 'b', c: 'c', d: 'd', cb: Cb<number>) => void>(
    (a: 'a', b: 'b', c: 'c', d: 'd', cb: Cb<number>) => {
      cb(null, 1)
    },
    'a',
    'b',
    'c',
    'd',
  )

  // typings:expect-error
  yield cps((a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb: Cb<number>) => {}, 1, 'b', 'c', 'd', 'e', 'f')

  yield cps(
    (a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb: Cb<number>) => {
      cb(null, 1)
    },
    'a',
    'b',
    'c',
    'd',
    'e',
    'f',
  )
  yield cps<(a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb: Cb<number>) => void>(
    (a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb: Cb<number>) => {
      cb(null, 1)
    },
    'a',
    'b',
    'c',
    'd',
    'e',
    'f',
  )

  const obj = {
    foo: 'bar',
    getFoo(arg: string, cb: Cb<string>) {
      cb(null, this.foo)
    },
  }

  // typings:expect-error
  yield cps([obj, obj.foo])
  // typings:expect-error
  yield cps([obj, obj.getFoo])
  // typings:expect-error
  yield cps([obj, obj.getFoo], 1)
//.........这里部分代码省略.........
开发者ID:rahulrcopart,项目名称:redux-saga,代码行数:101,代码来源:effects.ts


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