@khanacademy/wonder-blocks-data 2.3.2 → 3.0.1

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/es/index.js +210 -439
  3. package/dist/index.js +235 -478
  4. package/docs.md +19 -13
  5. package/package.json +6 -7
  6. package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +40 -160
  7. package/src/__tests__/generated-snapshot.test.js +15 -195
  8. package/src/components/__tests__/data.test.js +159 -965
  9. package/src/components/__tests__/intercept-data.test.js +9 -66
  10. package/src/components/__tests__/track-data.test.js +6 -5
  11. package/src/components/data.js +9 -119
  12. package/src/components/data.md +38 -60
  13. package/src/components/intercept-context.js +2 -3
  14. package/src/components/intercept-data.js +2 -34
  15. package/src/components/intercept-data.md +7 -105
  16. package/src/hooks/__tests__/use-data.test.js +826 -0
  17. package/src/hooks/use-data.js +143 -0
  18. package/src/index.js +1 -3
  19. package/src/util/__tests__/memory-cache.test.js +134 -35
  20. package/src/util/__tests__/request-fulfillment.test.js +21 -36
  21. package/src/util/__tests__/request-handler.test.js +30 -30
  22. package/src/util/__tests__/request-tracking.test.js +29 -30
  23. package/src/util/__tests__/response-cache.test.js +521 -561
  24. package/src/util/__tests__/result-from-cache-entry.test.js +68 -0
  25. package/src/util/memory-cache.js +20 -15
  26. package/src/util/request-fulfillment.js +4 -0
  27. package/src/util/request-handler.js +4 -28
  28. package/src/util/request-handler.md +0 -32
  29. package/src/util/request-tracking.js +2 -3
  30. package/src/util/response-cache.js +50 -110
  31. package/src/util/result-from-cache-entry.js +38 -0
  32. package/src/util/types.js +14 -35
  33. package/LICENSE +0 -21
  34. package/src/components/__tests__/intercept-cache.test.js +0 -124
  35. package/src/components/__tests__/internal-data.test.js +0 -1030
  36. package/src/components/intercept-cache.js +0 -79
  37. package/src/components/intercept-cache.md +0 -103
  38. package/src/components/internal-data.js +0 -219
  39. package/src/util/__tests__/no-cache.test.js +0 -112
  40. package/src/util/no-cache.js +0 -66
  41. package/src/util/no-cache.md +0 -66
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2018 Khan Academy
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,124 +0,0 @@
1
- // @flow
2
- import * as React from "react";
3
- import {mount} from "enzyme";
4
-
5
- import InterceptContext from "../intercept-context.js";
6
- import InterceptData from "../intercept-data.js";
7
- import InterceptCache from "../intercept-cache.js";
8
-
9
- import type {IRequestHandler} from "../../util/types.js";
10
-
11
- describe("InterceptCache", () => {
12
- afterEach(() => {
13
- jest.resetAllMocks();
14
- });
15
-
16
- it("should update context with getEntry", () => {
17
- // Arrange
18
- const fakeHandler: IRequestHandler<string, string> = {
19
- fulfillRequest: () => Promise.resolve("data"),
20
- getKey: (o) => o,
21
- shouldRefreshCache: () => false,
22
- type: "MY_HANDLER",
23
- cache: null,
24
- hydrate: true,
25
- };
26
- const getEntryFn = jest.fn();
27
- const captureContextFn = jest.fn();
28
-
29
- // Act
30
- mount(
31
- <InterceptCache handler={fakeHandler} getEntry={getEntryFn}>
32
- <InterceptContext.Consumer>
33
- {captureContextFn}
34
- </InterceptContext.Consumer>
35
- </InterceptCache>,
36
- );
37
-
38
- // Assert
39
- expect(captureContextFn).toHaveBeenCalledWith(
40
- expect.objectContaining({
41
- MY_HANDLER: {
42
- getEntry: getEntryFn,
43
- },
44
- }),
45
- );
46
- });
47
-
48
- it("should override parent InterceptData", () => {
49
- // Arrange
50
- const fakeHandler: IRequestHandler<string, string> = {
51
- fulfillRequest: () => Promise.resolve("data"),
52
- getKey: (o) => o,
53
- shouldRefreshCache: () => false,
54
- type: "MY_HANDLER",
55
- cache: null,
56
- hydrate: true,
57
- };
58
- const getEntry1Fn = jest.fn();
59
- const getEntry2Fn = jest.fn();
60
- const captureContextFn = jest.fn();
61
-
62
- // Act
63
- mount(
64
- <InterceptCache handler={fakeHandler} getEntry={getEntry1Fn}>
65
- <InterceptCache handler={fakeHandler} getEntry={getEntry2Fn}>
66
- <InterceptContext.Consumer>
67
- {captureContextFn}
68
- </InterceptContext.Consumer>
69
- </InterceptCache>
70
- </InterceptCache>,
71
- );
72
-
73
- // Assert
74
- expect(captureContextFn).toHaveBeenCalledWith(
75
- expect.objectContaining({
76
- MY_HANDLER: {
77
- getEntry: getEntry2Fn,
78
- },
79
- }),
80
- );
81
- });
82
-
83
- it("should not change InterceptData methods on existing interceptor", () => {
84
- // Arrange
85
- const fakeHandler: IRequestHandler<string, string> = {
86
- fulfillRequest: () => Promise.resolve("data"),
87
- getKey: (o) => o,
88
- shouldRefreshCache: () => false,
89
- type: "MY_HANDLER",
90
- cache: null,
91
- hydrate: true,
92
- };
93
- const fulfillRequestFn = jest.fn();
94
- const shouldRefreshCacheFn = jest.fn();
95
- const getEntryFn = jest.fn();
96
- const captureContextFn = jest.fn();
97
-
98
- // Act
99
- mount(
100
- <InterceptData
101
- handler={fakeHandler}
102
- fulfillRequest={fulfillRequestFn}
103
- shouldRefreshCache={shouldRefreshCacheFn}
104
- >
105
- <InterceptCache handler={fakeHandler} getEntry={getEntryFn}>
106
- <InterceptContext.Consumer>
107
- {captureContextFn}
108
- </InterceptContext.Consumer>
109
- </InterceptCache>
110
- </InterceptData>,
111
- );
112
-
113
- // Assert
114
- expect(captureContextFn).toHaveBeenCalledWith(
115
- expect.objectContaining({
116
- MY_HANDLER: {
117
- fulfillRequest: fulfillRequestFn,
118
- shouldRefreshCache: shouldRefreshCacheFn,
119
- getEntry: getEntryFn,
120
- },
121
- }),
122
- );
123
- });
124
- });