當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。