本文整理汇总了TypeScript中redux-saga.runSaga函数的典型用法代码示例。如果您正苦于以下问题:TypeScript runSaga函数的具体用法?TypeScript runSaga怎么用?TypeScript runSaga使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了runSaga函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: testRunSaga
function testRunSaga() {
const task0: Task = runSaga<{foo : string}, {baz: boolean}>({
context: {a: 42},
subscribe(cb) {
// typings:expect-error
cb({});
cb({foo: 'foo'});
cb(END);
return () => {};
},
getState() {
return {baz: true};
},
dispatch(input) {
input.foo;
// typings:expect-error
input.bar;
},
sagaMonitor: {
effectTriggered() {},
effectResolved() {},
effectRejected() {},
effectCancelled() {},
actionDispatched() {},
},
logger(level, ...args) {
console.log(level, ...args);
},
onError(error) {
console.error(error);
},
}, function* saga(): SagaIterator {yield effect});
// typings:expect-error
runSaga();
// typings:expect-error
runSaga({});
// typings:expect-error
runSaga({}, iterator);
runSaga({}, function* saga(): SagaIterator {yield effect});
// typings:expect-error
runSaga({}, function* saga(a: 'a'): SagaIterator {yield effect});
// typings:expect-error
runSaga({}, function* saga(a: 'a'): SagaIterator {yield effect}, 1);
runSaga({}, function* saga(a: 'a'): SagaIterator {yield effect}, 'a');
// typings:expect-error
runSaga({}, function* saga(a: 'a', b: 'b'): SagaIterator {yield effect},
'a');
// typings:expect-error
runSaga({}, function* saga(a: 'a', b: 'b'): SagaIterator {yield effect},
'a', 1);
// typings:expect-error
runSaga({}, function* saga(a: 'a', b: 'b'): SagaIterator {yield effect},
1, 'b');
runSaga({}, function* saga(a: 'a', b: 'b'): SagaIterator {yield effect},
'a', 'b');
runSaga({}, function* saga(a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f',
g: 'g'): SagaIterator {yield effect},
'a', 'b', 'c', 'd', 'e', 'f', 'g');
// typings:expect-error
runSaga({}, function* saga(a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f',
g: 'g'): SagaIterator {yield effect},
1, 'b', 'c', 'd', 'e', 'f', 'g');
// test with any iterator i.e. when generator doesn't always yield Effects.
runSaga({}, function* saga() {
yield promise;
});
// typings:expect-error
runSaga({context: 42}, function* saga(): SagaIterator {yield effect});
}
开发者ID:gajus,项目名称:redux-saga,代码行数:94,代码来源:runSaga.ts
示例2: testRunSaga
function testRunSaga() {
const task0: Task = runSaga<{ foo: string }, { baz: boolean }, () => SagaIterator>(
{
context: { a: 42 },
channel: stdChannel,
effectMiddlewares: [
next => effect => {
setTimeout(() => {
next(effect)
}, 10)
},
next => effect => {
setTimeout(() => {
next(effect)
}, 10)
},
],
getState() {
return { baz: true }
},
dispatch(input) {
input.foo
// typings:expect-error
input.bar
},
sagaMonitor: {
effectTriggered() {},
effectResolved() {},
effectRejected() {},
effectCancelled() {},
actionDispatched() {},
},
onError(error) {
console.error(error)
},
},
function* saga(): SagaIterator {
yield effect
},
)
// typings:expect-error
runSaga()
// typings:expect-error
runSaga({})
// typings:expect-error
runSaga({}, iterator)
runSaga({}, function* saga() {
yield effect
})
// TODO: https://github.com/Microsoft/TypeScript/issues/28803
{
// typings:expect-error
// runSaga({}, function* saga(a: 'a'): SagaIterator {})
}
// typings:expect-error
runSaga({}, function* saga(a: 'a'): SagaIterator {}, 1)
runSaga({}, function* saga(a: 'a'): SagaIterator {}, 'a')
// TODO: https://github.com/Microsoft/TypeScript/issues/28803
{
// typings:expect-error
// runSaga({}, function* saga(a: 'a', b: 'b'): SagaIterator {}, 'a')
}
// typings:expect-error
runSaga({}, function* saga(a: 'a', b: 'b'): SagaIterator {}, 'a', 1)
// typings:expect-error
runSaga({}, function* saga(a: 'a', b: 'b'): SagaIterator {}, 1, 'b')
runSaga({}, function* saga(a: 'a', b: 'b'): SagaIterator {}, 'a', 'b')
// test with any iterator i.e. when generator doesn't always yield Effects.
runSaga({}, function* saga() {
yield promise
})
// typings:expect-error
runSaga({ context: 42 }, function* saga(): SagaIterator {})
}
开发者ID:rahulrcopart,项目名称:redux-saga,代码行数:93,代码来源:runSaga.ts
示例3: testOldRunSaga
/**
* Test deprecated runSaga signature
*/
function testOldRunSaga() {
function* saga(): SagaIterator {
yield call(() => {});
}
const iterator = saga();
const task1: Task = runSaga(iterator, {});
const task2: Task = runSaga<{foo : string}, {baz: boolean}>(iterator, {
context: {a: 42},
subscribe(cb) {
// typings:expect-error
cb({});
cb({foo: 'foo'});
cb(END);
return () => {};
},
getState() {
return {baz: true};
},
dispatch(input) {
input.foo;
// typings:expect-error
input.bar;
},
sagaMonitor: {
effectTriggered() {},
effectResolved() {},
effectRejected() {},
effectCancelled() {},
actionDispatched() {},
},
logger(level, ...args) {
console.log(level, ...args);
},
onError(error) {
console.error(error);
},
});
// typings:expect-error
runSaga(iterator, {
context: 42,
});
// test with any iterator i.e. when generator doesn't always yield Effects.
function* generator() {
yield promise;
}
runSaga(generator(), {});
}
开发者ID:gajus,项目名称:redux-saga,代码行数:65,代码来源:runSaga.ts
示例4: cancel
// task
yield cancel(bgSyncTask)
}
}
}
namespace DynamicallyStartingSagasWithRunSaga {
const store = createStore((state: any, action: any) => state);
function* serverSaga(getState) {
yield getState()
}
runSaga(
serverSaga(store.getState),
storeIO(store)
)
}
namespace DynamicallyStartingSagasWithMiddleware {
function* startupSaga() {
}
function* dynamicSaga() {
}
sagaMiddleware(startupSaga).run(dynamicSaga)
}
namespace TestHelpers {
function* watchAndLog(getState) {
开发者ID:HawkHouseIntegration,项目名称:DefinitelyTyped,代码行数:32,代码来源:redux-saga-tests.ts
注:本文中的redux-saga.runSaga函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论