@cleanweb/react 1.1.1-beta.14 → 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.
@@ -1,6 +1,6 @@
1
1
  import type { TCleanState, TStateData } from './state';
2
2
  export declare class ComponentMethods<TProps extends object = {}, TState extends TStateData | null = null> {
3
- props: TProps;
3
+ readonly props: TProps;
4
4
  state: TState extends TStateData ? TCleanState<TState> : null;
5
5
  }
6
6
  type UseMethods = {
@@ -74,7 +74,10 @@ var useMethods = function () {
74
74
  var methods = (0, react_1.useRef)((0, react_1.useMemo)(function () {
75
75
  return new Methods();
76
76
  }, [])).current;
77
- methods.props = props;
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);
78
81
  if (state)
79
82
  methods.state = state;
80
83
  return methods;
@@ -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 o = {}, TState extends TStateData = WeakEmpty, // WeakEmpty,
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 | (() => HardEmptyObject | undefined) : () => THooks;
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> {
@@ -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 Methods = args[0], _c = args[1], props = _c === void 0 ? {} : _c;
37
- var state = (0, state_1.useCleanState)(Methods.getInitialState, props);
38
- var methods = (0, react_1.useRef)((0, react_1.useMemo)(function () {
39
- return new Methods();
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
- methods.state = state;
42
- methods.props = props;
43
- methods.hooks = (_b = (_a = methods.useHooks) === null || _a === void 0 ? void 0 : _a.call(methods)) !== null && _b !== void 0 ? _b : {};
44
- return methods;
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: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleanweb/react",
3
- "version": "1.1.1-beta.14",
3
+ "version": "1.1.1-beta.15",
4
4
  "description": "A suite of helpers for writing cleaner React function components.",
5
5
  "engines": {
6
6
  "node": ">=18"