import {Middleware} from '../core/Middleware'; import {PromiseAction, Action} from '../core/Action'; import {Store} from '../core/Store'; export const PROMISE_FETCHING = 0x1000000; export const PROMISE_RESOLVED = 0x2000000; export const PROMISE_REJECTED = 0x4000000; export const PROMISE_NOTIFY = 0x8000000; /** * (description) * * @export * @template T * @param {PromiseAction} action (description) * @param {Store} store (description) * @returns {Action} (description) */ export function IntegerPromisify(action: PromiseAction, store: Store): Action { if (typeof action.promise === "undefined") { return action; } action.promise.then(function(data: T) { store.dispatch({ type: PROMISE_RESOLVED | action.type, data: data }); }, function(data: any) { store.dispatch({ type: PROMISE_REJECTED | action.type, data: data }) }, function(data: any) { store.dispatch({ type: PROMISE_NOTIFY | action.type, data: data }); }); return { type: PROMISE_FETCHING | action.type, data: action.data }; }