@cleanweb/react 1.1.1-beta.24 → 1.1.1-beta.27

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.
Files changed (35) hide show
  1. package/build/classy/{class.d.ts → class/index.d.ts} +6 -41
  2. package/build/classy/{class.js → class/index.js} +12 -46
  3. package/build/classy/class/types/class/instance.d.ts +13 -0
  4. package/build/classy/class/types/class/static.d.ts +9 -0
  5. package/build/classy/class/types/class/static.js +12 -0
  6. package/build/classy/class/types/extractor.d.ts +6 -0
  7. package/build/classy/class/utils/function-name.d.ts +2 -0
  8. package/build/classy/class/utils/function-name.js +17 -0
  9. package/build/classy/class/utils/rerender.d.ts +1 -0
  10. package/build/classy/class/utils/rerender.js +11 -0
  11. package/build/classy/class/utils/use-component/index.d.ts +6 -0
  12. package/build/classy/class/utils/use-component/index.js +17 -0
  13. package/build/classy/class/utils/use-component/types.d.ts +22 -0
  14. package/build/classy/{instance.d.ts → instance/index.d.ts} +14 -17
  15. package/build/classy/{instance.js → instance/index.js} +15 -30
  16. package/build/classy/instance/mount-callbacks.d.ts +4 -0
  17. package/build/classy/instance/mount-callbacks.js +30 -0
  18. package/build/classy/instance/types/hook.d.ts +17 -0
  19. package/build/classy/instance/types/hook.js +2 -0
  20. package/build/classy/instance/types/instance.d.ts +12 -0
  21. package/build/classy/instance/types/instance.js +2 -0
  22. package/build/classy/instance/types/static.d.ts +11 -0
  23. package/build/classy/instance/types/static.js +17 -0
  24. package/build/classy/logic/index.d.ts +3 -3
  25. package/build/classy/logic/{hook-types.d.ts → types/hook.d.ts} +3 -3
  26. package/build/classy/logic/types/hook.js +2 -0
  27. package/build/classy/logic/{instance-types.d.ts → types/instance.d.ts} +3 -3
  28. package/build/classy/logic/types/instance.js +2 -0
  29. package/build/classy/logic/{static-types.d.ts → types/static.d.ts} +4 -4
  30. package/build/classy/logic/types/static.js +2 -0
  31. package/build/globals.d.ts +1 -1
  32. package/package.json +7 -5
  33. /package/build/classy/{logic/hook-types.js → class/types/class/instance.js} +0 -0
  34. /package/build/classy/{logic/instance-types.js → class/types/extractor.js} +0 -0
  35. /package/build/classy/{logic/static-types.js → class/utils/use-component/types.js} +0 -0
@@ -1,18 +1,9 @@
1
1
  import type { VoidFunctionComponent } from 'react';
2
- import type { TStateData } from '../base';
3
- import type { IComponentInstanceClass } from './instance';
4
- import { ComponentInstance } from './instance';
5
- import { THooksBase } from './logic';
6
- export declare const useRerender: () => () => void;
2
+ import type { TStateData } from '../../base';
3
+ import type { THooksBase } from '../logic';
4
+ import type { Extractor } from './types/extractor';
5
+ import { ComponentInstance } from '../instance';
7
6
  type o = object;
8
- type ComponentClassOwnStaticKeys = Exclude<keyof typeof ClassComponent, keyof IComponentInstanceClass>;
9
- type ComponentClassOwnStatics = {
10
- [Key in ComponentClassOwnStaticKeys]: (typeof ClassComponent)[Key];
11
- };
12
- export interface IComponentClass<Instance extends ClassComponent<o, o, THooksBase> = ClassComponent> extends Constructor<Instance>, ComponentClassOwnStatics, IComponentInstanceClass<Instance> {
13
- }
14
- type BaseClassComponent = ClassComponent<o, o, THooksBase>;
15
- type Extractor = <TComponent extends IComponentClass<BaseClassComponent>>(this: NonNullable<typeof _Component>, _Component?: TComponent) => VoidFunctionComponent<InstanceType<TComponent>['props']>;
16
7
  /**
17
8
  * A superset of {@link ComponentInstance} that allows defining your
18
9
  * component's JSX template directly inside the class.
@@ -71,7 +62,7 @@ export declare class ClassComponent<TProps extends o = WeakEmptyObject, TState e
71
62
  * Manually trigger a rerender of your component.
72
63
  * You should rarely ever need this. But if you are migrating
73
64
  * an older React.Component class, this should provide similar functionality
74
- * to the {@link Component.forceUpdate | `forceUpdate`} method provided there.
65
+ * to the {@link React.Component.forceUpdate | `forceUpdate`} method provided there.
75
66
  *
76
67
  * Note that the callback argument is currently not supported.
77
68
  */
