/** * Copyright 2017, IOOF Holdings Limited. * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ import * as Redux from 'redux'; /** * Store */ export interface MapState{ (state: TParentState, rootState?: TRootState): TSubState; } export enum SubspaceType { ROOT, NAMESPACE_ROOT, CHILD } export interface ProcessActionCallback { (action: Redux.Action): TReturn; } export interface ProcessAction { (action: Redux.Action, callback: ProcessActionCallback): undefined; (action: Redux.Action, callback: ProcessActionCallback, defaultValue: TReturn): TReturn; } export interface SubspaceOptions { enhancer: Redux.StoreEnhancer } export interface StoreWithParent extends Redux.Store { parentStore: Redux.Store; } export interface Subspace extends StoreWithParent { rootStore: Redux.Store; namespace: string; subspaceTypes: SubspaceType[]; processAction: ProcessAction; subspaceOptions: SubspaceOptions; } export interface StoreDecorator> { (store: Redux.Store): TStore; } export interface SubspaceCreator { (mapState: MapState): StoreDecorator>; (mapState: MapState, namespace: string): StoreDecorator>; (mapState: MapState): StoreDecorator>; (mapState: MapState, namespace: string): StoreDecorator>; (namespace: keyof TParentState): StoreDecorator>; (mapState: keyof TParentState, namespace: string): StoreDecorator>; } export const subspace: SubspaceCreator; export function parentSpace(store: StoreWithParent | Redux.Store): Redux.Store; /** * Reducers */ export interface ReducerDecorator { (reducer: Redux.Reducer): Redux.Reducer; } export interface Namespaced { (namespace: string): ReducerDecorator; } export const namespaced: Namespaced; /** * Middleware */ export type GetState = () => TState; export interface GetStateMiddleware { (next: GetState): GetState; } export interface DispatchMiddleware { (next: Redux.Dispatch): Redux.Dispatch; } export interface SubspaceMiddlewareAPI { getState: GetState; dispatch: Redux.Dispatch; rootStore: Redux.Store; namespace: string; subspaceTypes: SubspaceType[]; processAction: ProcessAction; subspaceOptions: SubspaceOptions; } export interface SubspaceMiddleware { (subspace: SubspaceMiddlewareAPI): ({ getState?: GetStateMiddleware, dispatch?: DispatchMiddleware }); } export function applyMiddleware(...middlewares: (SubspaceMiddleware | Redux.Middleware)[]): Redux.StoreEnhancer; export function applyToRoot(middleware: SubspaceMiddleware | Redux.Middleware): SubspaceMiddleware; export function applyToNamespaceRoots(middleware: SubspaceMiddleware | Redux.Middleware): SubspaceMiddleware; export function applyToChildren(middleware: SubspaceMiddleware | Redux.Middleware): SubspaceMiddleware; export function globalActions(...actionTypes: (string | RegExp)[]): SubspaceMiddleware; /** * Actions */ export interface ActionDecorator { (action: TAction): TAction; } export const globalAction: ActionDecorator; export function namespacedAction(namespace: string): ActionDecorator;