@cleanweb/react 1.1.1-beta.6 → 1.1.1-beta.8

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.
@@ -6,7 +6,7 @@ type o = object;
6
6
  export interface IComponentClass<Instance extends ClassComponent<o, o, o> = ClassComponent, Params extends ComponentClassParams = ComponentClassParams> extends IComponentInstanceClass<Instance, Params> {
7
7
  }
8
8
  type Extractor = <TComponent extends typeof ClassComponent<o, o, o>>(this: NonNullable<typeof _Component>, _Component?: TComponent & IComponentClass<InstanceType<TComponent>>) => VoidFunctionComponent<InstanceType<TComponent>['props']>;
9
- export declare class ClassComponent<TProps extends o = EmptyObject, TState extends o = EmptyObject, THooks extends o = EmptyObject> extends ComponentInstance<TState, TProps, THooks> {
9
+ export declare class ClassComponent<TProps extends o = EmptyObject, TState extends o = EmptyObject, THooks extends o = EmptyObject> extends ComponentInstance<TProps, TState, THooks> {
10
10
  Render: VoidFunctionComponent<{}>;
11
11
  readonly forceUpdate: VoidFunction;
12
12
  static renderAs: 'component' | 'template';
@@ -110,8 +110,9 @@ testing: {
110
110
  function MyComponentLogic() {
111
111
  return _super !== null && _super.apply(this, arguments) || this;
112
112
  }
113
- MyComponentLogic.getInitialState = function () { return ({}); };
113
+ MyComponentLogic.getInitialState = function () { return ({ a: '' }); };
114
114
  return MyComponentLogic;
115
115
  }(ClassComponent));
116
116
  ;
117
+ var Template = MyComponentLogic.FC();
117
118
  }
@@ -3,7 +3,7 @@ type AsyncAllowedEffectCallback = () => Awaitable<IVoidFunction>;
3
3
  type UseMountCallbacks = <TInstance extends ComponentInstance<any, any, any>>(instance: TInstance) => void;
4
4
  export declare const useMountCallbacks: UseMountCallbacks;
5
5
  export declare const noOp: () => void;
