@cleanweb/react 1.0.8 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- package/build/base/methods.js +5 -13
- package/build/base/state.d.ts +4 -3
- package/build/base/state.js +1 -0
- package/build/classy/logic.d.ts +1 -1
- package/build/classy/logic.js +2 -13
- package/build/globals.d.ts +3 -0
- package/package.json +1 -1
package/build/base/methods.js
CHANGED
@@ -1,15 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
3
|
-
__assign = Object.assign || function(t) {
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
-
s = arguments[i];
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
-
t[p] = s[p];
|
8
|
-
}
|
9
|
-
return t;
|
10
|
-
};
|
11
|
-
return __assign.apply(this, arguments);
|
12
|
-
};
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
14
3
|
exports.useMethods = exports.ComponentMethods = void 0;
|
15
4
|
var react_1 = require("react");
|
@@ -21,13 +10,16 @@ var ComponentMethods = /** @class */ (function () {
|
|
21
10
|
exports.ComponentMethods = ComponentMethods;
|
22
11
|
;
|
23
12
|
var useMethods = function (Methods, state, props) {
|
13
|
+
// @todo Switch to useRef. Vite HMR seems to sometimes reinitialize useMemo calls after a hot update,
|
14
|
+
// causing the instance to be unexpectedly recreated in the middle of the components lifecycle.
|
15
|
+
// But useRef and useState values appear to always be preserved whenever this happens.
|
16
|
+
// So those two are the only cross-render-persistence methods we can consider safe.
|
24
17
|
var methods = (0, react_1.useMemo)(function () {
|
25
18
|
// See useLogic implementation for a discussion of this type assertion.
|
26
19
|
return new Methods();
|
27
20
|
}, []);
|
28
21
|
methods.state = state;
|
29
22
|
methods.props = props;
|
30
|
-
|
31
|
-
return __assign(__assign({}, methods), { props: undefined, state: undefined });
|
23
|
+
return methods;
|
32
24
|
};
|
33
25
|
exports.useMethods = useMethods;
|
package/build/base/state.d.ts
CHANGED
@@ -12,9 +12,10 @@ declare class CleanStateBase<TState extends object> {
|
|
12
12
|
}
|
13
13
|
type TCleanStateInstance<TState extends object> = TState & CleanStateBase<TState>;
|
14
14
|
export type TCleanState<TState extends object> = TCleanStateInstance<TState>;
|
15
|
-
type
|
16
|
-
type
|
17
|
-
|
15
|
+
type StateInitFunction = (props?: object) => object;
|
16
|
+
type TInitialState<StateParamType> = StateParamType extends StateInitFunction ? ReturnType<StateParamType> : StateParamType;
|
17
|
+
type StateInitParameters<StateInitializer> = StateInitializer extends StateInitFunction ? Parameters<StateInitializer> : [];
|
18
|
+
type UseCleanState = <StateInitializer extends StateInitFunction | object>(_initialState: StateInitializer, ...props: StateInitParameters<StateInitializer>) => TCleanState<TInitialState<StateInitializer>>;
|
18
19
|
export declare const useCleanState: UseCleanState;
|
19
20
|
/**
|
20
21
|
* Returns a value that is false before the component has been mounted,
|
package/build/base/state.js
CHANGED
@@ -93,6 +93,7 @@ var CleanStateBase = /** @class */ (function () {
|
|
93
93
|
;
|
94
94
|
var CleanState = CleanStateBase;
|
95
95
|
var useCleanState = function (_initialState, props) {
|
96
|
+
if (props === void 0) { props = {}; }
|
96
97
|
var initialState = typeof _initialState === 'function' ? (0, react_1.useMemo)(function () { return _initialState(props); }, []) : _initialState;
|
97
98
|
var cleanState = (0, react_1.useMemo)(function () { return new CleanState(initialState); }, []);
|
98
99
|
CleanState.update.call(cleanState);
|
package/build/classy/logic.d.ts
CHANGED
@@ -8,6 +8,6 @@ export declare class ComponentLogic<TState extends object, TProps extends object
|
|
8
8
|
export interface ComponentLogicConstructor<TState extends object, TProps extends object, THooks extends object> extends Constructor<ComponentLogic<TState, TProps, THooks>> {
|
9
9
|
getInitialState: (props?: TProps) => TState;
|
10
10
|
}
|
11
|
-
type UseLogic = <
|
11
|
+
type UseLogic = <LogicClass extends ComponentLogicConstructor<{}, object, any>>(Methods: LogicClass, props?: InstanceType<LogicClass>['props']) => InstanceType<LogicClass>;
|
12
12
|
export declare const useLogic: UseLogic;
|
13
13
|
export {};
|
package/build/classy/logic.js
CHANGED
@@ -1,15 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
3
|
-
__assign = Object.assign || function(t) {
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5
|
-
s = arguments[i];
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7
|
-
t[p] = s[p];
|
8
|
-
}
|
9
|
-
return t;
|
10
|
-
};
|
11
|
-
return __assign.apply(this, arguments);
|
12
|
-
};
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
14
3
|
exports.useLogic = exports.ComponentLogic = void 0;
|
15
4
|
var react_1 = require("react");
|
@@ -23,6 +12,7 @@ exports.ComponentLogic = ComponentLogic;
|
|
23
12
|
;
|
24
13
|
var useLogic = function (Methods, props) {
|
25
14
|
var _a;
|
15
|
+
if (props === void 0) { props = {}; }
|
26
16
|
var state = (0, state_1.useCleanState)(Methods.getInitialState, props);
|
27
17
|
// There's apparently a bug? with Typescript that pegs the return type of "new Methods()" to "ComponentLogic<{}, {}, {}>",
|
28
18
|
// completely ignoring the type specified for Methods in the function's type definition.
|
@@ -36,7 +26,6 @@ var useLogic = function (Methods, props) {
|
|
36
26
|
methods.state = state;
|
37
27
|
methods.props = props;
|
38
28
|
methods.hooks = ((_a = methods.useHooks) === null || _a === void 0 ? void 0 : _a.call(methods)) || {};
|
39
|
-
|
40
|
-
return __assign(__assign({}, methods), { useHooks: undefined });
|
29
|
+
return methods;
|
41
30
|
};
|
42
31
|
exports.useLogic = useLogic;
|
package/build/globals.d.ts
CHANGED