本文整理匯總了TypeScript中redux-saga.default函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript default函數的具體用法?TypeScript default怎麽用?TypeScript default使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了default函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: default
export default (history: History, dsn: string) => {
const sagaMiddleware: SagaMiddleware<{}> = createSagaMiddleware();
let middlewares: Middleware[] = [];
if (process.env.NODE_ENV !== 'production') {
middlewares = [
createLogger(),
];
}
Raven.config(dsn).install();
const devtools: any = process.env.NODE_ENV !== 'production' && (window as any)._REDUX_DEVTOOLS_EXTENSION__ ?
(window as any)._REDUX_DEVTOOLS_EXTENSION__() : (f: any) => f;
const store = createStore(
createRootReducer(history),
compose(
applyMiddleware(
routerMiddleware(history),
googleAnalytics,
sagaMiddleware,
createRavenMiddleware(Raven, {}),
...middlewares,
),
devtools,
),
);
sagaMiddleware.run(rootSaga);
return store;
};
示例2: createSagaMiddleware
export const configureStore = () => {
const sagaMiddleware = createSagaMiddleware()
const logger = createLogger()
const store = createStore(
persistReducer({ key: 'reversi', storage, whitelist: ['history'] }, reducer),
compose(
applyMiddleware(sagaMiddleware, logger),
getDevtools()
)
)
const persistor = persistStore(store)
if (module.hot) {
module.hot.accept('./reducer', () => {
store.replaceReducer(require('./reducer').default)
})
}
return {
store,
persistor,
runSaga: sagaMiddleware.run,
close () {
store.dispatch(END as any)
}
}
}
示例3: configureStore
export function configureStore(preloadedState?: IApplicationState): SagaEnhancedStore<IApplicationState> {
const sagaMiddleware = createSagaMiddleware()
const middlewares = [
routerMiddleware(browserHistory),
sagaMiddleware,
]
const store = createStore<IApplicationState | undefined>(
rootReducer,
preloadedState,
compose<any, any>(
applyMiddleware(...middlewares),
devTools(),
),
) as SagaEnhancedStore<IApplicationState>
sagaMiddleware.run(rootSaga)
store.runSaga = sagaMiddleware.run
store.close = () => store.dispatch(END)
// Hot reload reducers:
// https://github.com/reactjs/react-redux/releases/tag/v2.0.0
/* tslint:disable:no-string-literal */
if (process.env.NODE_ENV === "development" && module["hot"]) {
module["hot"].accept("./reducers", () => {
const nextRootReducer = require("./reducers").default
store.replaceReducer(nextRootReducer)
})
}
/* tslint:enable:no-string-literal */
return store
}
示例4: configureStore
export default function configureStore(initialState: DeepPartial<RootState>) {
const sagaMiddleware = createSagaMiddleware();
const middleware = [
sagaMiddleware
];
const composeEnhancers = composeWithDevTools({});
const composedEnhancers = composeEnhancers(
applyMiddleware(...middleware)
);
const store = createStore(
rootReducer,
initialState,
composedEnhancers
);
for (const sagaKey of Object.keys(sagas)) {
sagaMiddleware.run(sagas[sagaKey]);
}
return store;
}
示例5: configureStore
export default function configureStore(initialState = {}, history) {
// Middleware you want to use in production:
const enhancer = applyMiddleware(
routerMiddleware(history),
createSagaMiddleware()
);
// Note: only Redux >= 3.1.0 supports passing enhancer as third argument.
// See https://github.com/rackt/redux/releases/tag/v3.1.0
const reducer = createReducer();
return createStore(reducer, initialState, enhancer);
};
示例6: function
export default function (initialState, ...middlewares) {
const sagaMiddleware = createSagaMiddleware();
const store: Store<State> = createStore(
reducer,
initialState || {},
applyMiddleware(
...middlewares,
sagaMiddleware
)
);
sagaMiddleware.run(sagas);
return store;
}
示例7: testContext
function testContext() {
interface Context {
a: string;
b: number;
}
// typings:expect-error
createSagaMiddleware<Context>({context: {c: 42}});
// typings:expect-error
createSagaMiddleware({context: 42});
const middleware = createSagaMiddleware<Context>({
context: {a: '', b: 42},
});
// typings:expect-error
middleware.setContext({c: 42});
middleware.setContext({b: 42});
const task = middleware.run(function* () {yield effect});
task.setContext({b: 42});
task.setContext<Context>({a: ''});
// typings:expect-error
task.setContext<Context>({c: ''});
}
示例8: testOptions
function testOptions() {
const emptyOptions = createSagaMiddleware({});
const withOptions = createSagaMiddleware({
onError(error) {
console.error(error);
},
logger(level, ...args) {
console.log(level, ...args);
},
sagaMonitor: {
effectTriggered() { },
},
emitter: emit => action => {
if (Array.isArray(action)) {
action.forEach(emit);
return
}
emit(action);
},
});
const withMonitor = createSagaMiddleware({
sagaMonitor: {
effectTriggered() {},
effectResolved() {},
effectRejected() {},
effectCancelled() {},
actionDispatched() {},
}
});
}
示例9: configureStore
export function configureStore() {
const sagaMiddleware = createSagaMiddleware({
onError: () => null,
});
function runSaga(saga: Effect): Task {
return sagaMiddleware.run(SagaRunner, saga);
}
function runSagaInitialized(saga: any): Task {
return sagaMiddleware.run(SagaInitialized, saga);
}
const store = createStore(
reducer,
applyMiddleware(sagaMiddleware)
);
(store as any).runSaga = runSaga;
(store as any).runSagaInitialized = runSagaInitialized;
(store as any).sagaMiddleware = sagaMiddleware;
return store as ExtendedStore<typeof store, {
runSaga: RunSagaEffect;
runSagaInitialized: RunSagaEffect;
sagaMiddleware: SagaMiddleware,
}>;
}
示例10: createSagaMiddleware
const createStore = (initialState?: State): Store<State> => {
const sagaMiddleware = createSagaMiddleware();
const enhancer = applyMiddleware(sagaMiddleware);
const store = create<State>(reducer, initialState, enhancer);
sagaMiddleware.run(saga);
return store;
};
示例11: testRun
function testRun() {
const middleware = createSagaMiddleware()
middleware.run(function* saga(): SagaIterator {})
// TODO: https://github.com/Microsoft/TypeScript/issues/28803
{
// typings:expect-error
// middleware.run(function* saga(a: 'a'): SagaIterator {})
}
// typings:expect-error
middleware.run(function* saga(a: 'a'): SagaIterator {}, 1)
middleware.run(function* saga(a: 'a'): SagaIterator {}, 'a')
// TODO: https://github.com/Microsoft/TypeScript/issues/28803
{
// typings:expect-error
// middleware.run(function* saga(a: 'a', b: 'b'): SagaIterator {}, 'a')
}
// typings:expect-error
middleware.run(function* saga(a: 'a', b: 'b'): SagaIterator {}, 'a', 1)
// typings:expect-error
middleware.run(function* saga(a: 'a', b: 'b'): SagaIterator {}, 1, 'b')
middleware.run(function* saga(a: 'a', b: 'b'): SagaIterator {}, 'a', 'b')
// test with any iterator i.e. when generator doesn't always yield Effects.
middleware.run(function* saga() {
yield promise
})
}
示例12: createAdminUIStore
export function createAdminUIStore() {
const sagaMiddleware = createSagaMiddleware();
const store = createStore(
combineReducers<AdminUIState>({
cachedData: apiReducersReducer,
hover: hoverReducer,
localSettings: localSettingsReducer,
metrics: metricsReducer,
queryManager: queryManagerReducer,
routing: routerReducer,
timewindow: timeWindowReducer,
uiData: uiDataReducer,
}),
compose(
applyMiddleware(thunk, sagaMiddleware),
// Support for redux dev tools
// https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd
(window as any).devToolsExtension ? (window as any).devToolsExtension({
// TODO(maxlang): implement {,de}serializeAction.
// TODO(maxlang): implement deserializeState.
serializeState: (_key: string, value: any): Object => {
if (value && value.toRaw) {
return value.toRaw();
}
return value;
},
}) : _.identity,
) as GenericStoreEnhancer,
);
sagaMiddleware.run(queryMetricsSaga);
return store;
}
示例13: Promise
return new Promise((resolve, reject) => {
try {
const pages = pagesLoaders.map(Page => new Page())
const initialState = bindInitialState(pages)
const reducerList = bindReducers(pages)
const enhancer: any =
process.env.NODE_ENV === 'development' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
: compose
const sagaMiddleware = createSagaMiddleware()
const appReducer = combineReducers(reducerList)
const signOutAction = Actions.SignOut.SIGN_OUT
const rootReducer = (state: any, action: any) => appReducer(action.type === signOutAction ? {} : state, action)
const store = createStore(rootReducer, initialState, enhancer(applyMiddleware(sagaMiddleware), autoRehydrate()))
sagaMiddleware.run(bindSagas(pages))
persistStore(store, {}, () => resolve({ store, pages }))
} catch (e) {
reject(e)
}
})
示例14: createSagaMiddleware
export const init = (state: RootState) => {
const sagaMiddleware = createSagaMiddleware({});
const store = createStore(
rootReducer, state,
applyMiddleware(sagaMiddleware)
);
sagaMiddleware.run(rootSaga);
};
示例15: createSagaMiddleware
const init = (initialState: ApplicationState) => {
const sagaMiddleware = createSagaMiddleware();
const store = createStore(
mainReducer,
initialState,
applyMiddleware(sagaMiddleware)
);
sagaMiddleware.run(mainSaga);
};