resourcerer 1.0.2 → 1.0.3

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <img src="https://user-images.githubusercontent.com/1355779/61337603-f9fffd80-a7ea-11e9-9cb3-fa82e044c86e.png" alt="Resourcerer Icon" height="200" width="200" />
2
2
 
3
- # resourcerer (now in 1.0-beta!)
3
+ # resourcerer
4
4
 
5
5
  `resourcerer` is a library for declaratively fetching and caching your application's data. Its powerful [`useResources`](#useresources) React hook or [`withResources`](#withresources) higher-order React component (HOC) allows you to easily construct a component's data flow, including:
6
6
 
@@ -499,19 +499,20 @@ function findCacheKey(resource, getResources, props) {
499
499
  * @param {object} props - current component props
500
500
  * @param {LoadingStates} defaultState - state to return if resource already exists in cache;
501
501
  * in most circumstances, this should be the LOADED state as you might expect. However, when we
502
- * prep resources to be re-fetched, in order to keep the loading state in sync with its model
503
- * state, even a cached resource should be temporarily in a LOADING state (if cached, this will
504
- * be corrected in the next microtask and before the JS stack is completed, so the LOADING state
505
- * should never be shown in the UI, despite render being called multiple times).
502
+ * prep resources to be re-fetched or if models were previously created lazily (without fetching),
503
+ * in order to keep the loading state in sync with its model state, even a cached resource should
504
+ * be temporarily in a LOADING state (if cached, this will be corrected in the next microtask and
505
+ * before the JS stack is completed, so the LOADING state should never be shown in the UI, despite
506
+ * render being called multiple times).
506
507
  * @return {object} state object with resource state keys as keys and the loading
507
508
  * state as values
508
509
  */
509
510
  function buildResourcesLoadingState(resources, props, defaultState=LoadingStates.LOADED) {
510
511
  return resources.reduce((state, [name, config]) => Object.assign(state, {
511
- [getResourceState(name)]:
512
- !config.refetch && (shouldBypassFetch(props, [name, config]) || getModelFromCache(config)) ?
513
- defaultState :
514
- (!hasAllDependencies(props, [, config]) ? LoadingStates.PENDING : LoadingStates.LOADING)
512
+ [getResourceState(name)]: !config.refetch && (shouldBypassFetch(props, [name, config]) ||
513
+ (getModelFromCache(config) && !getModelFromCache(config).lazy)) ?
514
+ defaultState :
515
+ (!hasAllDependencies(props, [, config]) ? LoadingStates.PENDING : LoadingStates.LOADING)
515
516
  }), {});
516
517
  }
517
518
 
@@ -683,10 +684,10 @@ function modelAggregator(resources) {
683
684
 
684
685
  /**
685
686
  * Separates out resources between those that are loading and those that have loaded. The latter
686
- * won't need to get passed to fetchResources, but the former will. Make sure that prefetched
687
- * resources get added to those that are loading so that the request gets made. Since prefetched
688
- * models don't factor into loading states, there's no concern that they get passed to
689
- * fetchResources even if they have been cached.
687
+ * won't need to get passed to fetchResources, but the former will. Make sure that prefetched,
688
+ * refetched, and lazy resources get added to those that are loading so that the request gets made.
689
+ * Since prefetched models don't factor into loading states, there's no concern that they get passed
690
+ * to fetchResources even if they have been cached.
690
691
  *
691
692
  * @param {array[]} resourcesToUpdate - resource configs to partition
692
693
  * @param {object} loadingStates - contains upcoming loading states for each resource
@@ -695,7 +696,8 @@ function modelAggregator(resources) {
695
696
  */
696
697
  function partitionResources(resourcesToUpdate, loadingStates) {
697
698
  return resourcesToUpdate.reduce((memo, [name, config]) =>
698
- config.refetch || config.prefetch || !hasLoaded(loadingStates[getResourceState(name)]) ?
699
+ config.refetch || config.prefetch || !hasLoaded(loadingStates[getResourceState(name)]) ||
700
+ getModelFromCache(config)?.lazy ?
699
701
  [memo[0], memo[1].concat([[name, config]])] :
700
702
  [memo[0].concat([[name, config]]), memo[1]],
701
703
  [[], []]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "resourcerer",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "repository": "github.com/noahgrant/resourcerer",
5
5
  "description": "Declarative data-fetching and caching framework for React",
6
6
  "keywords": [