@cleanweb/react 1.0.9 → 1.0.11
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.js +4 -0
- package/build/base/state.d.ts +4 -3
- package/build/base/state.js +6 -2
- package/build/classy/logic.d.ts +1 -1
- package/build/classy/logic.js +1 -0
- package/build/globals.d.ts +3 -0
- package/package.json +1 -1
package/build/base/methods.js
CHANGED
@@ -10,6 +10,10 @@ var ComponentMethods = /** @class */ (function () {
|
|
10
10
|
exports.ComponentMethods = ComponentMethods;
|
11
11
|
;
|
12
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.
|
13
17
|
var methods = (0, react_1.useMemo)(function () {
|
14
18
|
// See useLogic implementation for a discussion of this type assertion.
|
15
19
|
return new Methods();
|
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 TFunctionType = (...args: any) => object;
|
16
|
+
type TInitialState<StateParamType> = StateParamType extends TFunctionType ? ReturnType<StateParamType> : StateParamType;
|
17
|
+
type StateInitParameters<StateInitializer> = StateInitializer extends TFunctionType ? Parameters<StateInitializer> : [];
|
18
|
+
type UseCleanState = <StateInitializer extends TFunctionType | object>(_initialState: StateInitializer, ...props: StateInitParameters<StateInitializer>) => TCleanStateInstance<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
@@ -92,8 +92,12 @@ var CleanStateBase = /** @class */ (function () {
|
|
92
92
|
}());
|
93
93
|
;
|
94
94
|
var CleanState = CleanStateBase;
|
95
|
-
var useCleanState = function (_initialState
|
96
|
-
var
|
95
|
+
var useCleanState = function (_initialState) {
|
96
|
+
var props = [];
|
97
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
98
|
+
props[_i - 1] = arguments[_i];
|
99
|
+
}
|
100
|
+
var initialState = typeof _initialState === 'function' ? (0, react_1.useMemo)(function () { return _initialState.apply(void 0, props); }, []) : _initialState;
|
97
101
|
var cleanState = (0, react_1.useMemo)(function () { return new CleanState(initialState); }, []);
|
98
102
|
CleanState.update.call(cleanState);
|
99
103
|
return 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
@@ -12,6 +12,7 @@ exports.ComponentLogic = ComponentLogic;
|
|
12
12
|
;
|
13
13
|
var useLogic = function (Methods, props) {
|
14
14
|
var _a;
|
15
|
+
if (props === void 0) { props = {}; }
|
15
16
|
var state = (0, state_1.useCleanState)(Methods.getInitialState, props);
|
16
17
|
// There's apparently a bug? with Typescript that pegs the return type of "new Methods()" to "ComponentLogic<{}, {}, {}>",
|
17
18
|
// completely ignoring the type specified for Methods in the function's type definition.
|
package/build/globals.d.ts
CHANGED