@@ -106,33 +97,7 @@ export declare class ClassComponent<TProps extends o = WeakEmptyObject, TState e
106
97
  /** @see {@link ClassComponent.FC} */
107
98
  static readonly extract: Extractor;
108
99
  }
109
- interface HookWrapperProps<THookFunction extends AnyFunction> {
110
- /**
111
- * The React hook you which to consume.
112
- * Render a separate instance of the `<Use />` component for each hook.
113
- * You can also create a custom hook that combines multiple hooks,
114
- * then use that wrapper hook with a single `<Use />` instance.
115
- */
116
- hook: THookFunction;
117
- /**
118
- * An array containing the list of arguments
119
- * to be passed to your hook, in the right order.
120
- */
121
- argumentsList: Parameters<THookFunction>;
122
- /**
123
- * A callback that will be called with whatever value your hook returns.
124
- * Use this to update your component's state with the value.
125
- * This will allow your component to rerender whenever the hook returns a new value.
126
- */
127
- onUpdate: (output: ReturnType<THookFunction>) => void;
128
- }
129
- type ClassComponentHookWrapper = <Hook extends AnyFunction>(props: HookWrapperProps<Hook>) => null;
130
- /**
131
- * A component you can use to consume hooks
132
- * in a {@link Component | React.Component} class component.
133
- */
134
- export declare const Use: ClassComponentHookWrapper;
135
- export {};
100
+ export { ClassComponent as Component };
136
101
  /** /testing: {
137
102
  const a: object = {b: ''};
138
103
 
@@ -15,34 +15,12 @@ var __extends = (this && this.__extends) || (function () {
15
15
  };
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.Use = exports.ClassComponent = exports.useRerender = void 0;
18
+ exports.Component = exports.ClassComponent = void 0;
19
19
  var jsx_runtime_1 = require("react/jsx-runtime");
20
20
  var react_1 = require("react");
21
- var instance_1 = require("./instance");
22
- /** Provide more useful stack traces for otherwise non-specific function names. */
23
- var setFunctionName = function (func, newName) {
24
- try {
25
- // Must use try block, as `name` is not configurable on older browsers, and may yield a TypeError.
26
- Object.defineProperty(func, 'name', {
27
- writable: true,
28
- value: newName,
29
- });
30
- }
31
- catch (error) {
32
- console.warn(error);
33
- }
34
- };
35
- var useRerender = function () {
36
- /*
37
- * Skip the value, we don't need it.
38
- * Grab just the setter function.
39
- */
40
- var _a = (0, react_1.useState)(Date.now()), _forceRerender = _a[1];
41
- var rerender = function () { return _forceRerender(Date.now()); };
42
- return rerender;
43
- };
44
- exports.useRerender = useRerender;
45
- ;
21
+ var instance_1 = require("../instance");
22
+ var function_name_1 = require("./utils/function-name");
23
+ var rerender_1 = require("./utils/rerender");
46
24
  /**
47
25
  * A superset of {@link ComponentInstance} that allows defining your
48
26
  * component's JSX template directly inside the class.
@@ -92,20 +70,20 @@ var ClassComponent = /** @class */ (function (_super) {
92
70
  /*************************************
93
71
  * Begin Function Component *
94
72
  **************************************/
95
- /** A class-based React function component created with (@cleanweb/react).ClassComponent */
73
+ /** A class-based React function component created with (@cleanweb/react).{@link ClassComponent} */
96
74
  var Wrapper = function (props) {
97
75
  var instance = (0, instance_1.useInstance)(Component, props);
98
76
  var Render = instance.Render, template = instance.template;
99
77
  var _forceUpdate;
100
78
  // @ts-expect-error (Cannot assign to 'forceUpdate' because it is a read-only property.ts(2540))
101
- instance.forceUpdate = (_forceUpdate = (0, exports.useRerender)() // Moved this to separate line to allow TS errors. Use proxy local variable to regain some type checking for the assignment to `instance.forceUpdate`.
79
+ instance.forceUpdate = (_forceUpdate = (0, rerender_1.useRerender)() // Moved this to separate line to allow TS errors. Use proxy local variable to regain some type checking for the assignment to `instance.forceUpdate`.
102
80
  );
103
81
  // Add calling component name to Render function name in stack traces.
104
82
  (0, react_1.useMemo)(function () {
105
83
  if (typeof template === 'function')
106
- setFunctionName(template, "".concat(Component.name, ".template"));
84
+ (0, function_name_1.setFunctionName)(template, "".concat(Component.name, ".template"));
107
85
  else if (typeof Render === 'function')
108
- setFunctionName(Render, "".concat(Component.name, ".Render"));
86
+ (0, function_name_1.setFunctionName)(Render, "".concat(Component.name, ".Render"));
109
87
  }, [Render, template]);
110
88
  /**
111
89
  * Normally a component can update it's own state in the "before-render" stage to
@@ -146,10 +124,10 @@ var ClassComponent = /** @class */ (function (_super) {
146
124
  default: return template;
147
125
  }
148
126
  };
149
- /*************************************
150
- * End Function Component *
127
+ /**************************************
128
+ * End Function Component *
151
129
  **************************************/
152
- setFunctionName(Wrapper, "$".concat(Component.name, "$"));
130
+ (0, function_name_1.setFunctionName)(Wrapper, "$".concat(Component.name, "$"));
153
131
  return Wrapper;
154
132
  };
155
133
  /** @see {@link ClassComponent.FC} */
@@ -157,16 +135,4 @@ var ClassComponent = /** @class */ (function (_super) {
157
135
  return ClassComponent;
158
136
  }(instance_1.ComponentInstance));
159
137
  exports.ClassComponent = ClassComponent;
160
- /**
161
- * A component you can use to consume hooks
162
- * in a {@link Component | React.Component} class component.
163
- */
164
- var Use = function (params) {
165
- var useGenericHook = params.hook, argumentsList = params.argumentsList, onUpdate = params.onUpdate;
166
- var output = useGenericHook.apply(void 0, argumentsList);
167
- (0, react_1.useEffect)(function () {
168
- onUpdate(output);
169
- }, [output]);
170
- return null;
171
- };
172
- exports.Use = Use;
138
+ exports.Component = ClassComponent;
@@ -0,0 +1,13 @@
1
+ import type { THooksBase } from '../../../../classy/logic';
2
+ import type { ExtractCleanStateData } from '../../../../base';
3
+ import type { InstanceOverrides as CIInstanceOverrides } from '../../../../classy/instance/types/instance';
4
+ import { ClassComponent } from '../../../../classy/class';
5
+ export type BaseClassComponent = ClassComponent<object, object, THooksBase>;
6
+ export type CCBaseType = ClassComponent<object, object, THooksBase>;
7
+ type CCFromSubType<SubType extends CCBaseType> = ClassComponent<SubType['props'], ExtractCleanStateData<SubType['state']>, SubType['_thooks']>;
8
+ export interface InstanceOverrides<Instance extends CCBaseType = ClassComponent> extends CIInstanceOverrides<Instance> {
9
+ }
10
+ type BaseInstance<Instance extends CCBaseType = ClassComponent> = Omit<CCFromSubType<Instance>, keyof InstanceOverrides>;
11
+ export interface IClassComponent<Instance extends CCBaseType = ClassComponent> extends BaseInstance<Instance>, InstanceOverrides<Instance> {
12
+ }
13
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { StaticOverrides as CIStaticOverrides } from '../../../../classy/instance/types/static';
2
+ import type { CCBaseType } from './instance';
3
+ import { ClassComponent } from '../..';
4
+ export interface StaticOverrides<Instance extends CCBaseType = ClassComponent> extends CIStaticOverrides<Instance> {
5
+ }
6
+ type BaseStatics = Omit<typeof ClassComponent, 'prototype' | keyof StaticOverrides>;
7
+ export interface IClassComponentConstructor<Instance extends CCBaseType = ClassComponent> extends BaseStatics, StaticOverrides<Instance> {
8
+ }
9
+ export {};
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // type ComponentClassOwnStaticKeys = Exclude<
4
+ // keyof typeof ClassComponent,
5
+ // keyof IComponentInstanceClass
6
+ // >;
7
+ // type ComponentClassOwnStatics = {
8
+ // [Key in ComponentClassOwnStaticKeys]: (typeof ClassComponent)[Key];
9
+ // }
10
+ // export interface ClassComponentConstructor<
11
+ // Instance extends BaseClassComponent = ClassComponent
12
+ // > extends Constructor<Instance>, ComponentClassOwnStatics, IComponentInstanceClass<Instance> {};
@@ -0,0 +1,6 @@
1
+ import type { VoidFunctionComponent } from 'react';
2
+ import type { BaseClassComponent, IClassComponent } from './class/instance';
3
+ import type { IClassComponentConstructor } from './class/static';
4
+ type BaseCCConstructor = IClassComponentConstructor<BaseClassComponent>;
5
+ export type Extractor = <TComponent extends BaseCCConstructor>(this: TComponent & Constructor<IClassComponent<InstanceType<TComponent>>>, Component?: TComponent & Constructor<IClassComponent<InstanceType<TComponent>>>) => VoidFunctionComponent<InstanceType<TComponent>['props']>;
6
+ export {};
@@ -0,0 +1,2 @@
1
+ /** Provide more useful stack traces for otherwise non-specific function names. */
2
+ export declare const setFunctionName: (func: FunctionType, newName: string) => void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setFunctionName = void 0;
4
+ /** Provide more useful stack traces for otherwise non-specific function names. */
5
+ var setFunctionName = function (func, newName) {
6
+ try {
7
+ // Must use try block, as `name` is not configurable on older browsers, and may yield a TypeError.
8
+ Object.defineProperty(func, 'name', {
9
+ writable: true,
10
+ value: newName,
11
+ });
12
+ }
13
+ catch (error) {
14
+ console.warn(error);
15
+ }
16
+ };
17
+ exports.setFunctionName = setFunctionName;
@@ -0,0 +1 @@
1
+ export declare const useRerender: () => () => void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRerender = void 0;
4
+ var react_1 = require("react");
5
+ var useRerender = function () {
6
+ // Skip the value, we don't need it. Grab just the setter function.
7
+ var _a = (0, react_1.useState)(Date.now()), _forceRerender = _a[1];
8
+ var rerender = function () { return _forceRerender(Date.now()); };
9
+ return rerender;
10
+ };
11
+ exports.useRerender = useRerender;
@@ -0,0 +1,6 @@
1
+ import type { ClassComponentHookWrapper } from './types';
2
+ /**
3
+ * A component you can use to consume hooks
4
+ * in a {@link Component | React.Component} class component.
5
+ */
6
+ export declare const Use: ClassComponentHookWrapper;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Use = void 0;
4
+ var react_1 = require("react");
5
+ /**
6
+ * A component you can use to consume hooks
7
+ * in a {@link Component | React.Component} class component.
8
+ */
9
+ var Use = function (params) {
10
+ var useGenericHook = params.hook, argumentsList = params.argumentsList, onUpdate = params.onUpdate;
11
+ var output = useGenericHook.apply(void 0, argumentsList);
12
+ (0, react_1.useEffect)(function () {
13
+ onUpdate(output);
14
+ }, [output]);
15
+ return null;
16
+ };
17
+ exports.Use = Use;
@@ -0,0 +1,22 @@
1
+ interface HookWrapperProps<THookFunction extends AnyFunction> {
2
+ /**
3
+ * The React hook you which to consume.
4
+ * Render a separate instance of the `<Use />` component for each hook.
5
+ * You can also create a custom hook that combines multiple hooks,
6
+ * then use that wrapper hook with a single `<Use />` instance.
7
+ */
8
+ hook: THookFunction;
9
+ /**
10
+ * An array containing the list of arguments
11
+ * to be passed to your hook, in the right order.
12
+ */
13
+ argumentsList: Parameters<THookFunction>;
14
+ /**
15
+ * A callback that will be called with whatever value your hook returns.
16
+ * Use this to update your component's state with the value.
17
+ * This will allow your component to rerender whenever the hook returns a new value.
18
+ */
19
+ onUpdate: (output: ReturnType<THookFunction>) => void;
20
+ }
21
+ export type ClassComponentHookWrapper = <Hook extends AnyFunction>(props: HookWrapperProps<Hook>) => null;
22
+ export {};
@@ -1,11 +1,15 @@
1
- import type { ExtractCleanStateData, TStateData } from '../base/state';
2
- import type { THooksBase } from './logic';
3
- import { ComponentLogic } from './logic';
1
+ import type { TStateData } from '../../base/state';
2
+ import type { THooksBase } from '../../classy/logic';
3
+ import type { UseInstance } from './types/hook';
4
+ import type { CIBaseType, IComponentInstance } from './types/instance';
5
+ import type { IComponentInstanceClass } from './types/static';
6
+ import { ComponentLogic } from '../../classy/logic';
4
7
  type AsyncAllowedEffectCallback = () => Awaitable<IVoidFunction>;
8
+ type o = object;
5
9
  /** An empty function. It returns (void) without performing any operations. */
6
10
  export declare const noOp: () => void;
7
11
  /**
8
- * A superset of {@link ComponentLogic} that adds support for special lifecycle methods.
12
+ * A superset of {@link ComponentLogic} that adds support for lifecycle methods.
9
13
  * This provides a declarative API for working with your React function component's lifecycle,
10
14
  * a simpler alternative to the imperative approach with `useEffect` and/or `useMemo`.
11
15
  */
@@ -54,20 +58,13 @@ export declare class ComponentInstance<TProps extends o = {}, TState extends TSt
54
58
  */
55
59
  cleanUp: IVoidFunction;
56
60
  }
57
- type o = object;
58
- type ComponentInstanceOwnStaticKeys = Exclude<keyof typeof ComponentInstance, keyof ComponentLogic.ClassType>;
59
- type ComponentInstanceOwnStatics = {
60
- [Key in ComponentInstanceOwnStaticKeys]: (typeof ComponentInstance)[Key];
61
- };
62
- export interface IComponentInstance<Instance extends ComponentInstance<o, o, THooksBase>> extends ComponentLogic.Instance<Instance>, Omit<ComponentInstance<Instance['props'], ExtractCleanStateData<Instance['state']>, Instance['_thooks']>, 'useHooks'> {
63
- }
64
- export interface IComponentInstanceClass<Instance extends ComponentInstance<o, o, THooksBase> = ComponentInstance> extends Constructor<IComponentInstance<Instance>>, ComponentInstanceOwnStatics, ComponentLogic.ClassType<Instance> {
65
- }
66
- type UseInstance = {
67
- <Class extends IComponentInstanceClass<ComponentInstance<o, o, THooksBase>>>(Methods: Class): InstanceType<Class>;
68
- <Class extends IComponentInstanceClass<ComponentInstance<o, o, THooksBase>>>(Methods: Class, props: InstanceType<Class>['props']): InstanceType<Class>;
69
- };
70
61
  export declare const useInstance: UseInstance;
62
+ export declare namespace ComponentInstance {
63
+ class Class<TProps extends object = {}, TState extends TStateData = WeakEmptyObject, THooks extends THooksBase = void> extends ComponentInstance<TProps, TState, THooks> {
64
+ }
65
+ type Instance<Instance extends CIBaseType = Class> = IComponentInstance<Instance>;
66
+ type ClassType<Instance extends CIBaseType = Class> = IComponentInstanceClass<Instance>;
67
+ }
71
68
  export {};
72
69
  /** /testing: {
73
70
  class A extends ComponentInstance<{}, {}, object> {
@@ -17,38 +17,13 @@ var __extends = (this && this.__extends) || (function () {
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.useInstance = exports.ComponentInstance = exports.noOp = void 0;
19
19
  var react_1 = require("react");
20
- var state_1 = require("../base/state");
21
- var logic_1 = require("./logic");
22
- var useMountCallbacks = function (instance) {
23
- var _a;
24
- var mounted = (0, state_1.useMountState)();
25
- if (!mounted)
26
- (_a = instance.beforeMount) === null || _a === void 0 ? void 0 : _a.call(instance);
27
- (0, react_1.useEffect)(function () {
28
- var _a;
29
- var mountHandlerCleanUp = (_a = instance.onMount) === null || _a === void 0 ? void 0 : _a.call(instance);
30
- return function () {
31
- var doCleanUp = function (runMountCleaners) {
32
- var _a;
33
- runMountCleaners === null || runMountCleaners === void 0 ? void 0 : runMountCleaners();
34
- // onDismount? willUnmount?
35
- (_a = instance.cleanUp) === null || _a === void 0 ? void 0 : _a.call(instance);
36
- };
37
- if (typeof mountHandlerCleanUp === 'function') {
38
- doCleanUp(mountHandlerCleanUp);
39
- }
40
- else {
41
- mountHandlerCleanUp === null || mountHandlerCleanUp === void 0 ? void 0 : mountHandlerCleanUp.then(doCleanUp);
42
- }
43
- };
44
- }, []);
45
- };
20
+ var logic_1 = require("../../classy/logic");
21
+ var mount_callbacks_1 = require("./mount-callbacks");
46
22
  /** An empty function. It returns (void) without performing any operations. */
47
23
  var noOp = function () { };
48
24
  exports.noOp = noOp;
49
- // @todo Use rollup. Insert globals.ts reference tag to all d.ts output files.
50
25
  /**
51
- * A superset of {@link ComponentLogic} that adds support for special lifecycle methods.
26
+ * A superset of {@link ComponentLogic} that adds support for lifecycle methods.
52
27
  * This provides a declarative API for working with your React function component's lifecycle,
53
28
  * a simpler alternative to the imperative approach with `useEffect` and/or `useMemo`.
54
29
  */
@@ -105,7 +80,6 @@ var ComponentInstance = /** @class */ (function (_super) {
105
80
  }(logic_1.ComponentLogic.Class));
106
81
  exports.ComponentInstance = ComponentInstance;
107
82
  ;
108
- ;
109
83
  /*
110
84
  * To ensure successful type checking, the second parameter must be written with spread syntax.
111
85
  * Likely because of the `exactOptionalPropertyTypes` config option turned on,
@@ -139,7 +113,7 @@ var useInstance = function () {
139
113
  '
140
114
  */
141
115
  // beforeMount, onMount, cleanUp.
142
- useMountCallbacks(instance);
116
+ (0, mount_callbacks_1.useMountCallbacks)(instance);
143
117
  // beforeRender.
144
118
  (_a = instance.beforeRender) === null || _a === void 0 ? void 0 : _a.call(instance);
145
119
  // onRender.
@@ -156,6 +130,17 @@ var useInstance = function () {
156
130
  return instance;
157
131
  };
158
132
  exports.useInstance = useInstance;
133
+ (function (ComponentInstance) {
134
+ var Class = /** @class */ (function (_super) {
135
+ __extends(Class, _super);
136
+ function Class() {
137
+ return _super !== null && _super.apply(this, arguments) || this;
138
+ }
139
+ return Class;
140
+ }(ComponentInstance));
141
+ ComponentInstance.Class = Class;
142
+ ;
143
+ })(ComponentInstance || (exports.ComponentInstance = ComponentInstance = {}));
159
144
  /** /testing: {
160
145
  class A extends ComponentInstance<{}, {}, object> {
161
146
  static getInitialState: (p?: object) => ({putan: ''});
@@ -0,0 +1,4 @@
1
+ import { ComponentInstance } from '.';
2
+ type UseMountCallbacks = <TInstance extends ComponentInstance<any, any, any>>(instance: TInstance) => void;
3
+ export declare const useMountCallbacks: UseMountCallbacks;
4
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMountCallbacks = void 0;
4
+ var react_1 = require("react");
5
+ var state_1 = require("../../base/state");
6
+ var useMountCallbacks = function (instance) {
7
+ var _a;
8
+ var mounted = (0, state_1.useMountState)();
9
+ if (!mounted)
10
+ (_a = instance.beforeMount) === null || _a === void 0 ? void 0 : _a.call(instance);
11
+ (0, react_1.useEffect)(function () {
12
+ var _a;
13
+ var mountHandlerCleanUp = (_a = instance.onMount) === null || _a === void 0 ? void 0 : _a.call(instance);
14
+ return function () {
15
+ var doCleanUp = function (runMountCleaners) {
16
+ var _a;
17
+ runMountCleaners === null || runMountCleaners === void 0 ? void 0 : runMountCleaners();
18
+ // onDismount? willUnmount?
19
+ (_a = instance.cleanUp) === null || _a === void 0 ? void 0 : _a.call(instance);
20
+ };
21
+ if (typeof mountHandlerCleanUp === 'function') {
22
+ doCleanUp(mountHandlerCleanUp);
23
+ }
24
+ else {
25
+ mountHandlerCleanUp === null || mountHandlerCleanUp === void 0 ? void 0 : mountHandlerCleanUp.then(doCleanUp);
26
+ }
27
+ };
28
+ }, []);
29
+ };
30
+ exports.useMountCallbacks = useMountCallbacks;
@@ -0,0 +1,17 @@
1
+ import type { THooksBase } from '../../../classy/logic';
2
+ import type { CIBaseType, IComponentInstance } from './instance';
3
+ import type { IComponentInstanceClass } from './static';
4
+ import { ComponentInstance } from '..';
5
+ type o = object;
6
+ type UIClassParam = IComponentInstanceClass<IComponentInstance<CIBaseType>>;
7
+ type UIProplessClassParam = IComponentInstanceClass<IComponentInstance<ComponentInstance<HardEmptyObject, o, THooksBase>>>;
8
+ export type UseInstance = {
9
+ <Class extends UIProplessClassParam>(Methods: Class & Constructor<IComponentInstance<InstanceType<Class>>>): InstanceType<Class>;
10
+ <Class extends UIClassParam>(Methods: Class & Constructor<IComponentInstance<InstanceType<Class>>>, props: InstanceType<Class>['props']): InstanceType<Class>;
11
+ };
12
+ export type UIParams = [
13
+ Class: IComponentInstanceClass<IComponentInstance<CIBaseType>>,
14
+ props?: object
15
+ ];
16
+ export type UIReturn = CIBaseType;
17
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import type { InstanceOverrides as CLInstanceOverrides } from '../../../classy/logic/types/instance';
2
+ import type { ExtractCleanStateData } from '../../../base';
3
+ import type { THooksBase } from '../../../classy/logic';
4
+ import { ComponentInstance } from '../../../classy/instance';
5
+ export type CIBaseType = ComponentInstance<object, object, THooksBase>;
6
+ type CIFromSubType<SubType extends CIBaseType> = ComponentInstance<SubType['props'], ExtractCleanStateData<SubType['state']>, SubType['_thooks']>;
7
+ export interface InstanceOverrides<Instance extends CIBaseType = ComponentInstance> extends CLInstanceOverrides<Instance> {
8
+ }
9
+ type BaseInstance<Instance extends CIBaseType = ComponentInstance> = Omit<CIFromSubType<Instance>, keyof InstanceOverrides>;
10
+ export interface IComponentInstance<Instance extends CIBaseType = ComponentInstance> extends BaseInstance<Instance>, InstanceOverrides<Instance> {
11
+ }
12
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ import type { StaticOverrides as CLStaticOverrides } from '../../../classy/logic/types/static';
2
+ import type { CIBaseType } from './instance';
3
+ import { ComponentInstance } from '../../../classy/instance';
4
+ /** */
5
+ export interface StaticOverrides<Instance extends CIBaseType = ComponentInstance> extends CLStaticOverrides<Instance> {
6
+ }
7
+ type BaseStatics = Omit<typeof ComponentInstance, 'prototype' | keyof StaticOverrides>;
8
+ export interface IComponentInstanceClass<Instance extends CIBaseType = ComponentInstance> extends BaseStatics, StaticOverrides<Instance> {
9
+ }
10
+ export {};
11
+ /** */
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /** */
4
+ // type ComponentInstanceOwnStaticKeys = Exclude<
5
+ // keyof typeof ComponentInstance,
6
+ // keyof ComponentLogic.ClassType
7
+ // >;
8
+ // type ComponentInstanceOwnStatics = {
9
+ // [Key in ComponentInstanceOwnStaticKeys]: (typeof ComponentInstance)[Key];
10
+ // }
11
+ // export interface IComponentInstanceClass<
12
+ // Instance extends ComponentInstance<o, o, THooksBase> = ComponentInstance,
13
+ // > extends
14
+ // Constructor<IComponentInstance<Instance>>,
15
+ // ComponentInstanceOwnStatics,
16
+ // ComponentLogic.ClassType<Instance>
17
+ // {};
@@ -1,7 +1,7 @@
1
1
  import type { TCleanState, TStateData } from '../../base/state';
2
- import type { IComponentLogicClass } from './static-types';
3
- import type { CLBaseType, IComponentLogic } from './instance-types';
4
- import type { UseLogic } from './hook-types';
2
+ import type { IComponentLogicClass } from './types/static';
3
+ import type { CLBaseType, IComponentLogic } from './types/instance';
4
+ import type { UseLogic } from './types/hook';
5
5
  export type HardEmpty = HardEmptyObject;
6
6
  export type WeakEmpty = WeakEmptyObject;
7
7
  export type THooksBase = object | void;
@@ -1,6 +1,6 @@
1
- import type { ComponentLogic, THooksBase } from '.';
2
- import type { CLBaseType, IComponentLogic } from './instance-types';
3
- import type { IComponentLogicClass } from './static-types';
1
+ import type { ComponentLogic, THooksBase } from '..';
2
+ import type { CLBaseType, IComponentLogic } from './instance';
3
+ import type { IComponentLogicClass } from './static';
4
4
  /*************************************
5
5
  * # Utils *
6
6
  **************************************/
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
- import type { ExtractCleanStateData } from '../../base';
2
- import type { ComponentLogic, THooksBase } from '.';
1
+ import type { ExtractCleanStateData } from '../../../base';
2
+ import type { ComponentLogic, THooksBase } from '../../../classy/logic';
3
3
  /*************************************
4
4
  * # Utils *
5
5
  **************************************/
@@ -10,7 +10,7 @@ type CLFromSubType<SubType extends CLBaseType> = ComponentLogic<SubType['props']
10
10
  * # Instance Type *
11
11
  **************************************/
12
12
  /** */
13
- interface InstanceOverrides<Instance extends CLBaseType = ComponentLogic> {
13
+ export interface InstanceOverrides<Instance extends CLBaseType = ComponentLogic> {
14
14
  useHooks: Instance['_thooks'] extends void ? () => (void | HardEmptyObject) : () => Instance['_thooks'];
15
15
  }
16
16
  type BaseInstance<Instance extends CLBaseType = ComponentLogic> = Omit<CLFromSubType<Instance>, keyof InstanceOverrides>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,6 @@
1
- import type { ExtractCleanStateData } from '../../base';
2
- import type { ComponentLogic, THooksBase } from '.';
3
- import type { CLBaseType } from './instance-types';
1
+ import type { ExtractCleanStateData } from '../../../base';
2
+ import type { ComponentLogic, THooksBase } from '../../../classy/logic';
3
+ import type { CLBaseType } from './instance';
4
4
  /*************************************
5
5
  * # Utils *
6
6
  **************************************/
@@ -8,7 +8,7 @@ type o = object;
8
8
  /*************************************
9
9
  * # Class Static Side *
10
10
  **************************************/
11
- interface StaticOverrides<Instance extends CLBaseType = ComponentLogic> extends Constructor<Instance> {
11
+ export interface StaticOverrides<Instance extends CLBaseType = ComponentLogic> extends Constructor<Instance> {
12
12
  getInitialState: (props?: Instance['props']) => ExtractCleanStateData<Instance['state']>;
13
13
  }
14
14
  type BaseStatics = Omit<typeof ComponentLogic, 'prototype' | keyof StaticOverrides>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -29,7 +29,7 @@ declare global {
29
29
  * Pass a type argument to set whether `async` and/or `sync` functions are allowed.
30
30
  */
31
31
  interface IVoidFunction<AsyncType extends 'async' | 'sync' | 'both' = 'both'> {
32
- (): AsyncType extends 'async' ? Promise<void> : AsyncType extends 'sync' ? void : Promise<void> | void;
32
+ (): AsyncType extends 'async' ? Promise<void> : AsyncType extends 'sync' ? void : void | Promise<void>;
33
33
  }
34
34
  type AnyFunction = (...args: any) => any;
35
35
  type FunctionType = AnyFunction;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleanweb/react",
3
- "version": "1.1.1-beta.24",
3
+ "version": "1.1.1-beta.27",
4
4
  "description": "A suite of helpers for writing cleaner React function components.",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -22,10 +22,12 @@
22
22
  "./state": "./build/base/state.js",
23
23
  "./state/merged": "./build/base/merged-state.js",
24
24
  "./methods": "./build/base/methods.js",
25
- "./logic": "./build/classy/logic.js",
26
- "./instance": "./build/classy/instance.js",
27
- "./class-component": "./build/classy/class.js",
28
- "./full-class": "./build/classy/class.js"
25
+ "./logic": "./build/classy/logic/index.js",
26
+ "./logic/*": "./build/classy/logic/*.js",
27
+ "./instance": "./build/classy/instance/index.js",
28
+ "./instance/*": "./build/classy/instance/*.js",
29
+ "./class": "./build/classy/class/index.js",
30
+ "./class/*": "./build/classy/class/*.js"
29
31
  },
30
32
  "scripts": {
31
33
  "prebuild": "rimraf ./build",