(
context?: T,
config?: { isServer?: boolean; prefix?: string }
)
| 85 | ) |
| 86 | |
| 87 | const getInitialState = async <T extends { modelName: string | string[] }>( |
| 88 | context?: T, |
| 89 | config?: { isServer?: boolean; prefix?: string } |
| 90 | ) => { |
| 91 | const ServerState: { [name: string]: any } = { __FROM_SERVER__: true } |
| 92 | await Promise.all( |
| 93 | Object.keys(Global.State).map(async (modelName) => { |
| 94 | let prefix = (config && config.prefix) || '' |
| 95 | if ( |
| 96 | !context || |
| 97 | !context.modelName || |
| 98 | modelName === prefix + context.modelName || |
| 99 | context.modelName.indexOf(prefix + modelName) !== -1 |
| 100 | ) { |
| 101 | const asyncGetter = Global.AsyncState[modelName] |
| 102 | const asyncState = asyncGetter ? await asyncGetter(context) : {} |
| 103 | if (config && config.isServer) { |
| 104 | ServerState[modelName] = asyncState |
| 105 | } else { |
| 106 | Global.State = produce(Global.State, (s) => { |
| 107 | s[modelName] = { ...s[modelName], ...asyncState } |
| 108 | }) |
| 109 | } |
| 110 | } |
| 111 | }) |
| 112 | ) |
| 113 | return config && config.isServer ? ServerState : Global.State |
| 114 | } |
| 115 | |
| 116 | const getCache = (modelName: string, actionName: string) => { |
| 117 | const JSONString = localStorage.getItem( |
no outgoing calls
no test coverage detected
searching dependent graphs…