@webkrafters/react-observable-context 4.1.0-rc.0 → 4.1.0-rc.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.
package/README.md
CHANGED
|
@@ -92,6 +92,8 @@ A special property path [@@STATE](#fullstate-selectorkey) may be used to access
|
|
|
92
92
|
## Provider
|
|
93
93
|
The Provider component is a property of the `React-Observable-Context` context object. As a `React.context` based provider, it accepts the customary `children` and `value` props. It also accepts **2** optional props: <a href="#prehooks"><code>prehooks</code></a> and <a href="#storage"><code>storage</code></a>.
|
|
94
94
|
|
|
95
|
+
External direct access to the context store may be obtained via the `ref` attribute. Please see a [Provider Usage](#provider-usage) sample below.
|
|
96
|
+
|
|
95
97
|
Routinely, the `value` prop is initialized with the full initial state. It may only be updated with parts of the state which are changing. Please see a [Provider Usage](#provider-usage) sample below.
|
|
96
98
|
|
|
97
99
|
<h2 id="selector-map">Selector Map</h2>
|
|
@@ -541,6 +543,8 @@ const storageStub = {
|
|
|
541
543
|
};
|
|
542
544
|
|
|
543
545
|
const Provider = ({ c = DEFAULT_C }) => {
|
|
546
|
+
|
|
547
|
+
const storeRef = useRef();
|
|
544
548
|
|
|
545
549
|
const [ state, setState ] = useState(() => ({
|
|
546
550
|
a: { b: { c, x: { y: { z: [ 2022 ] } } } }
|
|
@@ -557,6 +561,7 @@ const Provider = ({ c = DEFAULT_C }) => {
|
|
|
557
561
|
return (
|
|
558
562
|
<ObservableContext.Provider
|
|
559
563
|
prehooks={ updateHooks }
|
|
564
|
+
ref={ storeRef }
|
|
560
565
|
storage={ storageStub }
|
|
561
566
|
value={ state }
|
|
562
567
|
>
|
|
@@ -580,16 +585,15 @@ ReactDOM.render( <Provider />, document.getElementById( 'root' ) );
|
|
|
580
585
|
```
|
|
581
586
|
|
|
582
587
|
<h1 id="changes">What's Changed?</h1>
|
|
583
|
-
|
|
588
|
+
|
|
584
589
|
<table>
|
|
590
|
+
<thead><tr><th>v4.1.0</th></tr></thead>
|
|
585
591
|
<tbody>
|
|
586
592
|
<tr><td><b>1.</b></td><td>Added new setState <a href="#setstate-tags">tags</a> to facilitate state update operations.</td></tr>
|
|
593
|
+
<tr><td><b>2.</b></td><td>Exposing the store via its Context Provider `ref` attribute.</td></tr>
|
|
594
|
+
<tr><td><b>3.</b></td><td>Exporting crucial constants such as @@STATE and setState <a href="#setstate-tags">tags</a> such as @@CLEAR, @@MOVE etc.</td></tr>
|
|
587
595
|
</tbody>
|
|
588
|
-
</
|
|
589
|
-
<hr />
|
|
590
|
-
|
|
591
|
-
<b>v4.0.0</b>
|
|
592
|
-
<table>
|
|
596
|
+
<thead><tr><th>v4.0.0</th></tr></thead>
|
|
593
597
|
<tbody>
|
|
594
598
|
<tr><td><b>1.</b></td><td>Added the <a href="#connect"><code>connect</code></a> function to facilitate the encapsulated context-usage method.</td></tr>
|
|
595
599
|
<tr><td><b>2.</b></td><td>Added stronger support for deeply nested state structure. See <a href="#store-setstate"><code>store.setState</code></a></td></tr>
|
|
@@ -17,6 +17,7 @@ declare function useStore<T extends import("../../../types").State>(prehooks: Pr
|
|
|
17
17
|
};
|
|
18
18
|
resetState: (propertyPaths?: string[]) => void;
|
|
19
19
|
setState: (changes: import("../../../types").UpdatePayload<import("../../../types").PartialState<T>>) => void;
|
|
20
|
+
state: T;
|
|
20
21
|
subscribe: (listener: import("../../../types").Listener<T>) => VoidFunction;
|
|
21
22
|
unlinkCache: (clientId: string) => void;
|
|
22
23
|
};
|
package/dist/main/index.d.ts
CHANGED
|
@@ -1,25 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param {ObservableContext<T>} context Refers to the PublicObservableContext<T> type of the ObservableContext<T>
|
|
3
|
-
* @param {SelectorMap<T>} [selectorMap] Key:value pairs where `key` => arbitrary key given to a Store.data property holding a state slice and `value` => property path to a state slice used by this component: see examples below. May add a mapping for a certain arbitrary key='state' and value='@@STATE' to indicate a desire to obtain the entire state object and assign to a `state` property of Store.data. A change in any of the referenced properties results in this component render. When using '@@STATE', note that any change within the state object will result in this component render.
|
|
4
|
-
* @returns {(WrappedComponent: C) => MemoExoticComponent<P>}
|
|
5
|
-
* @template {State} T
|
|
6
|
-
* @template {PartialStore<T> & {[x:string]:*}} [P=PartialStore<T>]
|
|
7
|
-
* @template {ComponentType<P>|ExoticComponent<P>} C
|
|
8
|
-
* @see {ObservableContext<T>}
|
|
9
|
-
* @see {useContext} for selectorMap sample
|
|
10
|
-
*/
|
|
11
|
-
export function connect<T extends import("../types").State, P extends PartialStore<T> & {
|
|
12
|
-
[x: string]: any;
|
|
13
|
-
} = PartialStore<T>, C extends ComponentType<P> | import("react").ExoticComponent<ComponentType<P>>>(context: ObservableContext<T>, selectorMap?: SelectorMap<T>): (WrappedComponent: C) => MemoExoticComponent<P>;
|
|
14
|
-
|
|
15
1
|
/**
|
|
16
2
|
* @returns {ObservableContext<T>} Refers to the IObservableContext<T> type of the ObservableContext<T>
|
|
17
3
|
* @template {State} T
|
|
18
4
|
* @see {ObservableContext<T>}
|
|
19
5
|
*/
|
|
20
6
|
export function createContext<T extends import("../types").State>(): ObservableContext<T>;
|
|
21
|
-
export class UsageError extends Error {
|
|
22
|
-
}
|
|
23
7
|
|
|
24
8
|
/**
|
|
25
9
|
* Actively monitors the store and triggers component re-render if any of the watched keys in the state objects changes
|
|
@@ -47,18 +31,101 @@ export class UsageError extends Error {
|
|
|
47
31
|
* {myData: '@@STATE'} => {myData: state}
|
|
48
32
|
*/
|
|
49
33
|
export function useContext<T extends import("../types").State>(context: ObservableContext<T>, selectorMap?: SelectorMap<T>): Store<T>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {ObservableContext<T>} context Refers to the PublicObservableContext<T> type of the ObservableContext<T>
|
|
37
|
+
* @param {SelectorMap<T>} [selectorMap] Key:value pairs where `key` => arbitrary key given to a Store.data property holding a state slice and `value` => property path to a state slice used by this component: see examples below. May add a mapping for a certain arbitrary key='state' and value='@@STATE' to indicate a desire to obtain the entire state object and assign to a `state` property of Store.data. A change in any of the referenced properties results in this component render. When using '@@STATE', note that any change within the state object will result in this component render.
|
|
38
|
+
* @returns {(WrappedComponent: C) => MemoExoticComponent<P>}
|
|
39
|
+
* @template {State} T
|
|
40
|
+
* @template {PartialStore<T> & {[x:string]:*}} [P=PartialStore<T>]
|
|
41
|
+
* @template {ComponentType<P>|ExoticComponent<P>} C
|
|
42
|
+
* @see {ObservableContext<T>}
|
|
43
|
+
* @see {useContext} for selectorMap sample
|
|
44
|
+
*/
|
|
45
|
+
export function connect<T extends import("../types").State, P extends PartialStore<T> & {
|
|
46
|
+
[x: string]: any;
|
|
47
|
+
} = PartialStore<T>, C extends ComponentType<P> | import("react").ExoticComponent<ComponentType<P>>>(context: ObservableContext<T>, selectorMap?: SelectorMap<T>): (WrappedComponent: C) => MemoExoticComponent<P>;
|
|
48
|
+
export type CLEAR_TAG = typeof CLEAR_TAG;
|
|
49
|
+
|
|
50
|
+
/** @example changes = { property: CLEAR_TAG } */
|
|
51
|
+
export const CLEAR_TAG: "@@CLEAR";
|
|
52
|
+
export type DELETE_TAG = typeof DELETE_TAG;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @example
|
|
56
|
+
* changes = {
|
|
57
|
+
* property: {
|
|
58
|
+
* [DELETE_TAG]: [keys/indexes to remove from property]
|
|
59
|
+
* }
|
|
60
|
+
* }
|
|
61
|
+
*/
|
|
62
|
+
export const DELETE_TAG: "@@DELETE";
|
|
63
|
+
export type FULL_STATE_SELECTOR = import("../types").FULL_STATE_SELECTOR;
|
|
64
|
+
export const FULL_STATE_SELECTOR: "@@STATE";
|
|
65
|
+
export type MOVE_TAG = typeof MOVE_TAG;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @example
|
|
69
|
+
* changes = {
|
|
70
|
+
* arrayProperty: {
|
|
71
|
+
* [MOVE_TAG]: [-/+fromIndex, -/+toIndex, +numItems?] // numItems = 1 by default
|
|
72
|
+
* }
|
|
73
|
+
* }
|
|
74
|
+
*/
|
|
75
|
+
export const MOVE_TAG: "@@MOVE";
|
|
76
|
+
export type PUSH_TAG = typeof PUSH_TAG;
|
|
77
|
+
|
|
78
|
+
/** @example changes = { arrayProperty: { [PUSH_TAG]: [new items to append to array] } } */
|
|
79
|
+
export const PUSH_TAG: "@@PUSH";
|
|
80
|
+
export type REPLACE_TAG = typeof REPLACE_TAG;
|
|
81
|
+
|
|
82
|
+
/** @example changes = { property: { [REPLACE_TAG]: replacement } } */
|
|
83
|
+
export const REPLACE_TAG: "@@REPLACE";
|
|
84
|
+
export type SET_TAG = typeof SET_TAG;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @example
|
|
88
|
+
* changes = {
|
|
89
|
+
* property: {
|
|
90
|
+
* [SET_TAG]: replacement // or a compute replacement function (i.e. currentProperty => replacement)
|
|
91
|
+
* }
|
|
92
|
+
* }
|
|
93
|
+
*/
|
|
94
|
+
export const SET_TAG: "@@SET";
|
|
95
|
+
export type SPLICE_TAG = typeof SPLICE_TAG;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @example
|
|
99
|
+
* changes = {
|
|
100
|
+
* arrayProperty: {
|
|
101
|
+
* [SPLICE_TAG]: [-/+fromIndex, +deleteCount, ...newItems?] // newItems = ...[] by default
|
|
102
|
+
* }
|
|
103
|
+
* }
|
|
104
|
+
*/
|
|
105
|
+
export const SPLICE_TAG: "@@SPLICE";
|
|
106
|
+
export class UsageError extends Error {
|
|
107
|
+
}
|
|
50
108
|
export type ObservableContext<T extends import("../types").State> = IObservableContext<T> | PublicObservableContext<T>;
|
|
51
109
|
export type PublicObservableContext<T extends import("../types").State> = WithObservableProvider<Context<Store<T>>, T>;
|
|
52
110
|
export type IObservableContext<T extends import("../types").State> = WithObservableProvider<Context<IStore>, T>;
|
|
53
111
|
export type WithObservableProvider<T, S extends import("../types").State> = T & {
|
|
54
112
|
Provider: ObservableProvider<S>;
|
|
55
113
|
};
|
|
56
|
-
export type ObservableProvider<T extends import("../types").State> =
|
|
114
|
+
export type ObservableProvider<T extends import("../types").State> = ForwardRefExoticComponent<ProviderProps<T>, StoreRef<T>>;
|
|
115
|
+
export type ProviderProps<T extends import("../types").State> = {
|
|
57
116
|
children?: ReactNode;
|
|
58
117
|
prehooks?: Prehooks<T>;
|
|
59
118
|
storage?: IStorage<T>;
|
|
60
119
|
value: PartialState<T>;
|
|
61
|
-
}
|
|
120
|
+
};
|
|
121
|
+
export type StoreRef<T extends import("../types").State> = {
|
|
122
|
+
[x: string]: any;
|
|
123
|
+
getState: () => T;
|
|
124
|
+
} & {
|
|
125
|
+
resetState: (propertyPaths?: string[]) => void;
|
|
126
|
+
setState: (changes: import("../types").UpdatePayload<import("../types").PartialState<T>>) => void;
|
|
127
|
+
subscribe: (listener: import("../types").Listener<T>) => VoidFunction;
|
|
128
|
+
};
|
|
62
129
|
export type State = import("../types").State;
|
|
63
130
|
export type PartialState<T extends import("../types").State> = import("../types").PartialState<T>;
|
|
64
131
|
export type Prehooks<T extends import("../types").State> = import("../types").Prehooks<T>;
|
|
@@ -79,6 +146,7 @@ export type IStorage<T extends import("../types").State> = import("../types").IS
|
|
|
79
146
|
export type NonReactUsageReport = import("../types").NonReactUsageReport;
|
|
80
147
|
export type Data = import("../types").Data;
|
|
81
148
|
export type ReactNode = import("react").ReactNode;
|
|
149
|
+
export type ForwardRefExoticComponent<P, T> = import('react').ForwardRefExoticComponent<import('react').PropsWithRef<P> & import('react').RefAttributes<T>>;
|
|
82
150
|
export type MemoExoticComponent<P extends {
|
|
83
151
|
[x: string]: any;
|
|
84
152
|
} = {}> = import('react').MemoExoticComponent<ComponentType<P>>;
|
package/dist/main/index.js
CHANGED
|
@@ -2,37 +2,26 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports.useContext = exports.createContext = exports.connect = exports.UsageError = void 0;
|
|
5
|
+
exports.useContext = exports.createContext = exports.connect = exports.UsageError = exports.SPLICE_TAG = exports.SET_TAG = exports.REPLACE_TAG = exports.PUSH_TAG = exports.MOVE_TAG = exports.FULL_STATE_SELECTOR = exports.DELETE_TAG = exports.CLEAR_TAG = void 0;
|
|
6
6
|
var _react = _interopRequireWildcard(require("react"));
|
|
7
7
|
var _lodash = _interopRequireDefault(require("lodash.isempty"));
|
|
8
8
|
var _lodash2 = _interopRequireDefault(require("lodash.isequal"));
|
|
9
9
|
var _lodash3 = _interopRequireDefault(require("lodash.isplainobject"));
|
|
10
10
|
var _lodash4 = _interopRequireDefault(require("lodash.omit"));
|
|
11
11
|
var _uuid = require("uuid");
|
|
12
|
+
var constants = _interopRequireWildcard(require("../constants"));
|
|
13
|
+
var _utils = require("../utils");
|
|
12
14
|
var _useRenderKeyProvider = _interopRequireDefault(require("./hooks/use-render-key-provider"));
|
|
13
15
|
var _useStore = _interopRequireDefault(require("./hooks/use-store"));
|
|
16
|
+
var _excluded = ["state"];
|
|
14
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
16
19
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
20
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
18
|
-
function
|
|
19
|
-
function
|
|
20
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
22
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
23
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
24
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
25
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
26
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
27
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
28
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
29
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
30
|
-
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
31
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
22
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
32
23
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
33
24
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
34
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
35
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
36
25
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
37
26
|
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
38
27
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
@@ -45,20 +34,22 @@ function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[nat
|
|
|
45
34
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
46
35
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
47
36
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
37
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
38
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
39
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
40
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
41
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
42
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
43
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
44
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
45
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
46
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
47
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
48
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
49
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
50
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
51
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
52
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
62
53
|
var createContext = function createContext() {
|
|
63
54
|
var Context = (0, _react.createContext)({
|
|
64
55
|
getState: reportNonReactUsage,
|
|
@@ -71,20 +62,10 @@ var createContext = function createContext() {
|
|
|
71
62
|
return Context;
|
|
72
63
|
};
|
|
73
64
|
exports.createContext = createContext;
|
|
74
|
-
var UsageError = function (_Error) {
|
|
75
|
-
_inherits(UsageError, _Error);
|
|
76
|
-
var _super = _createSuper(UsageError);
|
|
77
|
-
function UsageError() {
|
|
78
|
-
_classCallCheck(this, UsageError);
|
|
79
|
-
return _super.apply(this, arguments);
|
|
80
|
-
}
|
|
81
|
-
return _createClass(UsageError);
|
|
82
|
-
}( _wrapNativeSuper(Error));
|
|
83
|
-
exports.UsageError = UsageError;
|
|
84
65
|
var useContext = function useContext(context) {
|
|
85
66
|
var selectorMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
86
67
|
var _React$useContext = _react["default"].useContext(context),
|
|
87
|
-
|
|
68
|
+
getState = _React$useContext.getState,
|
|
88
69
|
_resetState = _React$useContext.resetState,
|
|
89
70
|
subscribe = _React$useContext.subscribe,
|
|
90
71
|
unlinkCache = _React$useContext.unlinkCache,
|
|
@@ -109,7 +90,7 @@ var useContext = function useContext(context) {
|
|
|
109
90
|
if ((0, _lodash["default"])(_renderKeys)) {
|
|
110
91
|
return data;
|
|
111
92
|
}
|
|
112
|
-
var state =
|
|
93
|
+
var state = getState.apply(void 0, [clientId].concat(_toConsumableArray(_renderKeys)));
|
|
113
94
|
var _iterator = _createForOfIteratorHelper(_renderKeys),
|
|
114
95
|
_step;
|
|
115
96
|
try {
|
|
@@ -129,7 +110,7 @@ var useContext = function useContext(context) {
|
|
|
129
110
|
setData = _React$useState4[1];
|
|
130
111
|
var updateData = function updateData() {
|
|
131
112
|
var hasChanges = false;
|
|
132
|
-
var state =
|
|
113
|
+
var state = getState.apply(void 0, [clientId].concat(_toConsumableArray(_renderKeys)));
|
|
133
114
|
var _iterator2 = _createForOfIteratorHelper(_renderKeys),
|
|
134
115
|
_step2;
|
|
135
116
|
try {
|
|
@@ -177,6 +158,46 @@ var useContext = function useContext(context) {
|
|
|
177
158
|
}, [data]);
|
|
178
159
|
};
|
|
179
160
|
exports.useContext = useContext;
|
|
161
|
+
var connect = function connect(context, selectorMap) {
|
|
162
|
+
return function (WrappedComponent) {
|
|
163
|
+
if (!((0, _lodash3["default"])(WrappedComponent) && 'compare' in WrappedComponent)) {
|
|
164
|
+
WrappedComponent = (0, _react.memo)(WrappedComponent);
|
|
165
|
+
}
|
|
166
|
+
var ConnectedComponent = (0, _react.memo)(function (ownProps) {
|
|
167
|
+
var store = useContext(context, selectorMap);
|
|
168
|
+
return _react["default"].createElement(WrappedComponent, _extends({}, store, ownProps));
|
|
169
|
+
});
|
|
170
|
+
ConnectedComponent.displayName = 'ObservableContext.Connected';
|
|
171
|
+
return ConnectedComponent;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
exports.connect = connect;
|
|
175
|
+
var CLEAR_TAG = constants.CLEAR_TAG;
|
|
176
|
+
exports.CLEAR_TAG = CLEAR_TAG;
|
|
177
|
+
var DELETE_TAG = constants.DELETE_TAG;
|
|
178
|
+
exports.DELETE_TAG = DELETE_TAG;
|
|
179
|
+
var FULL_STATE_SELECTOR = constants.FULL_STATE_SELECTOR;
|
|
180
|
+
exports.FULL_STATE_SELECTOR = FULL_STATE_SELECTOR;
|
|
181
|
+
var MOVE_TAG = constants.MOVE_TAG;
|
|
182
|
+
exports.MOVE_TAG = MOVE_TAG;
|
|
183
|
+
var PUSH_TAG = constants.PUSH_TAG;
|
|
184
|
+
exports.PUSH_TAG = PUSH_TAG;
|
|
185
|
+
var REPLACE_TAG = constants.REPLACE_TAG;
|
|
186
|
+
exports.REPLACE_TAG = REPLACE_TAG;
|
|
187
|
+
var SET_TAG = constants.SET_TAG;
|
|
188
|
+
exports.SET_TAG = SET_TAG;
|
|
189
|
+
var SPLICE_TAG = constants.SPLICE_TAG;
|
|
190
|
+
exports.SPLICE_TAG = SPLICE_TAG;
|
|
191
|
+
var UsageError = function (_Error) {
|
|
192
|
+
_inherits(UsageError, _Error);
|
|
193
|
+
var _super = _createSuper(UsageError);
|
|
194
|
+
function UsageError() {
|
|
195
|
+
_classCallCheck(this, UsageError);
|
|
196
|
+
return _super.apply(this, arguments);
|
|
197
|
+
}
|
|
198
|
+
return _createClass(UsageError);
|
|
199
|
+
}( _wrapNativeSuper(Error));
|
|
200
|
+
exports.UsageError = UsageError;
|
|
180
201
|
var ChildMemo = function () {
|
|
181
202
|
var useNodeMemo = function useNodeMemo(node) {
|
|
182
203
|
var nodeRef = (0, _react.useRef)(node);
|
|
@@ -201,7 +222,7 @@ var ChildMemo = function () {
|
|
|
201
222
|
}();
|
|
202
223
|
var defaultPrehooks = Object.freeze({});
|
|
203
224
|
function makeObservable(Provider) {
|
|
204
|
-
var Observable = function
|
|
225
|
+
var Observable = (0, _react.forwardRef)(function (_ref3, storeRef) {
|
|
205
226
|
var _ref3$children = _ref3.children,
|
|
206
227
|
children = _ref3$children === void 0 ? null : _ref3$children,
|
|
207
228
|
_ref3$prehooks = _ref3.prehooks,
|
|
@@ -209,10 +230,32 @@ function makeObservable(Provider) {
|
|
|
209
230
|
_ref3$storage = _ref3.storage,
|
|
210
231
|
storage = _ref3$storage === void 0 ? null : _ref3$storage,
|
|
211
232
|
value = _ref3.value;
|
|
233
|
+
var _store = (0, _useStore["default"])(prehooks, value, storage);
|
|
234
|
+
var _useMemo = (0, _react.useMemo)(function () {
|
|
235
|
+
var state = _store.state,
|
|
236
|
+
store = _objectWithoutProperties(_store, _excluded);
|
|
237
|
+
return {
|
|
238
|
+
state: state,
|
|
239
|
+
store: store
|
|
240
|
+
};
|
|
241
|
+
}, [_store]),
|
|
242
|
+
state = _useMemo.state,
|
|
243
|
+
store = _useMemo.store;
|
|
244
|
+
(0, _react.useImperativeHandle)(storeRef, function () {
|
|
245
|
+
var _storeRef$current;
|
|
246
|
+
return _objectSpread(_objectSpread({}, (_storeRef$current = storeRef === null || storeRef === void 0 ? void 0 : storeRef.current) !== null && _storeRef$current !== void 0 ? _storeRef$current : {}), {}, {
|
|
247
|
+
getState: function getState() {
|
|
248
|
+
return (0, _utils.clonedeep)(state);
|
|
249
|
+
},
|
|
250
|
+
resetState: store.resetState,
|
|
251
|
+
setState: store.setState,
|
|
252
|
+
subscribe: store.subscribe
|
|
253
|
+
});
|
|
254
|
+
}, [storeRef === null || storeRef === void 0 ? void 0 : storeRef.current, state]);
|
|
212
255
|
return _react["default"].createElement(Provider, {
|
|
213
|
-
value:
|
|
256
|
+
value: store
|
|
214
257
|
}, memoizeImmediateChildTree(children));
|
|
215
|
-
};
|
|
258
|
+
});
|
|
216
259
|
Observable.displayName = 'ObservableContext.Provider';
|
|
217
260
|
return Observable;
|
|
218
261
|
}
|
|
@@ -103,11 +103,10 @@ var AccessorCache = function () {
|
|
|
103
103
|
var atoms = _classPrivateFieldGet(this, _atoms);
|
|
104
104
|
var updatedPaths = [];
|
|
105
105
|
for (var path in atoms) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if ((0, _lodash2["default"])(newAtomVal, atoms[path].value)) {
|
|
106
|
+
var _classPrivateMethodGe = _classPrivateMethodGet(this, _getOriginAt, _getOriginAt2).call(this, path),
|
|
107
|
+
exists = _classPrivateMethodGe.exists,
|
|
108
|
+
newAtomVal = _classPrivateMethodGe.value;
|
|
109
|
+
if (path !== _constants.FULL_STATE_SELECTOR && exists && typeof newAtomVal === 'undefined' && !(0, _utils.getProperty)(originChanges, path).exists || (0, _lodash2["default"])(newAtomVal, atoms[path].value)) {
|
|
111
110
|
continue;
|
|
112
111
|
}
|
|
113
112
|
atoms[path].setValue(newAtomVal);
|
|
@@ -134,7 +133,7 @@ function _createAccessor2(cacheKey, propertyPaths) {
|
|
|
134
133
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
135
134
|
var path = _step2.value;
|
|
136
135
|
if (!(path in atoms)) {
|
|
137
|
-
atoms[path] = new _atom["default"](_classPrivateMethodGet(this, _getOriginAt, _getOriginAt2).call(this, path));
|
|
136
|
+
atoms[path] = new _atom["default"](_classPrivateMethodGet(this, _getOriginAt, _getOriginAt2).call(this, path).value);
|
|
138
137
|
}
|
|
139
138
|
}
|
|
140
139
|
} catch (err) {
|
|
@@ -145,7 +144,10 @@ function _createAccessor2(cacheKey, propertyPaths) {
|
|
|
145
144
|
return _classPrivateFieldGet(this, _accessors)[cacheKey];
|
|
146
145
|
}
|
|
147
146
|
function _getOriginAt2(propertyPath) {
|
|
148
|
-
return propertyPath
|
|
147
|
+
return propertyPath === _constants.FULL_STATE_SELECTOR ? {
|
|
148
|
+
exists: true,
|
|
149
|
+
value: _classPrivateFieldGet(this, _origin)
|
|
150
|
+
} : (0, _utils.getProperty)(_classPrivateFieldGet(this, _origin), propertyPath);
|
|
149
151
|
}
|
|
150
152
|
var _default = AccessorCache;
|
|
151
153
|
exports["default"] = _default;
|
package/package.json
CHANGED