@cleanweb/react 1.1.1-beta.3 → 1.1.1-beta.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,6 @@ export declare class ComponentMethods<TState extends object, TProps extends obje
3
3
  state: TCleanState<TState>;
4
4
  props: TProps;
5
5
  }
6
- type UseMethods = <TMethods extends typeof ComponentMethods<any, any>>(Methods: TMethods & Constructor<InstanceType<TMethods>>, state: InstanceType<TMethods>['state'], props: InstanceType<TMethods>['props']) => InstanceType<TMethods>;
6
+ type UseMethods = <Class extends typeof ComponentMethods<object, object>>(Methods: Class & Constructor<InstanceType<Class>>, state: InstanceType<Class>['state'], props: InstanceType<Class>['props']) => InstanceType<Class>;
7
7
  export declare const useMethods: UseMethods;
8
8
  export {};
@@ -5,14 +5,13 @@ export declare class ComponentLogic<TState extends o = Empty, TProps extends o =
5
5
  state: TCleanState<TState>;
6
6
  props: TProps;
7
7
  hooks: THooks;
8
- static getInitialState: TBaseComponentLogic['getInitialState'];
8
+ static getInitialState: (p?: o) => {};
9
9
  useHooks?: () => THooks;
10
10
  }
11
11
  type LogicClassParams = ConstructorParameters<typeof ComponentLogic>;
12
12
  export interface IComponentLogicClass<Instance extends ComponentLogic<o, o, o> = ComponentLogic, Params extends LogicClassParams = LogicClassParams> extends Constructor<Instance, Params> {
13
13
  getInitialState: (props?: Instance['props']) => TState<Instance['state']>;
14
14
  }
15
- export type TBaseComponentLogic = IComponentLogicClass<ComponentLogic<o, o, o>>;
16
15
  type UseLogic = <Class extends typeof ComponentLogic<o, o, o>>(Methods: Class & IComponentLogicClass<InstanceType<Class>>, ...props: valueof<InstanceType<Class>['props']> extends never ? ([] | [EmptyObject] | [InstanceType<Class>['props']]) : [InstanceType<Class>['props']]) => InstanceType<Class>;
17
16
  export declare const useLogic: UseLogic;
18
17
  export {};
@@ -14,7 +14,6 @@ var __extends = (this && this.__extends) || (function () {
14
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
15
  };
16
16
  })();
17
- var _a;
18
17
  Object.defineProperty(exports, "__esModule", { value: true });
19
18
  exports.useLogic = exports.ComponentLogic = void 0;
20
19
  var react_1 = require("react");
@@ -23,12 +22,13 @@ var state_1 = require("../base/state");
23
22
  var ComponentLogic = /** @class */ (function () {
24
23
  function ComponentLogic() {
25
24
  }
25
+ ComponentLogic.getInitialState = function (p) { return ({}); };
26
26
  return ComponentLogic;
27
27
  }());
28
28
  exports.ComponentLogic = ComponentLogic;
29
29
  ;
30
30
  var useLogic = function (Methods, props) {
31
- var _b, _c;
31
+ var _a, _b;
32
32
  if (props === void 0) { props = {}; }
33
33
  var state = (0, state_1.useCleanState)(Methods.getInitialState, props);
34
34
  var methods = (0, react_1.useRef)((0, react_1.useMemo)(function () {
@@ -36,7 +36,7 @@ var useLogic = function (Methods, props) {
36
36
  }, [])).current;
37
37
  methods.state = state;
38
38
  methods.props = props;
39
- methods.hooks = (_c = (_b = methods.useHooks) === null || _b === void 0 ? void 0 : _b.call(methods)) !== null && _c !== void 0 ? _c : {};
39
+ methods.hooks = (_b = (_a = methods.useHooks) === null || _a === void 0 ? void 0 : _a.call(methods)) !== null && _b !== void 0 ? _b : {};
40
40
  return methods;
41
41
  };
42
42
  exports.useLogic = useLogic;
@@ -45,28 +45,30 @@ testing: {
45
45
  var MyComponentLogic = /** @class */ (function (_super) {
46
46
  __extends(MyComponentLogic, _super);
47
47
  function MyComponentLogic() {
48
- return _super !== null && _super.apply(this, arguments) || this;
48
+ var _this = _super !== null && _super.apply(this, arguments) || this;
49
+ _this.b = _this.state.a;
50
+ return _this;
49
51
  }
50
- MyComponentLogic.getInitialState = function () { return ({}); };
52
+ MyComponentLogic.getInitialState = function (p) { return ({ a: '' }); };
51
53
  return MyComponentLogic;
52
54
  }(ComponentLogic));
53
55
  ;
54
- var self_1 = (0, exports.useLogic)(MyComponentLogic);
56
+ MyComponentLogic.getInitialState;
57
+ var self_1 = (0, exports.useLogic)(MyComponentLogic, {});
55
58
  }
56
59
  testing: {
57
- var A = (_a = /** @class */ (function (_super) {
58
- __extends(C, _super);
59
- function C() {
60
- var _this = _super !== null && _super.apply(this, arguments) || this;
61
- _this.b = _this.state.a;
62
- return _this;
63
- }
64
- return C;
65
- }(ComponentLogic)),
66
- _a.getInitialState = function () { return ({ a: 'l' }); },
67
- _a);
60
+ var A = /** @class */ (function (_super) {
61
+ __extends(C, _super);
62
+ function C() {
63
+ var _this = _super !== null && _super.apply(this, arguments) || this;
64
+ // static getInitialState = () => ({a: 'l'});
65
+ _this.b = _this.state.a;
66
+ return _this;
67
+ }
68
+ return C;
69
+ }(ComponentLogic));
68
70
  A.getInitialState();
69
- // const self = useLogic(A);
71
+ var self_2 = (0, exports.useLogic)(A);
70
72
  }
71
73
  // export type ComponentClassStatics<Instance extends ComponentLogic<object, object, object>> = {
72
74
  // getInitialState: (props?: Instance['props']) => TState<Instance['state']>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleanweb/react",
3
- "version": "1.1.1-beta.3",
3
+ "version": "1.1.1-beta.5",
4
4
  "description": "A suite of helpers for writing cleaner React function components.",
5
5
  "engines": {
6
6
  "node": ">=18"