Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function initAppInstance() {
// we get the snapshot from the server, which is a serializable object
const rootStoreSnapshot = server.getInitialState()
// and hydrate it into a proper object
const rootStore = fromSnapshot(rootStoreSnapshot)
let serverAction = false
const runServerActionLocally = (actionCall: SerializedActionCallWithModelIdOverrides) => {
let wasServerAction = serverAction
serverAction = true
try {
// in clients we use the sync new model ids version to make sure that
// any model ids that were generated in the server side end up being
// the same in the client side
applySerializedActionAndSyncNewModelIds(rootStore, actionCall)
} finally {
serverAction = wasServerAction
}
}
// listen to action messages to be replicated into the local root store