@cleanweb/react 1.1.1-beta.13 → 1.1.1-beta.15
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/build/base/methods.d.ts +10 -6
- package/build/base/methods.js +17 -6
- package/build/classy/logic.d.ts +4 -5
- package/build/classy/logic.js +15 -8
- package/package.json +1 -1
package/build/base/methods.d.ts
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
import type { TCleanState, TStateData } from './state';
|
2
|
-
export declare class ComponentMethods<TProps extends object, TState extends TStateData> {
|
3
|
-
props: TProps;
|
4
|
-
state: TCleanState<TState
|
2
|
+
export declare class ComponentMethods<TProps extends object = {}, TState extends TStateData | null = null> {
|
3
|
+
readonly props: TProps;
|
4
|
+
state: TState extends TStateData ? TCleanState<TState> : null;
|
5
5
|
}
|
6
|
-
type UseMethods =
|
7
|
-
|
8
|
-
|
6
|
+
type UseMethods = {
|
7
|
+
<Class extends typeof ComponentMethods<object, TStateData>>(Methods: Class & Constructor<InstanceType<Class>>, props: InstanceType<Class>['props'], state: InstanceType<Class>['state']): InstanceType<Class>;
|
8
|
+
<Class extends typeof ComponentMethods<object, null>>(Methods: Class & Constructor<InstanceType<Class>>, props: InstanceType<Class>['props'], state?: null): InstanceType<Class>;
|
9
|
+
<Class extends typeof ComponentMethods<HardEmptyObject, null>>(Methods: Class & Constructor<InstanceType<Class>>): InstanceType<Class>;
|
10
|
+
};
|
11
|
+
declare const useMethods: UseMethods;
|
12
|
+
export { useMethods };
|
package/build/base/methods.js
CHANGED
@@ -60,16 +60,26 @@ var ComponentMethods = /** @class */ (function () {
|
|
60
60
|
}());
|
61
61
|
exports.ComponentMethods = ComponentMethods;
|
62
62
|
;
|
63
|
-
var useMethods = function (
|
64
|
-
|
65
|
-
|
63
|
+
var useMethods = function () {
|
64
|
+
var args = [];
|
65
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
66
|
+
args[_i] = arguments[_i];
|
67
|
+
}
|
68
|
+
var Methods = args[0], _a = args[1], props = _a === void 0 ? {} : _a, state = args[2];
|
69
|
+
// Vite HMR seems to sometimes reinitialize useMemo calls after a hot update,
|
70
|
+
// causing the instance to be unexpectedly recreated in the middle of the component's lifecycle.
|
66
71
|
// But useRef and useState values appear to always be preserved whenever this happens.
|
67
72
|
// So those two are the only cross-render-persistence methods we can consider safe.
|
73
|
+
// @todo Provide a way for users to reflect updated methods code on the existing instance after HMR.
|
68
74
|
var methods = (0, react_1.useRef)((0, react_1.useMemo)(function () {
|
69
75
|
return new Methods();
|
70
76
|
}, [])).current;
|
71
|
-
methods.props
|
72
|
-
|
77
|
+
/** A proxy variable to allow typechecking of the assignment to methods.props despite the need for "readonly" error suppression. */
|
78
|
+
var _propsProxy_;
|
79
|
+
// @ts-expect-error
|
80
|
+
methods.props = (_propsProxy_ = props);
|
81
|
+
if (state)
|
82
|
+
methods.state = state;
|
73
83
|
return methods;
|
74
84
|
};
|
75
85
|
exports.useMethods = useMethods;
|
@@ -91,7 +101,8 @@ testing: {
|
|
91
101
|
return [4 /*yield*/, import('./state.js')];
|
92
102
|
case 1:
|
93
103
|
useCleanState = (_a.sent()).useCleanState;
|
94
|
-
self =
|
104
|
+
self = useMethods(MyMethods, {});
|
105
|
+
self.state;
|
95
106
|
return [2 /*return*/];
|
96
107
|
}
|
97
108
|
});
|
package/build/classy/logic.d.ts
CHANGED
@@ -2,13 +2,12 @@ import type { TCleanState, ExtractCleanStateData, TStateData } from '../base/sta
|
|
2
2
|
export type HardEmpty = HardEmptyObject;
|
3
3
|
export type WeakEmpty = WeakEmptyObject;
|
4
4
|
type o = object;
|
5
|
-
export declare class ComponentLogic<TProps extends
|
6
|
-
THooks extends o = WeakEmpty> {
|
5
|
+
export declare class ComponentLogic<TProps extends object = {}, TState extends TStateData = WeakEmpty, THooks extends object = {}> {
|
7
6
|
state: TCleanState<TState>;
|
8
|
-
props: TProps;
|
9
|
-
hooks: THooks;
|
7
|
+
readonly props: TProps;
|
8
|
+
readonly hooks: THooks;
|
10
9
|
static getInitialState: (p?: object) => object;
|
11
|
-
useHooks: THooks extends HardEmptyObject ? undefined | (() =>
|
10
|
+
useHooks: THooks extends HardEmptyObject ? undefined | (() => THooks | void) : () => THooks;
|
12
11
|
}
|
13
12
|
type LogicClassParams = ConstructorParameters<typeof ComponentLogic>;
|
14
13
|
export interface IComponentLogicClass<Instance extends ComponentLogic<o, o, o> = ComponentLogic, Params extends LogicClassParams = LogicClassParams> extends Constructor<Instance, Params> {
|
package/build/classy/logic.js
CHANGED
@@ -33,15 +33,22 @@ var useLogic = function () {
|
|
33
33
|
for (var _i = 0; _i < arguments.length; _i++) {
|
34
34
|
args[_i] = arguments[_i];
|
35
35
|
}
|
36
|
-
var
|
37
|
-
var state = (0, state_1.useCleanState)(
|
38
|
-
var
|
39
|
-
return new
|
36
|
+
var Logic = args[0], _c = args[1], props = _c === void 0 ? {} : _c;
|
37
|
+
var state = (0, state_1.useCleanState)(Logic.getInitialState, props);
|
38
|
+
var self = (0, react_1.useRef)((0, react_1.useMemo)(function () {
|
39
|
+
return new Logic();
|
40
40
|
}, [])).current;
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
/** A proxy variable to allow typechecking of the assignment to `self.props` despite the need for "readonly" error suppression. */
|
42
|
+
var _propsProxy_;
|
43
|
+
/** A proxy variable to allow typechecking of the assignment to `self.hooks` despite the need for "readonly" error suppression. */
|
44
|
+
var _hooksProxy_;
|
45
|
+
self.state = state;
|
46
|
+
// @ts-expect-error
|
47
|
+
self.props = (_propsProxy_ = props);
|
48
|
+
// @ts-expect-error
|
49
|
+
self.hooks = (_hooksProxy_ = (_b = (_a = self.useHooks) === null || _a === void 0 ? void 0 : _a.call(self)) !== null && _b !== void 0 ? _b : {} // @todo Improve UseLogic types to reflect that this may be undefined.
|
50
|
+
);
|
51
|
+
return self;
|
45
52
|
};
|
46
53
|
exports.useLogic = useLogic;
|
47
54
|
testing: {
|