@khanacademy/wonder-blocks-data 14.1.4 → 14.1.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @khanacademy/wonder-blocks-data
2
2
 
3
+ ## 14.1.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 642b5d7: Update docs to provide clearer details on fetch policy behaviors
8
+
9
+ ## 14.1.5
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies [1334e74]
14
+ - @khanacademy/wonder-blocks-core@12.4.0
15
+
3
16
  ## 14.1.4
4
17
 
5
18
  ### Patch Changes
@@ -5,9 +5,27 @@ type CachedEffectOptions<TData extends ValidCacheData> = {
5
5
  * The policy to use when determining how to retrieve the request data from
6
6
  * cache and network.
7
7
  *
8
+ * Inflight requests are shared so that multiple requests for the same
9
+ * resource do not cause multiple fetches while one fetch is already in
10
+ * progress.
11
+ *
12
+ * Network requests update the cache on return, regardless of which policy
13
+ * initiated the request.
14
+ *
15
+ * For fetch policies that use the cache, if the cache does not yet have
16
+ * the data, then a `no-data` status is returned.
17
+ *
18
+ * The `FetchPolicy.NetworkOnly` and `FetchPolicy.CacheAndNetwork` only
19
+ * fetch the data once and then reuse that result, unless a re-fetch is
20
+ * explicitly triggered via the fetch function in the returned tuple.
21
+ *
22
+ * For `FetchPolicy.NetworkOnly`, the cache is ignored (but the cache
23
+ * is still updated with the fetched value). Until a value is available,
24
+ * a `loading` status is returned for this policy.
25
+ *
8
26
  * Defaults to `FetchPolicy.CacheBeforeNetwork`.
9
27
  */
10
- fetchPolicy?: (typeof FetchPolicy)[keyof typeof FetchPolicy];
28
+ fetchPolicy?: FetchPolicy;
11
29
  /**
12
30
  * When `true`, the effect will not be executed; otherwise, the effect will
13
31
  * be executed.
@@ -1,24 +1,43 @@
1
1
  import type { Metadata } from "@khanacademy/wonder-stuff-core";
2
2
  /**
3
3
  * Defines the various fetch policies that can be applied to requests.
4
+ *
5
+ * If a policy fetches from the server, then the cache will be updated with
6
+ * the result of that fetch, once it completes. Inflight fetches are shared
7
+ * so that multiple requests for the same resource do not cause multiple
8
+ * fetches while one fetch is already in progress.
9
+ *
10
+ * It is up to the implementation to decide how to handle cache misses, but
11
+ * most cases likely return a `no-data` or, in the case of a network-only
12
+ * policy, `loading` result, depending on the policy.
4
13
  */
5
14
  export declare enum FetchPolicy {
6
15
  /**
7
- * If the data is in the cache, return that; otherwise, fetch from the
8
- * server.
16
+ * If the data is in the cache, use that data and do not fetch.
17
+ * Otherwise, provide `no-data` while data is fetched from the server.
18
+ *
19
+ * This is usually the policy you want. It means the value is retrieved
20
+ * once and then reused from cache thereafter.
9
21
  */
10
22
  CacheBeforeNetwork = "CacheBeforeNetwork",
11
23
  /**
12
- * If the data is in the cache, return that; always fetch from the server
13
- * regardless of cache.
24
+ * If the data is in the cache, use that data, but also fetch an update
25
+ * from the server if one was not already fetched.
26
+ * Otherwise, provide `no-data` while data is fetched from the server.
27
+ *
28
+ * If there is no cached data, this behaves like `NetworkOnly` while
29
+ * data is being fetched. If there is cached data, this behaves like
30
+ * `CacheOnly` while data is being fetched, and then updates the cache
31
+ * when the fetch completes, before acting like `NetworkOnly` thereafter.
14
32
  */
15
33
  CacheAndNetwork = "CacheAndNetwork",
16
34
  /**
17
- * If the data is in the cache, return that; otherwise, do nothing.
35
+ * If the data is in the cache, use that; otherwise, provide `no-data`.
18
36
  */
19
37
  CacheOnly = "CacheOnly",
20
38
  /**
21
- * Ignore any existing cached result; always fetch from the server.
39
+ * Ignore any existing cached result; fetch data from the server, if it
40
+ * wasn't already fetched. While there is no data, provide `loading`.
22
41
  */
23
42
  NetworkOnly = "NetworkOnly"
24
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-data",
3
- "version": "14.1.4",
3
+ "version": "14.1.6",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -10,7 +10,7 @@
10
10
  "module": "dist/es/index.js",
11
11
  "types": "dist/index.d.ts",
12
12
  "dependencies": {
13
- "@khanacademy/wonder-blocks-core": "12.3.0"
13
+ "@khanacademy/wonder-blocks-core": "12.4.0"
14
14
  },
15
15
  "peerDependencies": {
16
16
  "@khanacademy/wonder-stuff-core": "^1.5.4",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "devDependencies": {
20
20
  "@khanacademy/wonder-stuff-testing": "^3.0.5",
21
- "@khanacademy/wb-dev-build-settings": "3.0.0",
21
+ "@khanacademy/wb-dev-build-settings": "3.2.0",
22
22
  "@khanacademy/wonder-blocks-testing-core": "3.0.1"
23
23
  },
24
24
  "author": "",