nitro-web 0.0.28 → 0.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client/app.tsx CHANGED
@@ -49,9 +49,8 @@ export async function setupApp(config: Config, storeContainer: StoreContainer, l
49
49
  // Setup the jwt token
50
50
  updateJwt(localStorage.getItem(injectedConfig.jwtName))
51
51
 
52
- // Fetch the store/state
53
- const data = (await settings.beforeApp(config)) || {}
54
- // Make the store data available to the store
52
+ // Fetch the store data, and make it available to the store
53
+ const data = await settings.beforeApp(config)
55
54
  Object.assign(preloadedStoreData, data)
56
55
 
57
56
  const root = ReactDOM.createRoot(document.getElementById('app') as HTMLElement)
@@ -270,8 +269,8 @@ async function beforeApp(config: Config) {
270
269
  * Gets called once before React is initialised
271
270
  * @return {promise} - newStoreData which is used for sharedStore, later merged with the config.store() defaults
272
271
  */
273
- let apiAvailable
274
- let stateData
272
+ let apiAvailable = false
273
+ let storeData = {}
275
274
  try {
276
275
  // Unload prehot data
277
276
  // if (window.prehot) {
@@ -279,14 +278,14 @@ async function beforeApp(config: Config) {
279
278
  // delete window.prehot
280
279
  // }
281
280
  if (!config.isStatic) {
282
- stateData = (await axios().get('/api/state', { 'axios-retry': { retries: 3 }, timeout: 4000 } as AxiosRequestConfig)).data
281
+ storeData = (await axios().get('/api/store', { 'axios-retry': { retries: 3 }, timeout: 4000 } as AxiosRequestConfig)).data
283
282
  apiAvailable = true
284
283
  }
285
284
  } catch (err) {
286
285
  console.error('We had trouble connecting to the API, please refresh')
287
286
  console.log(err)
288
287
  }
289
- return { ...stateData, apiAvailable }
288
+ return { ...storeData, apiAvailable }
290
289
  }
291
290
 
292
291
  const defaultMiddleware = {
package/client/store.ts CHANGED
@@ -4,8 +4,8 @@ import { axios, isObject } from 'nitro-web/util'
4
4
  import { updateJwt } from 'nitro-web'
5
5
  import { Store } from 'nitro-web/types'
6
6
 
7
- export let preloadedStoreData: Store
8
- export let exposedStoreData: Store
7
+ export const preloadedStoreData: Store = {}
8
+ export let exposedStoreData: Store = preloadedStoreData
9
9
 
10
10
  export function createStore<T extends Store>(store: T) {
11
11
  const container = createContainer(() => {