@webkrafters/react-observable-context 4.1.0-alpha.3 → 4.1.0-rc.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.
|
@@ -3,7 +3,7 @@ export type Listener<T extends import("../../../types").State> = import("../../.
|
|
|
3
3
|
export type State = import("../../../types").State;
|
|
4
4
|
export type StoreInternal<T extends import("../../../types").State> = import("../../../types").StoreInternal<T>;
|
|
5
5
|
declare function useStateManager<T extends import("../../../types").State>(initStateValue: T): {
|
|
6
|
-
select: (clientId: string, ...propertyPaths?:
|
|
6
|
+
select: (clientId: string, ...propertyPaths?: string[]) => {
|
|
7
7
|
[propertyPaths: string]: Readonly<any>;
|
|
8
8
|
};
|
|
9
9
|
state: T;
|
|
@@ -12,10 +12,10 @@ export type State = import("../../../types").State;
|
|
|
12
12
|
export type MutableRefObject<T> = import('react').MutableRefObject<T>;
|
|
13
13
|
import _setState from "../../set-state";
|
|
14
14
|
declare function useStore<T extends import("../../../types").State>(prehooks: Prehooks<T>, value: T, storage?: IStorage<T>): {
|
|
15
|
-
getState: (clientId: string, ...propertyPaths?:
|
|
15
|
+
getState: (clientId: string, ...propertyPaths?: string[]) => {
|
|
16
16
|
[propertyPaths: string]: Readonly<any>;
|
|
17
17
|
};
|
|
18
|
-
resetState: (propertyPaths?:
|
|
18
|
+
resetState: (propertyPaths?: string[]) => void;
|
|
19
19
|
setState: (changes: import("../../../types").UpdatePayload<import("../../../types").PartialState<T>>) => void;
|
|
20
20
|
subscribe: (listener: import("../../../types").Listener<T>) => VoidFunction;
|
|
21
21
|
unlinkCache: (clientId: string) => void;
|
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,6 +31,80 @@ 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>;
|
|
@@ -70,7 +128,7 @@ export type SelectorMap<T extends import("../types").State> = {
|
|
|
70
128
|
export type StoreInternal<T extends import("../types").State> = import("../types").StoreInternal<T>;
|
|
71
129
|
export type PartialStore<T extends import("../types").State> = {
|
|
72
130
|
data?: import("../types").Data;
|
|
73
|
-
resetState?: (propertyPaths?:
|
|
131
|
+
resetState?: (propertyPaths?: string[]) => void;
|
|
74
132
|
setState?: (changes: import("../types").UpdatePayload<import("../types").PartialState<T>>) => void;
|
|
75
133
|
};
|
|
76
134
|
export type Store<T extends import("../types").State> = import("../types").Store<T>;
|
package/dist/main/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
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"));
|
|
@@ -11,28 +11,13 @@ var _lodash4 = _interopRequireDefault(require("lodash.omit"));
|
|
|
11
11
|
var _uuid = require("uuid");
|
|
12
12
|
var _useRenderKeyProvider = _interopRequireDefault(require("./hooks/use-render-key-provider"));
|
|
13
13
|
var _useStore = _interopRequireDefault(require("./hooks/use-store"));
|
|
14
|
+
var constants = _interopRequireWildcard(require("../constants"));
|
|
14
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
15
16
|
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
17
|
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
18
|
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 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; }
|
|
19
|
-
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; }
|
|
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; }
|
|
32
19
|
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
20
|
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
21
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
37
22
|
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
23
|
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 +30,22 @@ function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[nat
|
|
|
45
30
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
46
31
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
47
32
|
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
|
-
|
|
33
|
+
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; }
|
|
34
|
+
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; }
|
|
35
|
+
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; }
|
|
36
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
37
|
+
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); }
|
|
38
|
+
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; } } }; }
|
|
39
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
40
|
+
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."); }
|
|
41
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
42
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
43
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
44
|
+
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."); }
|
|
45
|
+
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); }
|
|
46
|
+
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; }
|
|
47
|
+
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; } }
|
|
48
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
62
49
|
var createContext = function createContext() {
|
|
63
50
|
var Context = (0, _react.createContext)({
|
|
64
51
|
getState: reportNonReactUsage,
|
|
@@ -71,20 +58,10 @@ var createContext = function createContext() {
|
|
|
71
58
|
return Context;
|
|
72
59
|
};
|
|
73
60
|
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
61
|
var useContext = function useContext(context) {
|
|
85
62
|
var selectorMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
86
63
|
var _React$useContext = _react["default"].useContext(context),
|
|
87
|
-
|
|
64
|
+
getState = _React$useContext.getState,
|
|
88
65
|
_resetState = _React$useContext.resetState,
|
|
89
66
|
subscribe = _React$useContext.subscribe,
|
|
90
67
|
unlinkCache = _React$useContext.unlinkCache,
|
|
@@ -109,7 +86,7 @@ var useContext = function useContext(context) {
|
|
|
109
86
|
if ((0, _lodash["default"])(_renderKeys)) {
|
|
110
87
|
return data;
|
|
111
88
|
}
|
|
112
|
-
var state =
|
|
89
|
+
var state = getState.apply(void 0, [clientId].concat(_toConsumableArray(_renderKeys)));
|
|
113
90
|
var _iterator = _createForOfIteratorHelper(_renderKeys),
|
|
114
91
|
_step;
|
|
115
92
|
try {
|
|
@@ -129,7 +106,7 @@ var useContext = function useContext(context) {
|
|
|
129
106
|
setData = _React$useState4[1];
|
|
130
107
|
var updateData = function updateData() {
|
|
131
108
|
var hasChanges = false;
|
|
132
|
-
var state =
|
|
109
|
+
var state = getState.apply(void 0, [clientId].concat(_toConsumableArray(_renderKeys)));
|
|
133
110
|
var _iterator2 = _createForOfIteratorHelper(_renderKeys),
|
|
134
111
|
_step2;
|
|
135
112
|
try {
|
|
@@ -177,6 +154,46 @@ var useContext = function useContext(context) {
|
|
|
177
154
|
}, [data]);
|
|
178
155
|
};
|
|
179
156
|
exports.useContext = useContext;
|
|
157
|
+
var connect = function connect(context, selectorMap) {
|
|
158
|
+
return function (WrappedComponent) {
|
|
159
|
+
if (!((0, _lodash3["default"])(WrappedComponent) && 'compare' in WrappedComponent)) {
|
|
160
|
+
WrappedComponent = (0, _react.memo)(WrappedComponent);
|
|
161
|
+
}
|
|
162
|
+
var ConnectedComponent = (0, _react.memo)(function (ownProps) {
|
|
163
|
+
var store = useContext(context, selectorMap);
|
|
164
|
+
return _react["default"].createElement(WrappedComponent, _extends({}, store, ownProps));
|
|
165
|
+
});
|
|
166
|
+
ConnectedComponent.displayName = 'ObservableContext.Connected';
|
|
167
|
+
return ConnectedComponent;
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
exports.connect = connect;
|
|
171
|
+
var CLEAR_TAG = constants.CLEAR_TAG;
|
|
172
|
+
exports.CLEAR_TAG = CLEAR_TAG;
|
|
173
|
+
var DELETE_TAG = constants.DELETE_TAG;
|
|
174
|
+
exports.DELETE_TAG = DELETE_TAG;
|
|
175
|
+
var FULL_STATE_SELECTOR = constants.FULL_STATE_SELECTOR;
|
|
176
|
+
exports.FULL_STATE_SELECTOR = FULL_STATE_SELECTOR;
|
|
177
|
+
var MOVE_TAG = constants.MOVE_TAG;
|
|
178
|
+
exports.MOVE_TAG = MOVE_TAG;
|
|
179
|
+
var PUSH_TAG = constants.PUSH_TAG;
|
|
180
|
+
exports.PUSH_TAG = PUSH_TAG;
|
|
181
|
+
var REPLACE_TAG = constants.REPLACE_TAG;
|
|
182
|
+
exports.REPLACE_TAG = REPLACE_TAG;
|
|
183
|
+
var SET_TAG = constants.SET_TAG;
|
|
184
|
+
exports.SET_TAG = SET_TAG;
|
|
185
|
+
var SPLICE_TAG = constants.SPLICE_TAG;
|
|
186
|
+
exports.SPLICE_TAG = SPLICE_TAG;
|
|
187
|
+
var UsageError = function (_Error) {
|
|
188
|
+
_inherits(UsageError, _Error);
|
|
189
|
+
var _super = _createSuper(UsageError);
|
|
190
|
+
function UsageError() {
|
|
191
|
+
_classCallCheck(this, UsageError);
|
|
192
|
+
return _super.apply(this, arguments);
|
|
193
|
+
}
|
|
194
|
+
return _createClass(UsageError);
|
|
195
|
+
}( _wrapNativeSuper(Error));
|
|
196
|
+
exports.UsageError = UsageError;
|
|
180
197
|
var ChildMemo = function () {
|
|
181
198
|
var useNodeMemo = function useNodeMemo(node) {
|
|
182
199
|
var nodeRef = (0, _react.useRef)(node);
|
|
@@ -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/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare const _default: any;
|
|
2
2
|
export default _default;
|
|
3
|
-
export type BaseType = any[] | {
|
|
3
|
+
export type BaseType = boolean | any[] | {
|
|
4
4
|
[x: string]: any;
|
|
5
|
-
} |
|
|
5
|
+
} | KeyType;
|
|
6
6
|
export type Data = {
|
|
7
7
|
[selectorKey: string]: Readonly<any>;
|
|
8
8
|
};
|
|
@@ -18,6 +18,7 @@ export type IStore = {
|
|
|
18
18
|
setState: NonReactUsageReport;
|
|
19
19
|
subscribe: NonReactUsageReport;
|
|
20
20
|
};
|
|
21
|
+
export type KeyType = number | string | symbol;
|
|
21
22
|
export type Listener<T extends State> = (changes: UpdatePayload<PartialState<T>>) => void;
|
|
22
23
|
export type NonReactUsageReport = () => never;
|
|
23
24
|
export type PartialState<T extends State> = { [K in keyof T]?: T[K]; };
|
|
@@ -36,29 +37,16 @@ export type PropertyInfo<T extends any[] | State> = {
|
|
|
36
37
|
source: T;
|
|
37
38
|
value: any;
|
|
38
39
|
};
|
|
39
|
-
export type PropertyPath<T extends State> = keyof T | KeyType | KeyType[];
|
|
40
|
-
export type PropertyPathTokens = Array<KeyType>;
|
|
41
|
-
export type Scalar = boolean | KeyType;
|
|
42
|
-
export type KeyType = number | string | symbol;
|
|
43
|
-
export type SelectorMap<T extends State> = {
|
|
44
|
-
[dataPropKey: string]: PropertyPath<T>;
|
|
45
|
-
[dataPropKey: number]: PropertyPath<T>;
|
|
46
|
-
[dataPropKey: symbol]: PropertyPath<T>;
|
|
47
|
-
} & {
|
|
48
|
-
[dataPropKey: string]: "@@STATE" | ["@@STATE"];
|
|
49
|
-
[dataPropKey: number]: "@@STATE" | ["@@STATE"];
|
|
50
|
-
[dataPropKey: symbol]: "@@STATE" | ["@@STATE"];
|
|
51
|
-
};
|
|
52
40
|
export type State = {
|
|
53
41
|
[x: string]: any;
|
|
54
42
|
[x: number]: any;
|
|
55
43
|
[x: symbol]: any;
|
|
56
44
|
};
|
|
57
45
|
export type StoreInternal<T extends State> = {
|
|
58
|
-
resetState: (propertyPaths?:
|
|
46
|
+
resetState: (propertyPaths?: string[]) => void;
|
|
59
47
|
setState: (changes: UpdatePayload<PartialState<T>>) => void;
|
|
60
48
|
} & {
|
|
61
|
-
getState: (clientId: string, ...propertyPaths?:
|
|
49
|
+
getState: (clientId: string, ...propertyPaths?: string[]) => {
|
|
62
50
|
[propertyPaths: string]: Readonly<any>;
|
|
63
51
|
};
|
|
64
52
|
subscribe: (listener: Listener<T>) => Unsubscribe;
|
|
@@ -66,7 +54,7 @@ export type StoreInternal<T extends State> = {
|
|
|
66
54
|
};
|
|
67
55
|
export type Store<T extends State> = {
|
|
68
56
|
data: Data;
|
|
69
|
-
resetState: (propertyPaths?:
|
|
57
|
+
resetState: (propertyPaths?: string[]) => void;
|
|
70
58
|
setState: (changes: UpdatePayload<PartialState<T>>) => void;
|
|
71
59
|
};
|
|
72
60
|
export type UpdateStats = {
|
package/package.json
CHANGED