@webkrafters/react-observable-context 4.2.0 → 4.4.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.
- package/README.md +8 -0
- package/dist/main/index.d.ts +12 -5
- package/dist/main/index.js +5 -3
- package/dist/model/atom/index.d.ts +1 -1
- package/dist/model/atom/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -648,6 +648,14 @@ store.setState({
|
|
|
648
648
|
<h1 id="changes">What's Changed?</h1>
|
|
649
649
|
|
|
650
650
|
<table>
|
|
651
|
+
<thead><tr><th>v4.4.0</th></tr></thead>
|
|
652
|
+
<tbody>
|
|
653
|
+
<tr><td><b>1.</b></td><td>Returns <code>undefined</code> for selector map pointing at a non-existent state slice. <i>(Previously returned <code>null</code>)</i></td></tr>
|
|
654
|
+
</tbody>
|
|
655
|
+
<thead><tr><th>v4.3.0</th></tr></thead>
|
|
656
|
+
<tbody>
|
|
657
|
+
<tr><td><b>1.</b></td><td>Added <code>React.Ref</code> forwarding to <code>connect</code>ed hoc client components.</td></tr>
|
|
658
|
+
</tbody>
|
|
651
659
|
<thead><tr><th>v4.1.0</th></tr></thead>
|
|
652
660
|
<tbody>
|
|
653
661
|
<tr><td><b>1.</b></td><td>Added new setState <a href="#setstate-tags">tags</a> to facilitate state update operations.</td></tr>
|
package/dist/main/index.d.ts
CHANGED
|
@@ -42,13 +42,15 @@ export function useContext<STATE extends import("../types").State, SELECTOR_MAP
|
|
|
42
42
|
* @param {SELECTOR_MAP} [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.
|
|
43
43
|
* @returns {(WrappedComponent: C) => ConnectedComponent<OWNPROPS, Store<STATE, SELECTOR_MAP>>} - Connector HOC function
|
|
44
44
|
* @template {State} STATE
|
|
45
|
-
* @template {State} [OWNPROPS
|
|
45
|
+
* @template {OwnProps<State>} [OWNPROPS=OwnProps]
|
|
46
46
|
* @template {SelectorMap<STATE>} [SELECTOR_MAP=SelectorMap<STATE>]
|
|
47
|
-
* @template {ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE, SELECTOR_MAP
|
|
47
|
+
* @template {ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE, SELECTOR_MAP>>>|ExoticComponent<ConnectedComponentProps<OWNPROPS, PartialStore<STATE, SELECTOR_MAP>>>} [C = ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE, SELECTOR_MAP>>>]
|
|
48
48
|
* @see {ObservableContext<STATE,SELECTOR_MAP>}
|
|
49
49
|
* @see {useContext} for selectorMap sample
|
|
50
50
|
*/
|
|
51
|
-
export function connect<STATE extends import("../types").State, OWNPROPS extends import("../types").State
|
|
51
|
+
export function connect<STATE extends import("../types").State, OWNPROPS extends Pick<import("../types").State, keyof import("../types").State> & {
|
|
52
|
+
ref?: unknown;
|
|
53
|
+
} = {}, SELECTOR_MAP extends BaseSelectorMap<STATE> = BaseSelectorMap<STATE>, C extends ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE, SELECTOR_MAP>>> | import("react").ExoticComponent<ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE, SELECTOR_MAP>>>> = ComponentType<ConnectedComponentProps<OWNPROPS, PartialStore<STATE, SELECTOR_MAP>>>>(context: ObservableContext<STATE, SELECTOR_MAP>, selectorMap?: SELECTOR_MAP): (WrappedComponent: C) => ConnectedComponent<OWNPROPS, Store<STATE, SELECTOR_MAP>>;
|
|
52
54
|
export type CLEAR_TAG = typeof CLEAR_TAG;
|
|
53
55
|
|
|
54
56
|
/** @example changes = { property: CLEAR_TAG } */
|
|
@@ -144,8 +146,13 @@ export type PartialStore<T extends import("../types").State, SELECTOR_MAP extend
|
|
|
144
146
|
export type Store<T extends import("../types").State, SELECTOR_MAP extends BaseSelectorMap<T> = BaseSelectorMap<T>> = import("../types").Store<T, SELECTOR_MAP>;
|
|
145
147
|
export type IStore = import("../types").IStore;
|
|
146
148
|
export type IStorage<T extends import("../types").State> = import("../types").IStorage<T>;
|
|
147
|
-
export type ConnectedComponent<OWNPROPS extends
|
|
148
|
-
|
|
149
|
+
export type ConnectedComponent<OWNPROPS extends Pick<import("../types").State, keyof import("../types").State> & {
|
|
150
|
+
ref?: unknown;
|
|
151
|
+
} = {}, STORE extends Store<import("../types").State, BaseSelectorMap<import("../types").State>> = Store<import("../types").State, BaseSelectorMap<import("../types").State>>> = MemoExoticComponent<ConnectedComponentProps<OWNPROPS, STORE>>;
|
|
152
|
+
export type ConnectedComponentProps<OWNPROPS extends Pick<import("../types").State, keyof import("../types").State> & {
|
|
153
|
+
ref?: unknown;
|
|
154
|
+
} = {}, STORE extends Store<import("../types").State, BaseSelectorMap<import("../types").State>> = Store<import("../types").State, BaseSelectorMap<import("../types").State>>> = STORE & OWNPROPS;
|
|
155
|
+
export type OwnProps<P extends import("../types").State = {}> = import("react").PropsWithRef<P>;
|
|
149
156
|
export type NonReactUsageReport = import("../types").NonReactUsageReport;
|
|
150
157
|
export type Data<SELECTOR_MAP extends BaseSelectorMap<import("../types").State> = BaseSelectorMap<import("../types").State>> = import("../types").Data<SELECTOR_MAP>;
|
|
151
158
|
export type ReactNode = import("react").ReactNode;
|
package/dist/main/index.js
CHANGED
|
@@ -163,10 +163,12 @@ var connect = function connect(context, selectorMap) {
|
|
|
163
163
|
if (!((0, _lodash3["default"])(WrappedComponent) && 'compare' in WrappedComponent)) {
|
|
164
164
|
WrappedComponent = (0, _react.memo)(WrappedComponent);
|
|
165
165
|
}
|
|
166
|
-
var ConnectedComponent = (0, _react.memo)(function (ownProps) {
|
|
166
|
+
var ConnectedComponent = (0, _react.memo)( (0, _react.forwardRef)(function (ownProps, ref) {
|
|
167
167
|
var store = useContext(context, selectorMap);
|
|
168
|
-
return _react["default"].createElement(WrappedComponent, _extends({}, store, ownProps
|
|
169
|
-
|
|
168
|
+
return _react["default"].createElement(WrappedComponent, _extends({}, store, ownProps, {
|
|
169
|
+
ref: ref
|
|
170
|
+
}));
|
|
171
|
+
}));
|
|
170
172
|
ConnectedComponent.displayName = 'ObservableContext.Connected';
|
|
171
173
|
return ConnectedComponent;
|
|
172
174
|
};
|
package/dist/model/atom/index.js
CHANGED
|
@@ -21,7 +21,7 @@ var _connections = new WeakMap();
|
|
|
21
21
|
var _value = new WeakMap();
|
|
22
22
|
var Atom = function () {
|
|
23
23
|
function Atom() {
|
|
24
|
-
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
24
|
+
var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undefined;
|
|
25
25
|
_classCallCheck(this, Atom);
|
|
26
26
|
_classPrivateFieldInitSpec(this, _connections, {
|
|
27
27
|
writable: true,
|
package/package.json
CHANGED