6
- export declare class ComponentInstance<TProps extends o = EmptyObject, TState extends o = EmptyObject, THooks extends o = EmptyObject> extends ComponentLogic<TState, TProps, THooks> {
6
+ export declare class ComponentInstance<TProps extends o = EmptyObject, TState extends o = EmptyObject, THooks extends o = EmptyObject> extends ComponentLogic<TProps, TState, THooks> {
7
7
  /**
8
8
  * Runs only _before_ first render, i.e before the component instance is mounted.
9
9
  * Useful for logic that is involved in determining what to render.
@@ -52,6 +52,9 @@ type o = object;
52
52
  type InstanceClassParams = ConstructorParameters<typeof ComponentInstance<o, o, o>>;
53
53
  export interface IComponentInstanceClass<Instance extends ComponentInstance<o, o, o> = ComponentInstance, Params extends InstanceClassParams = InstanceClassParams> extends IComponentLogicClass<Instance, Params> {
54
54
  }
55
- type UseInstance = <TClass extends typeof ComponentInstance<object, object, object>>(Class: TClass & IComponentInstanceClass<InstanceType<TClass>>, ...props: valueof<InstanceType<TClass>['props']> extends never ? ([] | [EmptyObject] | [InstanceType<TClass>['props']]) : [InstanceType<TClass>['props']]) => InstanceType<TClass>;
56
- export declare const useInstance: UseInstance;
55
+ type UseInstance2 = {
56
+ <Class extends typeof ComponentInstance<EmptyObject, o, o>>(Methods: Class & IComponentInstanceClass<InstanceType<Class>>, ...props: ([] | [EmptyObject])): InstanceType<Class>;
57
+ <Class extends typeof ComponentInstance<o, o, o>>(Methods: Class & IComponentInstanceClass<InstanceType<Class>>, ...props: [InstanceType<Class>['props']]): InstanceType<Class>;
58
+ };
59
+ export declare const useInstance: UseInstance2;
57
60
  export {};
@@ -14,15 +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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
- if (ar || !(i in from)) {
20
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
- ar[i] = from[i];
22
- }
23
- }
24
- return to.concat(ar || Array.prototype.slice.call(from));
25
- };
26
17
  Object.defineProperty(exports, "__esModule", { value: true });
27
18
  exports.useInstance = exports.ComponentInstance = exports.noOp = exports.useMountCallbacks = void 0;
28
19
  var react_1 = require("react");
@@ -118,14 +109,15 @@ exports.ComponentInstance = ComponentInstance;
118
109
  * the second param is given `{}` as a default follow to account for the empty tuple case. TypeScript
119
110
  * just wants us to use the rest parameter explicitly by force.
120
111
  */
121
- var useInstance = function (Component) {
112
+ var useInstance = function () {
122
113
  var _a;
123
114
  var args = [];
124
- for (var _i = 1; _i < arguments.length; _i++) {
125
- args[_i - 1] = arguments[_i];
115
+ for (var _i = 0; _i < arguments.length; _i++) {
116
+ args[_i] = arguments[_i];
126
117
  }
118
+ var Component = args[0], _b = args[1], props = _b === void 0 ? {} : _b;
127
119
  // useHooks.
128
- var instance = logic_1.useLogic.apply(void 0, __spreadArray([Component], args, false)); // Must spread rest parameter, rather than passing a single `props` argument directly.
120
+ var instance = (0, logic_1.useLogic)(Component, props); // Must spread rest parameter, rather than passing a single `props` argument directly.
129
121
  /**
130
122
  * Argument of type '
131
123
  * [
@@ -12,6 +12,9 @@ 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
- 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>;
16
- export declare const useLogic: UseLogic;
17
- export {};
15
+ type UseLogic2 = {
16
+ <Class extends typeof ComponentLogic<Empty, o, o>>(Methods: Class & IComponentLogicClass<InstanceType<Class>>, ...props: ([] | [EmptyObject])): InstanceType<Class>;
17
+ <Class extends typeof ComponentLogic<o, o, o>>(Methods: Class & IComponentLogicClass<InstanceType<Class>>, ...props: [InstanceType<Class>['props']]): InstanceType<Class>;
18
+ };
19
+ declare const useLogic: UseLogic2;
20
+ export { useLogic };
@@ -26,9 +26,13 @@ var ComponentLogic = /** @class */ (function () {
26
26
  }());
27
27
  exports.ComponentLogic = ComponentLogic;
28
28
  ;
29
- var useLogic = function (Methods, props) {
29
+ var useLogic = function () {
30
30
  var _a, _b;
31
- if (props === void 0) { props = {}; }
31
+ var args = [];
32
+ for (var _i = 0; _i < arguments.length; _i++) {
33
+ args[_i] = arguments[_i];
34
+ }
35
+ var Methods = args[0], _c = args[1], props = _c === void 0 ? {} : _c;
32
36
  var state = (0, state_1.useCleanState)(Methods.getInitialState, props);
33
37
  var methods = (0, react_1.useRef)((0, react_1.useMemo)(function () {
34
38
  return new Methods();
@@ -53,21 +57,18 @@ testing: {
53
57
  }(ComponentLogic));
54
58
  ;
55
59
  MyComponentLogic.getInitialState;
56
- var self_1 = (0, exports.useLogic)(MyComponentLogic, {});
60
+ var self_1 = useLogic(MyComponentLogic);
57
61
  }
58
62
  testing: {
59
63
  var A = /** @class */ (function (_super) {
60
64
  __extends(C, _super);
61
65
  function C() {
62
- var _this = _super !== null && _super.apply(this, arguments) || this;
63
- // static getInitialState = () => ({a: 'l'});
64
- _this.b = _this.state.a;
65
- return _this;
66
+ return _super !== null && _super.apply(this, arguments) || this;
66
67
  }
67
68
  return C;
68
69
  }(ComponentLogic));
69
70
  A.getInitialState();
70
- var self_2 = (0, exports.useLogic)(A);
71
+ var self_2 = useLogic(A, { a: 'boo' });
71
72
  }
72
73
  // export type ComponentClassStatics<Instance extends ComponentLogic<object, object, object>> = {
73
74
  // getInitialState: (props?: Instance['props']) => TState<Instance['state']>;
@@ -57,9 +57,7 @@ declare global {
57
57
  ''?: never;
58
58
  };
59
59
  type TEmptyObject2 = Record<symbol, never>;
60
- type EmptyObject = {
61
- [key: keyof any]: never;
62
- };
60
+ type EmptyObject = __FromPrivateHelpers['EmptyObject2'];
63
61
  type EmptyObject2 = __FromPrivateHelpers['EmptyObject2'];
64
62
  type EmptyObject3 = __FromPrivateHelpers['EmptyObject3'];
65
63
  type valueof<TObject> = TObject[keyof TObject];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleanweb/react",
3
- "version": "1.1.1-beta.6",
3
+ "version": "1.1.1-beta.8",
4
4
  "description": "A suite of helpers for writing cleaner React function components.",
5
5
  "engines": {
6
6
  "node": ">=18"