@mapsight/lib-redux 2.0.0

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 (149) hide show
  1. package/README.md +20 -0
  2. package/dist/README.md +20 -0
  3. package/dist/clone-action.d.ts +9 -0
  4. package/dist/clone-action.d.ts.map +1 -0
  5. package/dist/clone-action.js +30 -0
  6. package/dist/clone-action.js.map +1 -0
  7. package/dist/combine-sub-path-reducers.d.ts +13 -0
  8. package/dist/combine-sub-path-reducers.d.ts.map +1 -0
  9. package/dist/combine-sub-path-reducers.js +34 -0
  10. package/dist/combine-sub-path-reducers.js.map +1 -0
  11. package/dist/create-filtered-reducer-for-path.d.ts +13 -0
  12. package/dist/create-filtered-reducer-for-path.d.ts.map +1 -0
  13. package/dist/create-filtered-reducer-for-path.js +37 -0
  14. package/dist/create-filtered-reducer-for-path.js.map +1 -0
  15. package/dist/create-immutable-path-reducer.d.ts +13 -0
  16. package/dist/create-immutable-path-reducer.d.ts.map +1 -0
  17. package/dist/create-immutable-path-reducer.js +30 -0
  18. package/dist/create-immutable-path-reducer.js.map +1 -0
  19. package/dist/create-prefixed-async-action-middleware.d.ts +16 -0
  20. package/dist/create-prefixed-async-action-middleware.d.ts.map +1 -0
  21. package/dist/create-prefixed-async-action-middleware.js +25 -0
  22. package/dist/create-prefixed-async-action-middleware.js.map +1 -0
  23. package/dist/createSelectorUsingOwnProps.d.ts +23 -0
  24. package/dist/createSelectorUsingOwnProps.d.ts.map +1 -0
  25. package/dist/createSelectorUsingOwnProps.js +47 -0
  26. package/dist/createSelectorUsingOwnProps.js.map +1 -0
  27. package/dist/deep-change-state.d.ts +14 -0
  28. package/dist/deep-change-state.d.ts.map +1 -0
  29. package/dist/deep-change-state.js +29 -0
  30. package/dist/deep-change-state.js.map +1 -0
  31. package/dist/enable-async-dispatch.d.ts +13 -0
  32. package/dist/enable-async-dispatch.d.ts.map +1 -0
  33. package/dist/enable-async-dispatch.js +48 -0
  34. package/dist/enable-async-dispatch.js.map +1 -0
  35. package/dist/enable-controlled-dispatch-and-observe.d.ts +21 -0
  36. package/dist/enable-controlled-dispatch-and-observe.d.ts.map +1 -0
  37. package/dist/enable-controlled-dispatch-and-observe.js +59 -0
  38. package/dist/enable-controlled-dispatch-and-observe.js.map +1 -0
  39. package/dist/enable-initialization.d.ts +12 -0
  40. package/dist/enable-initialization.d.ts.map +1 -0
  41. package/dist/enable-initialization.js +25 -0
  42. package/dist/enable-initialization.js.map +1 -0
  43. package/dist/flatten-actions.d.ts +9 -0
  44. package/dist/flatten-actions.d.ts.map +1 -0
  45. package/dist/flatten-actions.js +18 -0
  46. package/dist/flatten-actions.js.map +1 -0
  47. package/dist/index.d.ts +2 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +3 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/local-storage.d.ts +15 -0
  52. package/dist/local-storage.d.ts.map +1 -0
  53. package/dist/local-storage.js +66 -0
  54. package/dist/local-storage.js.map +1 -0
  55. package/dist/matchPath.d.ts +15 -0
  56. package/dist/matchPath.d.ts.map +1 -0
  57. package/dist/matchPath.js +68 -0
  58. package/dist/matchPath.js.map +1 -0
  59. package/dist/matchesPath.d.ts +14 -0
  60. package/dist/matchesPath.d.ts.map +1 -0
  61. package/dist/matchesPath.js +19 -0
  62. package/dist/matchesPath.js.map +1 -0
  63. package/dist/observe-state.d.ts +8 -0
  64. package/dist/observe-state.d.ts.map +1 -0
  65. package/dist/observe-state.js +42 -0
  66. package/dist/observe-state.js.map +1 -0
  67. package/dist/package.json +52 -0
  68. package/dist/reducers/immutable/add-to.d.ts +4 -0
  69. package/dist/reducers/immutable/add-to.d.ts.map +1 -0
  70. package/dist/reducers/immutable/add-to.js +3 -0
  71. package/dist/reducers/immutable/add-to.js.map +1 -0
  72. package/dist/reducers/immutable/index.d.ts +4 -0
  73. package/dist/reducers/immutable/index.d.ts.map +1 -0
  74. package/dist/reducers/immutable/index.js +14 -0
  75. package/dist/reducers/immutable/index.js.map +1 -0
  76. package/dist/reducers/immutable/merge.d.ts +4 -0
  77. package/dist/reducers/immutable/merge.d.ts.map +1 -0
  78. package/dist/reducers/immutable/merge.js +9 -0
  79. package/dist/reducers/immutable/merge.js.map +1 -0
  80. package/dist/reducers/immutable/noop.d.ts +4 -0
  81. package/dist/reducers/immutable/noop.d.ts.map +1 -0
  82. package/dist/reducers/immutable/noop.js +3 -0
  83. package/dist/reducers/immutable/noop.js.map +1 -0
  84. package/dist/reducers/immutable/remove-from.d.ts +4 -0
  85. package/dist/reducers/immutable/remove-from.d.ts.map +1 -0
  86. package/dist/reducers/immutable/remove-from.js +3 -0
  87. package/dist/reducers/immutable/remove-from.js.map +1 -0
  88. package/dist/reducers/immutable/set.d.ts +4 -0
  89. package/dist/reducers/immutable/set.d.ts.map +1 -0
  90. package/dist/reducers/immutable/set.js +3 -0
  91. package/dist/reducers/immutable/set.js.map +1 -0
  92. package/dist/reducers/immutable-path/add-to.d.ts +3 -0
  93. package/dist/reducers/immutable-path/add-to.d.ts.map +1 -0
  94. package/dist/reducers/immutable-path/add-to.js +4 -0
  95. package/dist/reducers/immutable-path/add-to.js.map +1 -0
  96. package/dist/reducers/immutable-path/index.d.ts +11 -0
  97. package/dist/reducers/immutable-path/index.d.ts.map +1 -0
  98. package/dist/reducers/immutable-path/index.js +14 -0
  99. package/dist/reducers/immutable-path/index.js.map +1 -0
  100. package/dist/reducers/immutable-path/merge.d.ts +3 -0
  101. package/dist/reducers/immutable-path/merge.d.ts.map +1 -0
  102. package/dist/reducers/immutable-path/merge.js +4 -0
  103. package/dist/reducers/immutable-path/merge.js.map +1 -0
  104. package/dist/reducers/immutable-path/noop.d.ts +2 -0
  105. package/dist/reducers/immutable-path/noop.d.ts.map +1 -0
  106. package/dist/reducers/immutable-path/noop.js +4 -0
  107. package/dist/reducers/immutable-path/noop.js.map +1 -0
  108. package/dist/reducers/immutable-path/remove-from.d.ts +3 -0
  109. package/dist/reducers/immutable-path/remove-from.d.ts.map +1 -0
  110. package/dist/reducers/immutable-path/remove-from.js +4 -0
  111. package/dist/reducers/immutable-path/remove-from.js.map +1 -0
  112. package/dist/reducers/immutable-path/set.d.ts +3 -0
  113. package/dist/reducers/immutable-path/set.d.ts.map +1 -0
  114. package/dist/reducers/immutable-path/set.js +4 -0
  115. package/dist/reducers/immutable-path/set.js.map +1 -0
  116. package/dist/reducers/reduce-by-keys.d.ts +2 -0
  117. package/dist/reducers/reduce-by-keys.d.ts.map +1 -0
  118. package/dist/reducers/reduce-by-keys.js +14 -0
  119. package/dist/reducers/reduce-by-keys.js.map +1 -0
  120. package/package.json +51 -0
  121. package/src/js/clone-action.ts +36 -0
  122. package/src/js/combine-sub-path-reducers.ts +44 -0
  123. package/src/js/create-filtered-reducer-for-path.ts +52 -0
  124. package/src/js/create-immutable-path-reducer.ts +41 -0
  125. package/src/js/create-prefixed-async-action-middleware.ts +47 -0
  126. package/src/js/createSelectorUsingOwnProps.ts +84 -0
  127. package/src/js/deep-change-state.ts +37 -0
  128. package/src/js/enable-async-dispatch.ts +61 -0
  129. package/src/js/enable-controlled-dispatch-and-observe.ts +128 -0
  130. package/src/js/enable-initialization.ts +36 -0
  131. package/src/js/flatten-actions.ts +22 -0
  132. package/src/js/index.ts +1 -0
  133. package/src/js/local-storage.ts +96 -0
  134. package/src/js/matchPath.ts +78 -0
  135. package/src/js/matchesPath.ts +23 -0
  136. package/src/js/observe-state.ts +109 -0
  137. package/src/js/reducers/immutable/add-to.ts +6 -0
  138. package/src/js/reducers/immutable/index.ts +17 -0
  139. package/src/js/reducers/immutable/merge.ts +18 -0
  140. package/src/js/reducers/immutable/noop.ts +5 -0
  141. package/src/js/reducers/immutable/remove-from.ts +8 -0
  142. package/src/js/reducers/immutable/set.ts +5 -0
  143. package/src/js/reducers/immutable-path/add-to.ts +4 -0
  144. package/src/js/reducers/immutable-path/index.ts +17 -0
  145. package/src/js/reducers/immutable-path/merge.ts +4 -0
  146. package/src/js/reducers/immutable-path/noop.ts +3 -0
  147. package/src/js/reducers/immutable-path/remove-from.ts +4 -0
  148. package/src/js/reducers/immutable-path/set.ts +4 -0
  149. package/src/js/reducers/reduce-by-keys.ts +19 -0
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @mapsight/lib-redux
2
+
3
+ Library of redux helpers code to have them available from different projects and accessible by other internal libraries.
4
+
5
+ ## Getting started
6
+
7
+ TODO
8
+
9
+ ## How to publish
10
+
11
+ - Publish:
12
+
13
+ ```
14
+ git status
15
+ git commit
16
+ npm version x.x.x|major|minor|patch
17
+ npm publish
18
+ git push
19
+ git push --tags
20
+ ```
package/dist/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # @mapsight/lib-redux
2
+
3
+ Library of redux helpers code to have them available from different projects and accessible by other internal libraries.
4
+
5
+ ## Getting started
6
+
7
+ TODO
8
+
9
+ ## How to publish
10
+
11
+ - Publish:
12
+
13
+ ```
14
+ git status
15
+ git commit
16
+ npm version x.x.x|major|minor|patch
17
+ npm publish
18
+ git push
19
+ git push --tags
20
+ ```
@@ -0,0 +1,9 @@
1
+ import { AnyAction } from "redux";
2
+ /**
3
+ * Creates a new action (object or function) with the same content but new reference.
4
+ *
5
+ * @param action action
6
+ * @returns cloned action
7
+ */
8
+ export default function cloneAction<T = AnyAction>(action: T): T;
9
+ //# sourceMappingURL=clone-action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clone-action.d.ts","sourceRoot":"","sources":["../src/js/clone-action.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAMhC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,CAAC,GAAG,SAAS,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAuB/D"}
@@ -0,0 +1,30 @@
1
+ function shallowCloneObject(o) {
2
+ return { ...o };
3
+ }
4
+ /**
5
+ * Creates a new action (object or function) with the same content but new reference.
6
+ *
7
+ * @param action action
8
+ * @returns cloned action
9
+ */
10
+ export default function cloneAction(action) {
11
+ // special case for redux-thunk where the action is a function
12
+ if (typeof action === "function") {
13
+ const newAction = action.bind({});
14
+ if ("meta" in action) {
15
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
16
+ // @ts-ignore
17
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
18
+ newAction.meta = shallowCloneObject(action.meta);
19
+ }
20
+ if (action.name) {
21
+ Object.defineProperty(newAction, "name", {
22
+ value: action.name + "__cloned",
23
+ });
24
+ }
25
+ return newAction;
26
+ }
27
+ // otherwise just make a shallow copy of the plan object action
28
+ return shallowCloneObject(action);
29
+ }
30
+ //# sourceMappingURL=clone-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clone-action.js","sourceRoot":"","sources":["../src/js/clone-action.ts"],"names":[],"mappings":"AAEA,SAAS,kBAAkB,CAAI,CAAI;IAClC,OAAO,EAAC,GAAG,CAAC,EAAC,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAgB,MAAS;IAC3D,8DAA8D;IAC9D,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;QAClC,MAAM,SAAS,GAAM,MAAM,CAAC,IAAI,CAAC,EAAE,CAAM,CAAC;QAE1C,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;YACtB,6DAA6D;YAC7D,aAAa;YACb,mEAAmE;YACnE,SAAS,CAAC,IAAI,GAAG,kBAAkB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAClD,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;YACjB,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE;gBACxC,KAAK,EAAE,MAAM,CAAC,IAAI,GAAG,UAAU;aAC/B,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,+DAA+D;IAC/D,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { AnyAction, Reducer } from "redux";
2
+ /**
3
+ * Combines the given reducers, so they only get actions without a path or
4
+ * a path matching the map key.
5
+ *
6
+ * @param reducerMap a map of reducers and their keys representing their part of the store
7
+ * @param pathKey key of the action parameter that contains the path array
8
+ * @returns combined reducer
9
+ */
10
+ export default function combineSubPathReducers(reducerMap: Record<string, Reducer>, pathKey?: string): Reducer<import("redux").CombinedState<{
11
+ [x: string]: /*elided*/ any;
12
+ }>, AnyAction>;
13
+ //# sourceMappingURL=combine-sub-path-reducers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combine-sub-path-reducers.d.ts","sourceRoot":"","sources":["../src/js/combine-sub-path-reducers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,OAAO,EAAkB,MAAM,OAAO,CAAC;AAI1D;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC7C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,OAAO,SAAS;;eA6BhB"}
@@ -0,0 +1,34 @@
1
+ import { combineReducers } from "redux";
2
+ import cloneAction from "./clone-action";
3
+ /**
4
+ * Combines the given reducers, so they only get actions without a path or
5
+ * a path matching the map key.
6
+ *
7
+ * @param reducerMap a map of reducers and their keys representing their part of the store
8
+ * @param pathKey key of the action parameter that contains the path array
9
+ * @returns combined reducer
10
+ */
11
+ export default function combineSubPathReducers(reducerMap, pathKey = "path") {
12
+ const reducerEntries = Object.entries(reducerMap).map(([name, reducer]) => {
13
+ const wrapperReducer = (state, action) => {
14
+ if (typeof action.meta === "object") {
15
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
16
+ const path = action.meta[pathKey];
17
+ if (Array.isArray(path) && path.length) {
18
+ if (path[0] !== name) {
19
+ return state;
20
+ }
21
+ const controllerAction = cloneAction(action);
22
+ controllerAction[pathKey] = path.slice(1);
23
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
24
+ return reducer(state, controllerAction);
25
+ }
26
+ }
27
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
28
+ return reducer(state, action);
29
+ };
30
+ return [name, wrapperReducer];
31
+ });
32
+ return combineReducers(Object.fromEntries(reducerEntries));
33
+ }
34
+ //# sourceMappingURL=combine-sub-path-reducers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combine-sub-path-reducers.js","sourceRoot":"","sources":["../src/js/combine-sub-path-reducers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,eAAe,EAAC,MAAM,OAAO,CAAC;AAE1D,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC7C,UAAmC,EACnC,OAAO,GAAG,MAAM;IAEhB,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE;QACzE,MAAM,cAAc,GAAG,CAAI,KAAQ,EAAE,MAAiB,EAAO,EAAE;YAC9D,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;gBACrC,8GAA8G;gBAC9G,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBAElC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;oBACxC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;wBACtB,OAAO,KAAK,CAAC;oBACd,CAAC;oBAED,MAAM,gBAAgB,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;oBAC7C,gBAAgB,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;oBAE1C,+DAA+D;oBAC/D,OAAO,OAAO,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;gBACzC,CAAC;YACF,CAAC;YAED,+DAA+D;YAC/D,OAAO,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC/B,CAAC,CAAC;QAEF,OAAO,CAAC,IAAI,EAAE,cAAc,CAAU,CAAC;IACxC,CAAC,CAAC,CAAC;IAEH,OAAO,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { Reducer } from "redux";
2
+ /**
3
+ * Filters the actions, so the reducer only gets actions without a path or
4
+ * a path matching the given key.
5
+ *
6
+ * @param reducer the base reducer that should get filtered actions only
7
+ * @param key key of the action parameter that contains the path array
8
+ * @param [statePathMetaKey] name of the meta field that contains the path array (action.meta.path), default: 'path'
9
+ * @returns resulting reducer
10
+ */
11
+ declare function createFilteredReducerForPath(reducer: Reducer, key: string, statePathMetaKey?: string): Reducer;
12
+ export default createFilteredReducerForPath;
13
+ //# sourceMappingURL=create-filtered-reducer-for-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-filtered-reducer-for-path.d.ts","sourceRoot":"","sources":["../src/js/create-filtered-reducer-for-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,OAAO,EAAC,MAAM,OAAO,CAAC;AAIzC;;;;;;;;GAQG;AACH,iBAAS,4BAA4B,CACpC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,MAAM,EACX,gBAAgB,SAAS,GACvB,OAAO,CAgCT;AAED,eAAe,4BAA4B,CAAC"}
@@ -0,0 +1,37 @@
1
+ import cloneAction from "./clone-action";
2
+ /**
3
+ * Filters the actions, so the reducer only gets actions without a path or
4
+ * a path matching the given key.
5
+ *
6
+ * @param reducer the base reducer that should get filtered actions only
7
+ * @param key key of the action parameter that contains the path array
8
+ * @param [statePathMetaKey] name of the meta field that contains the path array (action.meta.path), default: 'path'
9
+ * @returns resulting reducer
10
+ */
11
+ function createFilteredReducerForPath(reducer, key, statePathMetaKey = "path") {
12
+ const filteredReducer = (state, action) => {
13
+ if (typeof action.meta === "object") {
14
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
15
+ const path = action.meta[statePathMetaKey];
16
+ if (Array.isArray(path) && path.length) {
17
+ if (path[0] !== key) {
18
+ return state;
19
+ }
20
+ const slicedAction = cloneAction(action);
21
+ slicedAction[statePathMetaKey] = path.slice(1);
22
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
23
+ return reducer(state, slicedAction);
24
+ }
25
+ }
26
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
27
+ return reducer(state, action);
28
+ };
29
+ if (reducer.name) {
30
+ Object.defineProperty(filteredReducer, "name", {
31
+ value: reducer.name + "__filtered-by-path",
32
+ });
33
+ }
34
+ return filteredReducer;
35
+ }
36
+ export default createFilteredReducerForPath;
37
+ //# sourceMappingURL=create-filtered-reducer-for-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-filtered-reducer-for-path.js","sourceRoot":"","sources":["../src/js/create-filtered-reducer-for-path.ts"],"names":[],"mappings":"AAEA,OAAO,WAAW,MAAM,gBAAgB,CAAC;AAEzC;;;;;;;;GAQG;AACH,SAAS,4BAA4B,CACpC,OAAgB,EAChB,GAAW,EACX,gBAAgB,GAAG,MAAM;IAEzB,MAAM,eAAe,GAAY,CAChC,KAAQ,EACR,MAAiB,EAChB,EAAE;QACH,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACrC,8GAA8G;YAC9G,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YAC3C,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBACxC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;oBACrB,OAAO,KAAK,CAAC;gBACd,CAAC;gBAED,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;gBACzC,YAAY,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAE/C,+DAA+D;gBAC/D,OAAO,OAAO,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;YACrC,CAAC;QACF,CAAC;QAED,+DAA+D;QAC/D,OAAO,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC/B,CAAC,CAAC;IAEF,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QAClB,MAAM,CAAC,cAAc,CAAC,eAAe,EAAE,MAAM,EAAE;YAC9C,KAAK,EAAE,OAAO,CAAC,IAAI,GAAG,oBAAoB;SAC1C,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,eAAe,CAAC;AACxB,CAAC;AAED,eAAe,4BAA4B,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { Reducer } from "redux";
2
+ /**
3
+ * Creates a new reducer, that replaces an value at the given path using the given reducer,
4
+ * replacing all parent objects, instead of mutating the existing object(s).
5
+ *
6
+ * The given reducer has to work immutable as well to get the full desired effect!
7
+ *
8
+ * @param reducer reducer to reduce the value at the path
9
+ * @param [pathKey] path in the object to reduce, default: 'path'
10
+ * @returns resulting immutable path reducer
11
+ */
12
+ export default function createImmutablePathReducer(reducer: Reducer, pathKey?: string): Reducer;
13
+ //# sourceMappingURL=create-immutable-path-reducer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-immutable-path-reducer.d.ts","sourceRoot":"","sources":["../src/js/create-immutable-path-reducer.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,OAAO,EAAC,MAAM,OAAO,CAAC;AAIzC;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,0BAA0B,CACjD,OAAO,EAAE,OAAO,EAChB,OAAO,SAAS,GACd,OAAO,CAsBT"}
@@ -0,0 +1,30 @@
1
+ import get from "lodash/get";
2
+ import deepChangeState from "./deep-change-state";
3
+ /**
4
+ * Creates a new reducer, that replaces an value at the given path using the given reducer,
5
+ * replacing all parent objects, instead of mutating the existing object(s).
6
+ *
7
+ * The given reducer has to work immutable as well to get the full desired effect!
8
+ *
9
+ * @param reducer reducer to reduce the value at the path
10
+ * @param [pathKey] path in the object to reduce, default: 'path'
11
+ * @returns resulting immutable path reducer
12
+ */
13
+ export default function createImmutablePathReducer(reducer, pathKey = "path") {
14
+ // noinspection UnnecessaryLocalVariableJS
15
+ const immutablePathReducer = (state, action) => {
16
+ const path = action[pathKey];
17
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
18
+ const oldValue = (path?.length ? get(state, path) : state);
19
+ const newValue = reducer(oldValue, action);
20
+ if (newValue === oldValue) {
21
+ return state;
22
+ }
23
+ return deepChangeState(state, path, newValue);
24
+ };
25
+ //if (reducer.name) {
26
+ // Object.defineProperty(aImmutablePathReducer, 'name', {value: reducer.name + '__immutable-path'});
27
+ //}
28
+ return immutablePathReducer;
29
+ }
30
+ //# sourceMappingURL=create-immutable-path-reducer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-immutable-path-reducer.js","sourceRoot":"","sources":["../src/js/create-immutable-path-reducer.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAG7B,OAAO,eAAe,MAAM,qBAAqB,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,0BAA0B,CACjD,OAAgB,EAChB,OAAO,GAAG,MAAM;IAEhB,0CAA0C;IAC1C,MAAM,oBAAoB,GAAY,CACrC,KAAQ,EACR,MAAiB,EACb,EAAE;QACN,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAkB,CAAC;QAC9C,6DAA6D;QAC7D,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAM,CAAC;QAChE,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAM,CAAC;QAChD,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC3B,OAAO,KAAK,CAAC;QACd,CAAC;QAED,OAAO,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC/C,CAAC,CAAC;IAEF,qBAAqB;IACrB,oGAAoG;IACpG,GAAG;IAEH,OAAO,oBAAoB,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Creates a redux middleware that allows dispatching of functions as actions, when the action
3
+ * exposes the defined actionFlag. If a prefix is provided, the action function will receive a
4
+ * prefixed getState, meaning it will retrieve the sub store with the prefix key (store.getState()[prefix]).
5
+ *
6
+ * Works similar to thunk, but with additional flag and optional sub store getState.
7
+ *
8
+ * @param [actionFlag] action flag, default: 'isAsync'
9
+ * @param [prefix] prefix state prefix
10
+ * @param [extraArgument] extra argument to be passed to action function
11
+ *
12
+ * @returns {function(*=): function(*): Function} resulting middleware
13
+ */
14
+ import { Middleware } from "redux";
15
+ export default function createPrefixedAsyncActionMiddleware<Prefix extends string | undefined>(actionFlag?: string, prefix?: Prefix, extraArgument?: unknown): Middleware;
16
+ //# sourceMappingURL=create-prefixed-async-action-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-prefixed-async-action-middleware.d.ts","sourceRoot":"","sources":["../src/js/create-prefixed-async-action-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAC,UAAU,EAAgB,MAAM,OAAO,CAAC;AAEhD,MAAM,CAAC,OAAO,UAAU,mCAAmC,CAC1D,MAAM,SAAS,MAAM,GAAG,SAAS,EAEjC,UAAU,SAAY,EACtB,MAAM,CAAC,EAAE,MAAM,EACf,aAAa,GAAE,OAAmB,GAChC,UAAU,CAyBZ"}
@@ -0,0 +1,25 @@
1
+ export default function createPrefixedAsyncActionMiddleware(actionFlag = "isAsync", prefix, extraArgument = undefined) {
2
+ return function prefixedAsyncActionMiddleware(api) {
3
+ // eslint-disable-next-line @typescript-eslint/unbound-method
4
+ let getState = api.getState;
5
+ if (typeof prefix === "string") {
6
+ // eslint-disable-next-line @typescript-eslint/unbound-method
7
+ const baseGetState = api.getState;
8
+ getState = function getStateWithPrefix() {
9
+ return baseGetState()[prefix];
10
+ };
11
+ }
12
+ return function (next) {
13
+ return function prefixedAsyncActionMiddlewareWithAction(action) {
14
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
15
+ if (typeof action === "function" && action.meta?.[actionFlag]) {
16
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
17
+ return action(api.dispatch, getState, extraArgument);
18
+ }
19
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
20
+ return next(action);
21
+ };
22
+ };
23
+ };
24
+ }
25
+ //# sourceMappingURL=create-prefixed-async-action-middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-prefixed-async-action-middleware.js","sourceRoot":"","sources":["../src/js/create-prefixed-async-action-middleware.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,OAAO,UAAU,mCAAmC,CAG1D,UAAU,GAAG,SAAS,EACtB,MAAe,EACf,gBAAyB,SAAS;IAElC,OAAO,SAAS,6BAA6B,CAAC,GAAkB;QAC/D,6DAA6D;QAC7D,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;QAC5B,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAChC,6DAA6D;YAC7D,MAAM,YAAY,GAAG,GAAG,CAAC,QAAyC,CAAC;YACnE,QAAQ,GAAG,SAAS,kBAAkB;gBACrC,OAAO,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC;YAC/B,CAAC,CAAC;QACH,CAAC;QAED,OAAO,UAAU,IAAI;YACpB,OAAO,SAAS,uCAAuC,CAAC,MAAM;gBAC7D,sEAAsE;gBACtE,IAAI,OAAO,MAAM,KAAK,UAAU,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;oBAC/D,iGAAiG;oBACjG,OAAO,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;gBACtD,CAAC;gBAED,+DAA+D;gBAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;YACrB,CAAC,CAAC;QACH,CAAC,CAAC;IACH,CAAC,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ declare function strictEqualityComparison<T>(a: T, b: T): boolean;
2
+ export type SelectorUsingPropsOptions = {
3
+ equals?: typeof strictEqualityComparison;
4
+ };
5
+ type OwnPropsSelector<OwnProps, T = unknown> = (ownProps: OwnProps) => T;
6
+ type SelectorWithOwnProps<OwnProps extends Array<unknown> = Array<unknown>, State = unknown, Value = unknown> = (state: State, ownProps: OwnProps) => Value;
7
+ type SelectorFactory<OwnProps extends Array<unknown> = Array<unknown>, State = unknown, Value = unknown> = (...selectedValues: unknown[]) => SelectorWithOwnProps<OwnProps, State, Value>;
8
+ /**
9
+ * Create a selector whenever some (own) properties change. To be used with react-redux's connect() mapState.
10
+ *
11
+ * @param ownPropsSelectorOrSelectors one selector function or an array of selector functions that receive
12
+ * the ownProps and should return one property value that will be used to determine changes
13
+ * @param selectorFactory factory function receives the selected props as arguments followed by the state and
14
+ * ownProps at the time of invalidation
15
+ * @param [options] optional options
16
+ * @param [options.equals] function that check equality, defaults to strict equality (===)
17
+ * @returns selector function to be used as mapState in react-redux's connect() function.
18
+ * May be combined with createSelector/createStructuredSelector or any other function as
19
+ * long as the selector is called with state as first and own props as second argument.
20
+ */
21
+ export default function createSelectorUsingOwnProps<State = unknown, Value = unknown, OwnProps extends Array<unknown> = Array<unknown>>(ownPropsSelectorOrSelectors: OwnPropsSelector<OwnProps> | Array<OwnPropsSelector<OwnProps>>, selectorFactory: SelectorFactory<OwnProps, State, Value>, options?: SelectorUsingPropsOptions): (state: State, ownProps: OwnProps) => Value;
22
+ export {};
23
+ //# sourceMappingURL=createSelectorUsingOwnProps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createSelectorUsingOwnProps.d.ts","sourceRoot":"","sources":["../src/js/createSelectorUsingOwnProps.ts"],"names":[],"mappings":"AAAA,iBAAS,wBAAwB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,CAExD;AAED,MAAM,MAAM,yBAAyB,GAAG;IACvC,MAAM,CAAC,EAAE,OAAO,wBAAwB,CAAC;CACzC,CAAC;AAEF,KAAK,gBAAgB,CAAC,QAAQ,EAAE,CAAC,GAAG,OAAO,IAAI,CAAC,QAAQ,EAAE,QAAQ,KAAK,CAAC,CAAC;AAEzE,KAAK,oBAAoB,CACxB,QAAQ,SAAS,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,EAChD,KAAK,GAAG,OAAO,EACf,KAAK,GAAG,OAAO,IACZ,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,KAAK,KAAK,CAAC;AAChD,KAAK,eAAe,CACnB,QAAQ,SAAS,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,EAChD,KAAK,GAAG,OAAO,EACf,KAAK,GAAG,OAAO,IACZ,CACH,GAAG,cAAc,EAAE,OAAO,EAAE,KACxB,oBAAoB,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAElD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,2BAA2B,CAClD,KAAK,GAAG,OAAO,EACf,KAAK,GAAG,OAAO,EACf,QAAQ,SAAS,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,EAEhD,2BAA2B,EACxB,gBAAgB,CAAC,QAAQ,CAAC,GAC1B,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,EACpC,eAAe,EAAE,eAAe,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,EACxD,OAAO,GAAE,yBAA8B,IAkCd,OAAO,KAAK,EAAE,UAAU,QAAQ,KAAG,KAAK,CAIjE"}
@@ -0,0 +1,47 @@
1
+ function strictEqualityComparison(a, b) {
2
+ return a === b;
3
+ }
4
+ /**
5
+ * Create a selector whenever some (own) properties change. To be used with react-redux's connect() mapState.
6
+ *
7
+ * @param ownPropsSelectorOrSelectors one selector function or an array of selector functions that receive
8
+ * the ownProps and should return one property value that will be used to determine changes
9
+ * @param selectorFactory factory function receives the selected props as arguments followed by the state and
10
+ * ownProps at the time of invalidation
11
+ * @param [options] optional options
12
+ * @param [options.equals] function that check equality, defaults to strict equality (===)
13
+ * @returns selector function to be used as mapState in react-redux's connect() function.
14
+ * May be combined with createSelector/createStructuredSelector or any other function as
15
+ * long as the selector is called with state as first and own props as second argument.
16
+ */
17
+ export default function createSelectorUsingOwnProps(ownPropsSelectorOrSelectors, selectorFactory, options = {}) {
18
+ const equals = options.equals || strictEqualityComparison;
19
+ let propsCache;
20
+ let cachedSelector;
21
+ const ownPropsSelectors = Array.isArray(ownPropsSelectorOrSelectors)
22
+ ? ownPropsSelectorOrSelectors
23
+ : [ownPropsSelectorOrSelectors];
24
+ function updateSelector(state, ownProps) {
25
+ let hasChanged = false;
26
+ if (!propsCache) {
27
+ propsCache = new Array(ownPropsSelectorOrSelectors.length);
28
+ hasChanged = true;
29
+ }
30
+ ownPropsSelectors.forEach(function updateProps(ownPropsSelector, i) {
31
+ const prev = propsCache[i];
32
+ const next = ownPropsSelector(ownProps);
33
+ if (!hasChanged && !equals(prev, next)) {
34
+ hasChanged = true;
35
+ }
36
+ propsCache[i] = next;
37
+ });
38
+ if (hasChanged || !cachedSelector) {
39
+ cachedSelector = selectorFactory(...propsCache, state, ownProps);
40
+ }
41
+ }
42
+ return function selector(state, ownProps) {
43
+ updateSelector(state, ownProps);
44
+ return cachedSelector(state, ownProps);
45
+ };
46
+ }
47
+ //# sourceMappingURL=createSelectorUsingOwnProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createSelectorUsingOwnProps.js","sourceRoot":"","sources":["../src/js/createSelectorUsingOwnProps.ts"],"names":[],"mappings":"AAAA,SAAS,wBAAwB,CAAI,CAAI,EAAE,CAAI;IAC9C,OAAO,CAAC,KAAK,CAAC,CAAC;AAChB,CAAC;AAqBD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,UAAU,2BAA2B,CAKlD,2BAEoC,EACpC,eAAwD,EACxD,UAAqC,EAAE;IAEvC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,wBAAwB,CAAC;IAC1D,IAAI,UAA0B,CAAC;IAC/B,IAAI,cAA4D,CAAC;IAEjE,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,2BAA2B,CAAC;QACnE,CAAC,CAAC,2BAA2B;QAC7B,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC;IAEjC,SAAS,cAAc,CAAC,KAAY,EAAE,QAAkB;QACvD,IAAI,UAAU,GAAG,KAAK,CAAC;QAEvB,IAAI,CAAC,UAAU,EAAE,CAAC;YACjB,UAAU,GAAG,IAAI,KAAK,CAAC,2BAA2B,CAAC,MAAM,CAAC,CAAC;YAC3D,UAAU,GAAG,IAAI,CAAC;QACnB,CAAC;QAED,iBAAiB,CAAC,OAAO,CAAC,SAAS,WAAW,CAAC,gBAAgB,EAAE,CAAC;YACjE,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YAC3B,MAAM,IAAI,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YAExC,IAAI,CAAC,UAAU,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;gBACxC,UAAU,GAAG,IAAI,CAAC;YACnB,CAAC;YAED,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;QACtB,CAAC,CAAC,CAAC;QAEH,IAAI,UAAU,IAAI,CAAC,cAAc,EAAE,CAAC;YACnC,cAAc,GAAG,eAAe,CAAC,GAAG,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QAClE,CAAC;IACF,CAAC;IAED,OAAO,SAAS,QAAQ,CAAC,KAAY,EAAE,QAAkB;QACxD,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAChC,OAAO,cAAc,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC,CAAC;AACH,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Creates a new state from {state} with the value at the {path} changed to the given {value} and
3
+ * reassigns all objects down along the path of the change so they aren't strictly equal anymore
4
+ * and can be easily observed as changed by redux/react.
5
+ *
6
+ * **Note:** Returns a new state object! Does NOT mutate the original state object!
7
+ *
8
+ * @param {object} state The original state
9
+ * @param {*[]|string} [path] The path at which the change gets applied.
10
+ * @param {*} [value] The new value to be set (or undefined).
11
+ * @returns {*} The new state with changed value and new objects along the path.
12
+ */
13
+ export default function deepChangeState<State = unknown, Value = unknown>(state: State, path: Array<string>, value: Value): State | Value;
14
+ //# sourceMappingURL=deep-change-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-change-state.d.ts","sourceRoot":"","sources":["../src/js/deep-change-state.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO,EACvE,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,EACnB,KAAK,EAAE,KAAK,iBAeZ"}
@@ -0,0 +1,29 @@
1
+ import setWith from "lodash/setWith";
2
+ function shallowCloneObject(o) {
3
+ return { ...o };
4
+ }
5
+ /**
6
+ * Creates a new state from {state} with the value at the {path} changed to the given {value} and
7
+ * reassigns all objects down along the path of the change so they aren't strictly equal anymore
8
+ * and can be easily observed as changed by redux/react.
9
+ *
10
+ * **Note:** Returns a new state object! Does NOT mutate the original state object!
11
+ *
12
+ * @param {object} state The original state
13
+ * @param {*[]|string} [path] The path at which the change gets applied.
14
+ * @param {*} [value] The new value to be set (or undefined).
15
+ * @returns {*} The new state with changed value and new objects along the path.
16
+ */
17
+ export default function deepChangeState(state, path, value) {
18
+ const hasPath = path?.length;
19
+ if (!hasPath) {
20
+ return value;
21
+ }
22
+ const newState = shallowCloneObject(state);
23
+ if (newState && typeof newState === "object") {
24
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
25
+ setWith(newState, path, value, shallowCloneObject);
26
+ }
27
+ return newState;
28
+ }
29
+ //# sourceMappingURL=deep-change-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-change-state.js","sourceRoot":"","sources":["../src/js/deep-change-state.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,gBAAgB,CAAC;AAErC,SAAS,kBAAkB,CAAI,CAAI;IAClC,OAAO,EAAC,GAAG,CAAC,EAAC,CAAC;AACf,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CACtC,KAAY,EACZ,IAAmB,EACnB,KAAY;IAEZ,MAAM,OAAO,GAAG,IAAI,EAAE,MAAM,CAAC;IAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACd,OAAO,KAAK,CAAC;IACd,CAAC;IAED,MAAM,QAAQ,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAE3C,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC9C,6DAA6D;QAC7D,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;IACpD,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { Store } from "redux";
2
+ /**
3
+ * Enhances the stores dispatch function, so you can dispatch actions flagged as async.
4
+ * This allows "dispatching while dispatching" by queueing actions that are dispatched while dispatching is already
5
+ * in progress and dispatching them after finishing with the current action.
6
+ *
7
+ * The action is guaranteed to be dispatched asynchronously in any case (even when dispatching is possible immediately).
8
+ *
9
+ * @param store redux store to be enhanced (having dispatch)
10
+ * @param asyncActionFlag flag that async actions expose (action[actionFlag] == true)
11
+ */
12
+ export default function enableAsyncDispatch(store: Store, asyncActionFlag?: string | symbol): void;
13
+ //# sourceMappingURL=enable-async-dispatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enable-async-dispatch.d.ts","sourceRoot":"","sources":["../src/js/enable-async-dispatch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,EAAC,MAAM,OAAO,CAAC;AAUvC;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAC1C,KAAK,EAAE,KAAK,EACZ,eAAe,GAAE,MAAM,GAAG,MAAkB,QAsC5C"}
@@ -0,0 +1,48 @@
1
+ function runAsync(fn) {
2
+ return setTimeout(() => fn(), 10);
3
+ }
4
+ function isRecord(val) {
5
+ return typeof val === "object" && val !== null;
6
+ }
7
+ /**
8
+ * Enhances the stores dispatch function, so you can dispatch actions flagged as async.
9
+ * This allows "dispatching while dispatching" by queueing actions that are dispatched while dispatching is already
10
+ * in progress and dispatching them after finishing with the current action.
11
+ *
12
+ * The action is guaranteed to be dispatched asynchronously in any case (even when dispatching is possible immediately).
13
+ *
14
+ * @param store redux store to be enhanced (having dispatch)
15
+ * @param asyncActionFlag flag that async actions expose (action[actionFlag] == true)
16
+ */
17
+ export default function enableAsyncDispatch(store, asyncActionFlag = "isAsync") {
18
+ // This function will override the store.dispatch method, deferring the actual dispatch of actions flagged as
19
+ // async by queueing them and only dispatching them in the next microtask by scheduling them with setTimeout.
20
+ let isAsyncScheduled = false;
21
+ const actionQueue = [];
22
+ const baseDispatch = store.dispatch;
23
+ function isActionAsync(action) {
24
+ return isRecord(action.meta) && !!action.meta[asyncActionFlag];
25
+ }
26
+ function runScheduleAsyncDispatch() {
27
+ isAsyncScheduled = false;
28
+ while (actionQueue.length) {
29
+ const action = actionQueue.shift();
30
+ baseDispatch(action);
31
+ }
32
+ }
33
+ function scheduleAsyncDispatch() {
34
+ if (!isAsyncScheduled) {
35
+ isAsyncScheduled = true;
36
+ runAsync(runScheduleAsyncDispatch);
37
+ }
38
+ }
39
+ store.dispatch = (action) => {
40
+ if (isActionAsync(action)) {
41
+ actionQueue.push(action);
42
+ scheduleAsyncDispatch();
43
+ return action;
44
+ }
45
+ return baseDispatch(action);
46
+ };
47
+ }
48
+ //# sourceMappingURL=enable-async-dispatch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enable-async-dispatch.js","sourceRoot":"","sources":["../src/js/enable-async-dispatch.ts"],"names":[],"mappings":"AAEA,SAAS,QAAQ,CAAC,EAAc;IAC/B,OAAO,UAAU,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,QAAQ,CAAC,GAAY;IAC7B,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI,CAAC;AAChD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,mBAAmB,CAC1C,KAAY,EACZ,kBAAmC,SAAS;IAE5C,6GAA6G;IAC7G,6GAA6G;IAC7G,IAAI,gBAAgB,GAAG,KAAK,CAAC;IAC7B,MAAM,WAAW,GAAqB,EAAE,CAAC;IAEzC,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC;IAEpC,SAAS,aAAa,CAAC,MAAiB;QACvC,OAAO,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAChE,CAAC;IAED,SAAS,wBAAwB;QAChC,gBAAgB,GAAG,KAAK,CAAC;QAEzB,OAAO,WAAW,CAAC,MAAM,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,EAAe,CAAC;YAChD,YAAY,CAAC,MAAM,CAAC,CAAC;QACtB,CAAC;IACF,CAAC;IAED,SAAS,qBAAqB;QAC7B,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACvB,gBAAgB,GAAG,IAAI,CAAC;YACxB,QAAQ,CAAC,wBAAwB,CAAC,CAAC;QACpC,CAAC;IACF,CAAC;IAED,KAAK,CAAC,QAAQ,GAAG,CAAC,MAAM,EAAE,EAAE;QAC3B,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACzB,qBAAqB,EAAE,CAAC;YACxB,OAAO,MAAM,CAAC;QACf,CAAC;QAED,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { Store } from "redux";
2
+ type CompareFunction = (a: unknown, b: unknown) => boolean;
3
+ type UncontrolledActionListener<State = unknown> = (previousState: State, state: State) => void;
4
+ type SubscribeUncontrolled<State = unknown> = (listener: UncontrolledActionListener<State>) => () => void;
5
+ export type ObserveHandler<State = unknown, Value = unknown> = (newValue?: Value, previousValue?: Value, state?: State) => void;
6
+ export type ObserveUncontrolled<State = unknown, Value = unknown> = (selector: (state: State) => Value, onChange: ObserveHandler<State, Value>, compare?: CompareFunction) => () => void;
7
+ export type StoreExtControlledActions<TState = unknown> = {
8
+ subscribeUncontrolled: SubscribeUncontrolled<TState>;
9
+ observeUncontrolled: ObserveUncontrolled<TState>;
10
+ };
11
+ export type StoreWithControlledActions<S extends Store = Store, TState = unknown> = S & StoreExtControlledActions<TState>;
12
+ /**
13
+ * Enhances the store. Allows actions to be flagged as controlled and adds a new function
14
+ * store.observeUncontrolled(selector, onChange, compare) to the store.
15
+ *
16
+ * @param {object} store redux store
17
+ * @param {string|symbol} controlledActionFlag flag that controlled actions expose (action[controlledActionFlag] == true)
18
+ */
19
+ export default function enableControlledDispatchAndObserve<State = unknown>(store: Store<State>, controlledActionFlag?: string): void;
20
+ export {};
21
+ //# sourceMappingURL=enable-controlled-dispatch-and-observe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enable-controlled-dispatch-and-observe.d.ts","sourceRoot":"","sources":["../src/js/enable-controlled-dispatch-and-observe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,EAAC,MAAM,OAAO,CAAC;AAEjD,KAAK,eAAe,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;AAI3D,KAAK,0BAA0B,CAAC,KAAK,GAAG,OAAO,IAAI,CAClD,aAAa,EAAE,KAAK,EACpB,KAAK,EAAE,KAAK,KACR,IAAI,CAAC;AACV,KAAK,qBAAqB,CAAC,KAAK,GAAG,OAAO,IAAI,CAC7C,QAAQ,EAAE,0BAA0B,CAAC,KAAK,CAAC,KACvC,MAAM,IAAI,CAAC;AAEhB,MAAM,MAAM,cAAc,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO,IAAI,CAC9D,QAAQ,CAAC,EAAE,KAAK,EAChB,aAAa,CAAC,EAAE,KAAK,EACrB,KAAK,CAAC,EAAE,KAAK,KACT,IAAI,CAAC;AAEV,MAAM,MAAM,mBAAmB,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,GAAG,OAAO,IAAI,CACnE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,KAAK,EACjC,QAAQ,EAAE,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,EACtC,OAAO,CAAC,EAAE,eAAe,KACrB,MAAM,IAAI,CAAC;AAEhB,MAAM,MAAM,yBAAyB,CAAC,MAAM,GAAG,OAAO,IAAI;IACzD,qBAAqB,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACrD,mBAAmB,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,0BAA0B,CACrC,CAAC,SAAS,KAAK,GAAG,KAAK,EACvB,MAAM,GAAG,OAAO,IACb,CAAC,GAAG,yBAAyB,CAAC,MAAM,CAAC,CAAC;AAiB1C;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kCAAkC,CAAC,KAAK,GAAG,OAAO,EACzE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,EACnB,oBAAoB,SAAiB,QAmErC"}
@@ -0,0 +1,59 @@
1
+ const strictEqualCompare = (a, b) => a === b;
2
+ function isActionWithMeta(action) {
3
+ return "meta" in action;
4
+ }
5
+ function isControlledAction(action, controlledActionFlag) {
6
+ return (isActionWithMeta(action) && action.meta?.[controlledActionFlag] === true);
7
+ }
8
+ /**
9
+ * Enhances the store. Allows actions to be flagged as controlled and adds a new function
10
+ * store.observeUncontrolled(selector, onChange, compare) to the store.
11
+ *
12
+ * @param {object} store redux store
13
+ * @param {string|symbol} controlledActionFlag flag that controlled actions expose (action[controlledActionFlag] == true)
14
+ */
15
+ export default function enableControlledDispatchAndObserve(store, controlledActionFlag = "isControlled") {
16
+ let listeners = [];
17
+ function removeListener(listener) {
18
+ listeners = listeners.filter((l) => l !== listener);
19
+ }
20
+ function addListener(listener) {
21
+ listeners.push(listener);
22
+ }
23
+ const subscribeUncontrolled = (listener) => {
24
+ addListener(listener);
25
+ return function removeListenerBound() {
26
+ removeListener(listener);
27
+ };
28
+ };
29
+ const observeUncontrolled = (selector, onChange, compare = strictEqualCompare) => subscribeUncontrolled(function handleUncontrolledChange(previousState, state) {
30
+ const previousValue = selector(previousState);
31
+ const newValue = selector(state);
32
+ if (!compare(previousValue, newValue)) {
33
+ onChange(newValue, previousValue, state);
34
+ }
35
+ });
36
+ let wasControlled = false;
37
+ const baseDispatch = store.dispatch;
38
+ const enhancedDispatch = (action) => {
39
+ wasControlled = isControlledAction(action, controlledActionFlag);
40
+ return baseDispatch(action);
41
+ };
42
+ let previousState = store.getState();
43
+ function listenForUncontrolledActions() {
44
+ const state = store.getState();
45
+ if (!wasControlled) {
46
+ listeners.forEach(function callUncontrolledChangeListener(listener) {
47
+ listener(previousState, state);
48
+ });
49
+ }
50
+ previousState = state;
51
+ }
52
+ store.subscribe(listenForUncontrolledActions);
53
+ Object.assign(store, {
54
+ dispatch: enhancedDispatch,
55
+ subscribeUncontrolled: subscribeUncontrolled,
56
+ observeUncontrolled: observeUncontrolled,
57
+ });
58
+ }
59
+ //# sourceMappingURL=enable-controlled-dispatch-and-observe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enable-controlled-dispatch-and-observe.js","sourceRoot":"","sources":["../src/js/enable-controlled-dispatch-and-observe.ts"],"names":[],"mappings":"AAIA,MAAM,kBAAkB,GAAoB,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;AAgC9D,SAAS,gBAAgB,CACxB,MAAiB;IAEjB,OAAO,MAAM,IAAI,MAAM,CAAC;AACzB,CAAC;AAED,SAAS,kBAAkB,CAC1B,MAAiB,EACjB,oBAA4B;IAE5B,OAAO,CACN,gBAAgB,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,oBAAoB,CAAC,KAAK,IAAI,CACxE,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,kCAAkC,CACzD,KAAmB,EACnB,oBAAoB,GAAG,cAAc;IAErC,IAAI,SAAS,GAA6C,EAAE,CAAC;IAE7D,SAAS,cAAc,CAAC,QAA2C;QAClE,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC;IACrD,CAAC;IAED,SAAS,WAAW,CAAC,QAA2C;QAC/D,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,qBAAqB,GAAiC,CAAC,QAAQ,EAAE,EAAE;QACxE,WAAW,CAAC,QAAQ,CAAC,CAAC;QAEtB,OAAO,SAAS,mBAAmB;YAClC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAC1B,CAAC,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,mBAAmB,GAA+B,CACvD,QAAQ,EACR,QAAQ,EACR,OAAO,GAAG,kBAAkB,EAC3B,EAAE,CACH,qBAAqB,CACpB,SAAS,wBAAwB,CAAC,aAAa,EAAE,KAAK;QACrD,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,CAAC;QAC9C,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEjC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,QAAQ,CAAC,EAAE,CAAC;YACvC,QAAQ,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;QAC1C,CAAC;IACF,CAAC,CACD,CAAC;IAEH,IAAI,aAAa,GAAG,KAAK,CAAC;IAC1B,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,CAAC;IAEpC,MAAM,gBAAgB,GAAa,CAAC,MAAM,EAAE,EAAE;QAC7C,aAAa,GAAG,kBAAkB,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;QACjE,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC,CAAC;IAEF,IAAI,aAAa,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;IAErC,SAAS,4BAA4B;QACpC,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;QAE/B,IAAI,CAAC,aAAa,EAAE,CAAC;YACpB,SAAS,CAAC,OAAO,CAChB,SAAS,8BAA8B,CAAC,QAAQ;gBAC/C,QAAQ,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;YAChC,CAAC,CACD,CAAC;QACH,CAAC;QAED,aAAa,GAAG,KAAK,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,4BAA4B,CAAC,CAAC;IAE9C,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE;QACpB,QAAQ,EAAE,gBAAgB;QAC1B,qBAAqB,EAAE,qBAAqB;QAC5C,mBAAmB,EAAE,mBAAmB;KACxC,CAAC,CAAC;AACJ,CAAC"}