本文整理匯總了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});
}
示例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 {})
}
示例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(), {});
}
示例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) {