本文整理匯總了TypeScript中redux.MiddlewareAPI類的典型用法代碼示例。如果您正苦於以下問題:TypeScript MiddlewareAPI類的具體用法?TypeScript MiddlewareAPI怎麽用?TypeScript MiddlewareAPI使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了MiddlewareAPI類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: next
export const fetchInstalledApps: Middleware = (store: MiddlewareAPI<AppState>) => (next: Dispatch<AppState>) => (action: AppAction) =>
{
const result = next(action);
if (action.type === "REQUEST_INSTALLED_APPS")
{
store.dispatch(requestRegisteredApps());
store.dispatch(requestSystemApps());
}
return result;
};
示例2: fetchLatestVersion
async function fetchLatestVersion(store: MiddlewareAPI<AppState>, action: RequestLatestVersionAction): Promise<void>
{
const app = store.getState().installedApps.apps.find(_ => _.id === action.payload.appId);
if (!app) return;
const versionProvider = appRegistry.loadVersionProvider(app.id);
const versionProviderAdapter = VersionProviderFactory.create(versionProvider);
const latestVersion = await versionProviderAdapter.getVersion();
const isOutdated = new VersionComparer(app.installedVersion).isLesserThan(latestVersion);
store.dispatch(receiveLatestVersion(app.id, latestVersion, isOutdated));
}
示例3: next
export const backendMiddleware: Middleware = <AppState>(store: MiddlewareAPI<AppState>) => (next: Dispatch<AppState>) => (originalAction: any) => {
const result = next(originalAction);
const action: AppAction = originalAction as any;
ipcRenderer.send('action', [store.getState(), action]);
return result
}
示例4: fetchLatestVersions
function fetchLatestVersions(store: MiddlewareAPI<AppState>): void
{
const state = store.getState();
state.installedApps.apps
.filter(_ => _.latestVersion === null)
.forEach(app => store.dispatch(requestLatestVersion(app.id)));
}
示例5: next
export const joinRegisteredAppsWithSystemApps: Middleware = (store: MiddlewareAPI<AppState>) => (next: Dispatch<AppState>) => (action: AppAction) =>
{
const result = next(action);
if (!(action.type === "RECEIVE_REGISTERED_APPS" || action.type === "RECEIVE_SYSTEM_APPS"))
return result;
const state = store.getState();
if (state.registeredApps.isFetching || state.systemApps.isFetching)
return result;
const installedApps = join(state.registeredApps.apps, state.systemApps.apps);
store.dispatch(receiveInstalledApps(installedApps));
return result;
};
示例6: next
return (next: Dispatch) => (action: Action) => {
const prevState = store.getState()
const res = next(action)
const newState = store.getState()
if (prevState.currentGame !== newState.currentGame) {
console.log('[Redux auto save middleware] Current game state changed. Triggering save game action.')
return next(saveGameAction(newState.currentGame))
}
return res
}
示例7: next
<A extends Action>(action: A) => {
console.log('will dispatch', action);
const returnValue = next(action);
console.log('state after dispatch', api.getState());
return returnValue;
};
示例8: next
) => (action: any) => {
console.log("dispatching", action);
let result = next(action);
console.log("next state", store.getState());
return result;
};
示例9:
) => next => action => {
api.dispatch({ type: 'INCREMENT' })
api.dispatch({ type: 'DECREMENT' })
// typings:expect-error
api.dispatch({ type: 'UNKNOWN' })
}
示例10:
.then(systemApps => store.dispatch(receiveSystemApps(systemApps)));