MCPcopy Create free account
hub / github.com/byte-fe/react-model / getInitialState

Function getInitialState

src/helper.ts:87–114  ·  view source on GitHub ↗
(
  context?: T,
  config?: { isServer?: boolean; prefix?: string }
)

Source from the content-addressed store, hash-verified

85 )
86
87const 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
116const getCache = (modelName: string, actionName: string) => {
117 const JSONString = localStorage.getItem(

Callers 4

ModelFunction · 0.90
asyncState.spec.tsFile · 0.85
index.spec.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…