@cleanweb/react 1.1.1-beta.16 → 1.1.1-beta.18

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,4 +1,11 @@
1
1
  import type { TCleanState, TStateData } from './state';
2
+ /**
3
+ * Base class for a class that holds methods intended for use in a function component.
4
+ * These methods will have access to the components state and props via
5
+ * `this.state` and `this.props` respectively.
6
+ *
7
+ * Call the {@link useMethods} hook inside your function component to instantiate the class.
8
+ */
2
9
  export declare class ComponentMethods<TProps extends object = {}, TState extends TStateData | null = null> {
3
10
  readonly props: TProps;
4
11
  state: TState extends TStateData ? TCleanState<TState> : null;
@@ -8,5 +15,11 @@ type UseMethods = {
8
15
  <Class extends typeof ComponentMethods<object, null>>(Methods: Class & Constructor<InstanceType<Class>>, props: InstanceType<Class>['props'], state?: null): InstanceType<Class>;
9
16
  <Class extends typeof ComponentMethods<HardEmptyObject, null>>(Methods: Class & Constructor<InstanceType<Class>>): InstanceType<Class>;
10
17
  };
18
+ /**
19
+ * Returns an instance of the provided class,
20
+ * with the state and props arguments added as instance members.
21
+ *
22
+ * `state` must be an instance of `CleanState` created with {@link useCleanState}.
23
+ */
11
24
  declare const useMethods: UseMethods;
12
25
  export { useMethods };
@@ -1,58 +1,15 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
28
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
2
  Object.defineProperty(exports, "__esModule", { value: true });
54
3
  exports.useMethods = exports.ComponentMethods = void 0;
4
+ // Values
55
5
  var react_1 = require("react");
6
+ /**
7
+ * Base class for a class that holds methods intended for use in a function component.
8
+ * These methods will have access to the components state and props via
9
+ * `this.state` and `this.props` respectively.
10
+ *
11
+ * Call the {@link useMethods} hook inside your function component to instantiate the class.
12
+ */
56
13
  var ComponentMethods = /** @class */ (function () {
57
14
  function ComponentMethods() {
58
15
  }
@@ -60,6 +17,12 @@ var ComponentMethods = /** @class */ (function () {
60
17
  }());
61
18
  exports.ComponentMethods = ComponentMethods;
62
19
  ;
20
+ /**
21
+ * Returns an instance of the provided class,
22
+ * with the state and props arguments added as instance members.
23
+ *
24
+ * `state` must be an instance of `CleanState` created with {@link useCleanState}.
25
+ */
63
26
  var useMethods = function () {
64
27
  var args = [];
65
28
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -83,28 +46,19 @@ var useMethods = function () {
83
46
  return methods;
84
47
  };
85
48
  exports.useMethods = useMethods;
86
- testing: {
87
- var a = function () { return __awaiter(void 0, void 0, void 0, function () {
88
- var a, MyMethods, useCleanState, self;
89
- return __generator(this, function (_a) {
90
- switch (_a.label) {
91
- case 0:
92
- a = { b: '' };
93
- MyMethods = /** @class */ (function (_super) {
94
- __extends(MyMethods, _super);
95
- function MyMethods() {
96
- return _super !== null && _super.apply(this, arguments) || this;
97
- }
98
- return MyMethods;
99
- }(ComponentMethods));
100
- ;
101
- return [4 /*yield*/, import('./state.js')];
102
- case 1:
103
- useCleanState = (_a.sent()).useCleanState;
104
- self = useMethods(MyMethods, {});
105
- self.state;
106
- return [2 /*return*/];
107
- }
108
- });
109
- }); };
110
- }
49
+ /*testing: {
50
+ let a = async () => {
51
+ const a: object = {b: ''};
52
+
53
+ type t = keyof typeof a;
54
+
55
+ class MyMethods extends ComponentMethods<WeakEmptyObject, null> {
56
+ // static getInitialState = () => ({});
57
+ };
58
+
59
+ const { useCleanState } = (await import('./state.js'));
60
+
61
+ const self = useMethods(MyMethods, {});
62
+ self.state;
63
+ }
64
+ }*/
@@ -28,5 +28,9 @@ type StateInitFunction = (...args: any[]) => object;
28
28
  type StateInit = object | StateInitFunction;
29
29
  type TInitialState<Initializer extends StateInit> = Initializer extends (...args: any[]) => (infer TState extends object) ? TState : Initializer;
30
30
  type TUseCleanState = <TInit extends StateInit>(_initialState: TInit, ...props: TInit extends (...args: infer TProps extends any[]) => (infer TState extends object) ? TProps : []) => TCleanState<TInitialState<TInit>>;
31
+ /**
32
+ * Creates a state object, which includes the provided values, and helper methods for
33
+ * updating those values and automatically rerendering your component's UI accordingly.
34
+ */
31
35
  export declare const useCleanState: TUseCleanState;
32
36
  export {};
@@ -118,6 +118,10 @@ var CleanStateBase = /** @class */ (function () {
118
118
  }());
119
119
  ;
120
120
  var CleanState = CleanStateBase;
121
+ /**
122
+ * Creates a state object, which includes the provided values, and helper methods for
123
+ * updating those values and automatically rerendering your component's UI accordingly.
124
+ */
121
125
  var useCleanState = function (_initialState) {
122
126
  var props = [];
123
127
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -8,19 +8,108 @@ type ComponentClassParams = ConstructorParameters<typeof ClassComponent>;
8
8
  type o = object;
9
9
  export interface IComponentClass<Instance extends ClassComponent<o, o, THooksBase> = ClassComponent, Params extends ComponentClassParams = ComponentClassParams> extends IComponentInstanceClass<Instance, Params> {
10
10
  }
11
- type Extractor = <TComponent extends typeof ClassComponent<o, o, o>>(this: NonNullable<typeof _Component>, _Component?: TComponent & IComponentClass<InstanceType<TComponent>>) => VoidFunctionComponent<InstanceType<TComponent>['props']>;
11
+ type Extractor = <TComponent extends typeof ClassComponent<o, o, THooksBase>>(this: NonNullable<typeof _Component>, _Component?: TComponent & IComponentClass<InstanceType<TComponent>>) => VoidFunctionComponent<InstanceType<TComponent>['props']>;
12
12
  type ReactTemplate = React.JSX.Element | null;
13
+ /**
14
+ * A superset of {@link ComponentInstance} that allows defining your
15
+ * component's JSX template directly inside the class.
16
+ *
17
+ * This is designed to closely resemble the old {@link React.Component} class,
18
+ * making it easier to migrate older class components to the newer hooks-based system
19
+ * with little to no changes to their existing semantics/implementation.
20
+ */
13
21
  export declare class ClassComponent<TProps extends o = WeakEmptyObject, TState extends TStateData = WeakEmptyObject, THooks extends THooksBase = void> extends ComponentInstance<TProps, TState, THooks> {
22
+ /**
23
+ * @deprecated An older alternative to {@link template}.
24
+ *
25
+ * Using this will add a component boundary between your JSX template
26
+ * and the function component returned from ClassComponent.FC();
27
+ *
28
+ * This means that from React's perspective, your template won't "own" the state and props it consumes.
29
+ * This could lead to subtle unexpected changes in behaviour.
30
+ *
31
+ * In most cases, you should use {@link template} instead, as it allows your class component
32
+ * to function more predictably as a single unit.
33
+ */
14
34
  Render?: VoidFunctionComponent<{}>;
35
+ /**
36
+ * Your components JSX template. This a variable that should represent what you
37
+ * would normally return from a regular function component.
38
+ *
39
+ * Alternatively, it can be a function that returns the required JSX.
40
+ * The function form is useful if your template references many nested instance members
41
+ * and you would like to destructure them into more easily accessible local variables.
42
+ *
43
+ * Besides that, you should place all other logic in {@link ComponentInstance.beforeRender | `beforeRender`}
44
+ * in order to separate concerns and keep the template itself clean.
45
+ *
46
+ * @example <caption>Using a simple JSX template</caption>
47
+ * template = (
48
+ * <h1>
49
+ * {this.props.title}
50
+ * </h1>
51
+ * );
52
+ *
53
+ * @example <caption>Using a template function that returns JSX.</caption>
54
+ * template = () => {
55
+ * const { title } = this.props;
56
+ *
57
+ * return (
58
+ * <h1>
59
+ * {this.props.title}
60
+ * </h1>
61
+ * );
62
+ * }
63
+ */
15
64
  template?: ReactTemplate | (() => ReactTemplate);
65
+ /**
66
+ * Manually trigger a rerender of your component.
67
+ * You should rarely ever need this. But if you are migrating
68
+ * an older React.Component class, this should provide similar functionality
69
+ * to the {@link Component.forceUpdate | `forceUpdate`} method provided there.
70
+ *
71
+ * Note that the callback argument is currently not supported.
72
+ */
16
73
  readonly forceUpdate: VoidFunction;
74
+ /*************************************
75
+ * Function Component Extractor *
76
+ **************************************/
77
+ /**
78
+ * Extract a function component which can be used to render
79
+ * your ClassComponent just like any other component.
80
+ *
81
+ * Each JSX reference to this returned component will render with
82
+ * a separate instance of your class.
83
+ *
84
+ * So you only need to call `YourClassComponent.FC()` once, then use the returned
85
+ * function component as many times as you need.
86
+ */
17
87
  static readonly FC: Extractor;
18
88
  }
19
89
  interface HookWrapperProps<THookFunction extends AnyFunction> {
90
+ /**
91
+ * The React hook you which to consume.
92
+ * Render a separate instance of the `<Use />` component for each hook.
93
+ * You can also create a custom hook that combines multiple hooks,
94
+ * then use that wrapper hook with a single `<Use />` instance.
95
+ */
20
96
  hook: THookFunction;
97
+ /**
98
+ * An array containing the list of arguments
99
+ * to be passed to your hook, in the right order.
100
+ */
21
101
  argumentsList: Parameters<THookFunction>;
102
+ /**
103
+ * A callback that will be called with whatever value your hook returns.
104
+ * Use this to update your component's state with the value.
105
+ * This will allow your component to rerender whenever the hook returns a new value.
106
+ */
22
107
  onUpdate: (output: ReturnType<THookFunction>) => void;
23
108
  }
24
109
  type ClassComponentHookWrapper = <Hook extends AnyFunction>(props: HookWrapperProps<Hook>) => null;
110
+ /**
111
+ * A component you can use to consume hooks
112
+ * in a {@link Component | React.Component} class component.
113
+ */
25
114
  export declare const Use: ClassComponentHookWrapper;
26
115
  export {};
@@ -43,16 +43,43 @@ var useRerender = function () {
43
43
  };
44
44
  exports.useRerender = useRerender;
45
45
  ;
46
+ /**
47
+ * A superset of {@link ComponentInstance} that allows defining your
48
+ * component's JSX template directly inside the class.
49
+ *
50
+ * This is designed to closely resemble the old {@link React.Component} class,
51
+ * making it easier to migrate older class components to the newer hooks-based system
52
+ * with little to no changes to their existing semantics/implementation.
53
+ */
46
54
  var ClassComponent = /** @class */ (function (_super) {
47
55
  __extends(ClassComponent, _super);
48
56
  function ClassComponent() {
49
57
  return _super !== null && _super.apply(this, arguments) || this;
50
58
  }
59
+ /*************************************
60
+ * Function Component Extractor *
61
+ **************************************/
62
+ // @todo Attempt using implicit `this` value to allow rendering <MyComponent.FC /> directly.
63
+ // const FC = (props) => { const self = useMemo(() => useInstance(this, props), {}); return self.template(); }
64
+ /**
65
+ * Extract a function component which can be used to render
66
+ * your ClassComponent just like any other component.
67
+ *
68
+ * Each JSX reference to this returned component will render with
69
+ * a separate instance of your class.
70
+ *
71
+ * So you only need to call `YourClassComponent.FC()` once, then use the returned
72
+ * function component as many times as you need.
73
+ */
51
74
  ClassComponent.FC = function FC(_Component) {
52
75
  var Component = _Component !== null && _Component !== void 0 ? _Component : this;
53
76
  var isClassComponentType = Component.prototype instanceof ClassComponent;
54
77
  if (!Component.getInitialState || !isClassComponentType)
55
78
  throw new Error('Attempted to initialize ClassComponent with invalid Class type. Either pass a class that extends ClassComponent to FC (e.g `export FC(MyComponent);`), or ensure it is called as a method on a ClassComponent constructor type (e.g `export MyComponent.FC()`).');
79
+ /*************************************
80
+ * Begin Function Component *
81
+ **************************************/
82
+ /** A class-based React function component created with (@cleanweb/react).ClassComponent */
56
83
  var Wrapper = function (props) {
57
84
  var instance = (0, instance_1.useInstance)(Component, props);
58
85
  var Render = instance.Render, template = instance.template;
@@ -106,13 +133,19 @@ var ClassComponent = /** @class */ (function (_super) {
106
133
  default: return template;
107
134
  }
108
135
  };
109
- // Include calling component name in wrapper function name on stack traces.
136
+ /*************************************
137
+ * End Function Component *
138
+ **************************************/
110
139
  setFunctionName(Wrapper, "$".concat(Component.name, "$"));
111
140
  return Wrapper;
112
141
  };
113
142
  return ClassComponent;
114
143
  }(instance_1.ComponentInstance));
115
144
  exports.ClassComponent = ClassComponent;
145
+ /**
146
+ * A component you can use to consume hooks
147
+ * in a {@link Component | React.Component} class component.
148
+ */
116
149
  var Use = function (params) {
117
150
  var useGenericHook = params.hook, argumentsList = params.argumentsList, onUpdate = params.onUpdate;
118
151
  var output = useGenericHook.apply(void 0, argumentsList);
@@ -122,16 +155,3 @@ var Use = function (params) {
122
155
  return null;
123
156
  };
124
157
  exports.Use = Use;
125
- testing: {
126
- var a = { b: '' };
127
- var MyComponentLogic = /** @class */ (function (_super) {
128
- __extends(MyComponentLogic, _super);
129
- function MyComponentLogic() {
130
- return _super !== null && _super.apply(this, arguments) || this;
131
- }
132
- MyComponentLogic.getInitialState = function () { return ({ a: '' }); };
133
- return MyComponentLogic;
134
- }(ClassComponent));
135
- ;
136
- var Template = MyComponentLogic.FC();
137
- }
@@ -2,9 +2,13 @@ import type { TStateData } from '../base/state';
2
2
  import type { THooksBase, IComponentLogicClass } from './logic';
3
3
  import { ComponentLogic } from './logic';
4
4
  type AsyncAllowedEffectCallback = () => Awaitable<IVoidFunction>;
5
- type UseMountCallbacks = <TInstance extends ComponentInstance<any, any, any>>(instance: TInstance) => void;
6
- export declare const useMountCallbacks: UseMountCallbacks;
5
+ /** An empty function. It returns (void) without performing any operations. */
7
6
  export declare const noOp: () => void;
7
+ /**
8
+ * A superset of {@link ComponentLogic} that adds support for special lifecycle methods.
9
+ * This provides a declarative API for working with your React function component's lifecycle,
10
+ * a simpler alternative to the imperative approach with `useEffect` and/or `useMemo`.
11
+ */
8
12
  export declare class ComponentInstance<TProps extends o = {}, TState extends TStateData = WeakEmptyObject, THooks extends THooksBase = void> extends ComponentLogic<TProps, TState, THooks> {
9
13
  /**
10
14
  * Runs only _before_ first render, i.e before the component instance is mounted.
@@ -15,7 +15,7 @@ var __extends = (this && this.__extends) || (function () {
15
15
  };
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.useInstance = exports.ComponentInstance = exports.noOp = exports.useMountCallbacks = void 0;
18
+ exports.useInstance = exports.ComponentInstance = exports.noOp = void 0;
19
19
  var react_1 = require("react");
20
20
  var state_1 = require("../base/state");
21
21
  var logic_1 = require("./logic");
@@ -43,10 +43,15 @@ var useMountCallbacks = function (instance) {
43
43
  };
44
44
  }, []);
45
45
  };
46
- exports.useMountCallbacks = useMountCallbacks;
46
+ /** An empty function. It returns (void) without performing any operations. */
47
47
  var noOp = function () { };
48
48
  exports.noOp = noOp;
49
49
  // @todo Use rollup. Insert globals.ts reference tag to all d.ts output files.
50
+ /**
51
+ * A superset of {@link ComponentLogic} that adds support for special lifecycle methods.
52
+ * This provides a declarative API for working with your React function component's lifecycle,
53
+ * a simpler alternative to the imperative approach with `useEffect` and/or `useMemo`.
54
+ */
50
55
  var ComponentInstance = /** @class */ (function (_super) {
51
56
  __extends(ComponentInstance, _super);
52
57
  function ComponentInstance() {
@@ -134,7 +139,7 @@ var useInstance = function () {
134
139
  '
135
140
  */
136
141
  // beforeMount, onMount, cleanUp.
137
- (0, exports.useMountCallbacks)(instance);
142
+ useMountCallbacks(instance);
138
143
  // beforeRender.
139
144
  (_a = instance.beforeRender) === null || _a === void 0 ? void 0 : _a.call(instance);
140
145
  // onRender.
@@ -151,20 +156,21 @@ var useInstance = function () {
151
156
  return instance;
152
157
  };
153
158
  exports.useInstance = useInstance;
154
- testing: {
155
- var A = /** @class */ (function (_super) {
156
- __extends(A, _super);
157
- function A() {
158
- var _this = _super !== null && _super.apply(this, arguments) || this;
159
- // k = this.props.o
160
- _this.a = _this.state['_initialValues_'];
161
- return _this;
162
- // hard empty has every key
163
- // weak empty has no key
164
- // weak empty is not assignable to hard empty
165
- }
166
- return A;
167
- }(ComponentInstance));
168
- var p = { k: '' };
169
- var a = (0, exports.useInstance)(A, { o: '' });
170
- }
159
+ /*testing: {
160
+ class A extends ComponentInstance {
161
+ static getInitialState: (p?: object) => ({putan: ''});
162
+ // k = this.props.o
163
+ a = this.state['_initialValues_']
164
+
165
+ // hard empty has every key
166
+ // weak empty has no key
167
+ // weak empty is not assignable to hard empty
168
+ }
169
+
170
+ const p = {k: ''}
171
+ const a = useInstance(A, {o: ''});
172
+
173
+ // a.props['o'];
174
+ type bbbb = A['state'];
175
+ type ttt = bbbb['put'];
176
+ }*/
@@ -3,11 +3,46 @@ export type HardEmpty = HardEmptyObject;
3
3
  export type WeakEmpty = WeakEmptyObject;
4
4
  export type THooksBase = o | void;
5
5
  type o = object;
6
- export declare class ComponentLogic<TProps extends object = {}, TState extends TStateData = WeakEmpty, THooks extends THooksBase = void> {
6
+ /**
7
+ * Base class for a class that holds methods intended for use in a function component,
8
+ * as well as a static method for initializing state.
9
+ *
10
+ * These methods will have access to the components state and props via
11
+ * `this.state` and `this.props` respectively.
12
+ *
13
+ * The special {@link ComponentLogic.useHooks | useHooks} method allows you to consume
14
+ * React hooks within this class.
15
+ *
16
+ * Call the {@link useLogic} hook inside your function component to instantiate the class.
17
+ */
18
+ export declare class ComponentLogic<
19
+ /** Describe the values your component expects to be passed as props. */
20
+ TProps extends object = {},
21
+ /** An object type that descibes your component's state. */
22
+ TState extends TStateData = WeakEmpty,
23
+ /** The object type returned by your component's {@link useHooks} method. */
24
+ THooks extends THooksBase = void> {
7
25
  state: TCleanState<TState>;
8
26
  readonly props: TProps;
9
27
  readonly hooks: THooks extends object ? THooks : WeakEmptyObject;
28
+ /**
29
+ * Called before each instance of your component is mounted.
30
+ * It receives the initial `props` object and should return
31
+ * an object with the initial values for your component's state.
32
+ */
10
33
  static getInitialState: (p?: object) => object;
34
+ /**
35
+ * This allows you to seamlessly consume React hooks in
36
+ * your class component.
37
+ *
38
+ * It is called after state and props are updated on each render.
39
+ * Call any hooks (e.g `useEffect`) you which to consume inside this function.
40
+ *
41
+ * To expose any returned values from your hooks to the rest of your component,
42
+ * return an object that contains all the relevant values.
43
+ *
44
+ * This object will be accessible as `this.hooks` to the rest of your class.
45
+ */
11
46
  useHooks: THooks extends void ? undefined | (() => void | HardEmptyObject) : () => THooks;
12
47
  }
13
48
  type LogicClassParams = ConstructorParameters<typeof ComponentLogic>;
@@ -1,27 +1,28 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var _a;
18
2
  Object.defineProperty(exports, "__esModule", { value: true });
19
3
  exports.useLogic = exports.ComponentLogic = void 0;
20
4
  var react_1 = require("react");
21
5
  var state_1 = require("../base/state");
6
+ /**
7
+ * Base class for a class that holds methods intended for use in a function component,
8
+ * as well as a static method for initializing state.
9
+ *
10
+ * These methods will have access to the components state and props via
11
+ * `this.state` and `this.props` respectively.
12
+ *
13
+ * The special {@link ComponentLogic.useHooks | useHooks} method allows you to consume
14
+ * React hooks within this class.
15
+ *
16
+ * Call the {@link useLogic} hook inside your function component to instantiate the class.
17
+ */
22
18
  var ComponentLogic = /** @class */ (function () {
23
19
  function ComponentLogic() {
24
20
  }
21
+ /**
22
+ * Called before each instance of your component is mounted.
23
+ * It receives the initial `props` object and should return
24
+ * an object with the initial values for your component's state.
25
+ */
25
26
  ComponentLogic.getInitialState = function (p) { return ({}); };
26
27
  return ComponentLogic;
27
28
  }());
@@ -51,37 +52,30 @@ var useLogic = function () {
51
52
  return self;
52
53
  };
53
54
  exports.useLogic = useLogic;
54
- testing: {
55
- var a = { b: '' };
56
- var MyComponentLogic = /** @class */ (function (_super) {
57
- __extends(MyComponentLogic, _super);
58
- function MyComponentLogic() {
59
- return _super !== null && _super.apply(this, arguments) || this;
60
- }
61
- MyComponentLogic.getInitialState = function () { return ({ a: '' }); };
62
- return MyComponentLogic;
63
- }(ComponentLogic));
64
- ;
65
- MyComponentLogic.getInitialState;
55
+ /*testing: {
56
+ const a: object = {b: ''};
57
+
58
+ type t = keyof typeof a;
59
+
60
+ class MyComponentLogic extends ComponentLogic<{a: string}> {
61
+ static getInitialState = () => ({a: '' as const});
62
+ // b = this.state.put[''] + this.props.b;
63
+ };
64
+
65
+ type tt = keyof {};
66
+
67
+ MyComponentLogic.getInitialState
66
68
  // const self = useLogic(MyComponentLogic);
67
- }
68
- testing: {
69
- var A = /** @class */ (function (_super) {
70
- __extends(C, _super);
71
- function C() {
72
- return _super !== null && _super.apply(this, arguments) || this;
73
- }
74
- return C;
75
- }(ComponentLogic));
69
+
70
+
71
+ const A = class C extends ComponentLogic {
72
+ // static getInitialState = () => ({a: 'l'});
73
+ // a = () => this.state.yyy = '';
74
+ }
75
+
76
76
  A.getInitialState();
77
+
77
78
  // const oa = {['a' as unknown as symbol]: 'boo'};
78
- var oa = (_a = {}, _a['a'] = 'boo', _a);
79
+ const oa = {['a']: 'boo'};
79
80
  // const self = useLogic(A, oa);
80
- }
81
- // export type ComponentClassStatics<Instance extends ComponentLogic<object, object, object>> = {
82
- // getInitialState: (props?: Instance['props']) => TState<Instance['state']>;
83
- // }
84
- // export type TComponentClass<
85
- // Instance extends ComponentLogic<object, object, object>,
86
- // Params extends CnstPrm = CnstPrm
87
- // > = ComponentClassStatics<Instance> & Constructor<Instance, Params>;
81
+ }*/
package/build/globals.js CHANGED
@@ -2,13 +2,3 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  /////////////
4
4
  var UniqueSecretSymbolKey = Symbol('asdfghjkliuytrewqaxcvb,nb');
5
- testing: {
6
- var mySymbol = Symbol('asdfgh');
7
- var tt = {
8
- // [mySymbol]: '' as never,
9
- // [UniqueSecretSymbolKey]: '',
10
- // '': '',
11
- };
12
- var TT = {};
13
- TT = tt;
14
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleanweb/react",
3
- "version": "1.1.1-beta.16",
3
+ "version": "1.1.1-beta.18",
4
4
  "description": "A suite of helpers for writing cleaner React function components.",
5
5
  "engines": {
6
6
  "node": ">=18"