resourcerer 2.3.1 → 2.3.2

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.
@@ -87,7 +87,7 @@ export function useResources(getResources, _props) {
87
87
  }
88
88
  });
89
89
  if (Object.keys(nextLoadingStates).some((ky) => nextLoadingStates[ky] !== loadingStates[ky])) {
90
- loaderDispatch({ type: "loading", payload: nextLoadingStates });
90
+ loaderDispatch({ type: "changed", payload: { loadingStates: nextLoadingStates, resources } });
91
91
  }
92
92
  useEffect(() => {
93
93
  if (resourcesToUpdate.length) {
@@ -122,7 +122,7 @@ export function useResources(getResources, _props) {
122
122
  setModels(modelAggregator([[name, config]]));
123
123
  loaderDispatch({
124
124
  type: "error",
125
- payload: { name, status },
125
+ payload: { name, status, resources },
126
126
  });
127
127
  });
128
128
  },
@@ -333,12 +333,12 @@ function partitionResources(resourcesToUpdate, loadingStates) {
333
333
  [memo[0], memo[1].concat([[name, config]])]
334
334
  : [memo[0].concat([[name, config]]), memo[1]], [[], []]);
335
335
  }
336
- function loaderReducer({ loadingStates, requestStatuses, hasInitiallyLoaded }, { type, payload = {} }) {
337
- switch (type) {
336
+ function loaderReducer({ loadingStates, requestStatuses, hasInitiallyLoaded }, action) {
337
+ switch (action.type) {
338
338
  case "error":
339
339
  case "loaded": {
340
- const { name, status, resources } = payload;
341
- let nextLoadingStates = { ...loadingStates, [getResourceState(name)]: type };
340
+ const { name, status, resources } = action.payload;
341
+ const nextLoadingStates = { ...loadingStates, [getResourceState(name)]: action.type };
342
342
  return {
343
343
  loadingStates: nextLoadingStates,
344
344
  requestStatuses: {
@@ -346,17 +346,19 @@ function loaderReducer({ loadingStates, requestStatuses, hasInitiallyLoaded }, {
346
346
  ...(status ? { [getResourceStatus(name)]: status } : {}),
347
347
  },
348
348
  hasInitiallyLoaded: hasInitiallyLoaded ||
349
- (type === "loaded" &&
350
- hasLoaded(getCriticalLoadingStates(nextLoadingStates, resources)) &&
351
- !hasInitiallyLoaded),
349
+ (action.type === "loaded" &&
350
+ hasLoaded(getCriticalLoadingStates(nextLoadingStates, resources))),
352
351
  };
353
352
  }
354
- case "loading":
353
+ case "changed": {
354
+ const { loadingStates: changedLoadingStates, resources } = action.payload;
355
+ const nextLoadingStates = { ...loadingStates, ...changedLoadingStates };
355
356
  return {
356
- loadingStates: { ...loadingStates, ...payload },
357
+ loadingStates: nextLoadingStates,
357
358
  requestStatuses,
358
- hasInitiallyLoaded,
359
+ hasInitiallyLoaded: hasInitiallyLoaded || hasLoaded(getCriticalLoadingStates(nextLoadingStates, resources)),
359
360
  };
361
+ }
360
362
  default:
361
363
  return { loadingStates, requestStatuses, hasInitiallyLoaded };
362
364
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resourcerer",
3
- "version": "2.3.1",
3
+ "version": "2.3.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "github.com/noahgrant/resourcerer"