@cleanweb/oore 2.0.0-alpha.16 → 2.0.0-alpha.19
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.
- package/build/_cjs/base/index.d.ts +3 -0
- package/build/_cjs/base/index.js +19 -0
- package/build/_cjs/base/merged-state.d.ts +20 -0
- package/build/_cjs/base/merged-state.js +61 -0
- package/build/_cjs/base/methods.d.ts +58 -0
- package/build/_cjs/base/methods.js +95 -0
- package/build/_cjs/base/state/class-types.d.ts +20 -0
- package/build/_cjs/base/state/class-types.js +2 -0
- package/build/_cjs/base/state/class.d.ts +69 -0
- package/build/_cjs/base/state/class.js +129 -0
- package/build/_cjs/base/state/hook-types.d.ts +32 -0
- package/build/_cjs/base/state/hook-types.js +2 -0
- package/build/_cjs/base/state/hooks.d.ts +12 -0
- package/build/_cjs/base/state/hooks.js +41 -0
- package/build/_cjs/base/state/index.d.ts +8 -0
- package/build/_cjs/base/state/index.js +34 -0
- package/build/_cjs/classy/class/index.d.ts +128 -0
- package/build/_cjs/classy/class/index.js +174 -0
- package/build/_cjs/classy/class/types/extractor.d.ts +5 -0
- package/build/_cjs/classy/class/types/extractor.js +2 -0
- package/build/_cjs/classy/class/utils/function-name.d.ts +2 -0
- package/build/_cjs/classy/class/utils/function-name.js +17 -0
- package/build/_cjs/classy/index.d.ts +3 -0
- package/build/_cjs/classy/index.js +19 -0
- package/build/_cjs/classy/instance/index.d.ts +144 -0
- package/build/_cjs/classy/instance/index.js +177 -0
- package/build/_cjs/classy/instance/mount-callbacks.d.ts +5 -0
- package/build/_cjs/classy/instance/mount-callbacks.js +30 -0
- package/build/_cjs/classy/instance/types/hook.d.ts +13 -0
- package/build/_cjs/classy/instance/types/hook.js +2 -0
- package/build/_cjs/classy/logic/index.d.ts +116 -0
- package/build/_cjs/classy/logic/index.js +123 -0
- package/build/_cjs/classy/logic/types/hook.d.ts +16 -0
- package/build/_cjs/classy/logic/types/hook.js +2 -0
- package/build/_cjs/docs-src/api/base-classes.d.ts +3 -0
- package/build/_cjs/docs-src/api/base-classes.js +9 -0
- package/build/_cjs/docs-src/api/index.d.ts +13 -0
- package/build/_cjs/docs-src/api/index.js +44 -0
- package/build/_cjs/docs-src/api/references.d.ts +5 -0
- package/build/_cjs/docs-src/api/references.js +31 -0
- package/build/_cjs/helpers/errors.d.ts +10 -0
- package/build/_cjs/helpers/errors.js +21 -0
- package/build/_cjs/helpers/index.d.ts +13 -0
- package/build/_cjs/helpers/index.js +31 -0
- package/build/_cjs/helpers/mount-state.d.ts +5 -0
- package/build/_cjs/helpers/mount-state.js +25 -0
- package/build/_cjs/helpers/rerender.d.ts +24 -0
- package/build/_cjs/helpers/rerender.js +42 -0
- package/build/_cjs/helpers/type-guards.d.ts +1 -0
- package/build/_cjs/helpers/type-guards.js +8 -0
- package/build/_cjs/helpers/use-component/index.d.ts +6 -0
- package/build/_cjs/helpers/use-component/index.js +17 -0
- package/build/_cjs/helpers/use-component/types.d.ts +22 -0
- package/build/_cjs/helpers/use-component/types.js +2 -0
- package/build/_cjs/index.d.ts +3 -0
- package/build/_cjs/index.js +19 -0
- package/build/_cjs/slots/hook.d.ts +20 -0
- package/build/_cjs/slots/hook.js +143 -0
- package/build/_cjs/slots/index.d.ts +1 -0
- package/build/_cjs/slots/index.js +17 -0
- package/build/_cjs/slots/types.d.ts +131 -0
- package/build/_cjs/slots/types.js +2 -0
- package/build/base/index.js +19 -3
- package/build/base/merged-state.js +35 -54
- package/build/base/methods.js +23 -25
- package/build/base/state/class-types.js +2 -1
- package/build/base/state/class.js +49 -69
- package/build/base/state/hook-types.js +2 -1
- package/build/base/state/hooks.js +12 -12
- package/build/base/state/index.d.ts +0 -1
- package/build/base/state/index.js +31 -4
- package/build/classy/class/index.js +89 -109
- package/build/classy/class/types/extractor.js +2 -1
- package/build/classy/class/utils/function-name.js +5 -1
- package/build/classy/index.js +19 -3
- package/build/classy/instance/index.js +62 -84
- package/build/classy/instance/mount-callbacks.js +12 -8
- package/build/classy/instance/types/hook.js +2 -1
- package/build/classy/logic/index.js +27 -28
- package/build/classy/logic/types/hook.js +2 -1
- package/build/docs-src/api/base-classes.js +9 -3
- package/build/docs-src/api/index.js +39 -8
- package/build/docs-src/api/references.js +31 -5
- package/build/globals.d.ts +130 -83
- package/build/helpers/errors.js +5 -1
- package/build/helpers/index.js +23 -5
- package/build/helpers/mount-state.js +10 -6
- package/build/helpers/rerender.js +16 -12
- package/build/helpers/type-guards.js +6 -2
- package/build/helpers/use-component/index.js +9 -5
- package/build/helpers/use-component/types.js +2 -1
- package/build/index.d.ts +0 -1
- package/build/index.js +19 -3
- package/build/slots/hook.js +58 -36
- package/build/slots/index.js +17 -1
- package/build/slots/types.js +2 -1
- package/build/tsconfig.json +5 -6
- package/package.json +31 -12
- package/build/globals.js +0 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMountCallbacks = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const mount_state_1 = require("../../helpers/mount-state");
|
|
6
|
+
/** @internal */
|
|
7
|
+
const useMountCallbacks = (instance) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const isMounted = (0, mount_state_1.useMountState)();
|
|
10
|
+
if (!isMounted())
|
|
11
|
+
(_a = instance.beforeMount) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
|
+
var _a;
|
|
14
|
+
const mountHandlerCleanUp = (_a = instance.onMount) === null || _a === void 0 ? void 0 : _a.call(instance);
|
|
15
|
+
return () => {
|
|
16
|
+
const doCleanUp = (runMountCleaners) => {
|
|
17
|
+
var _a;
|
|
18
|
+
runMountCleaners === null || runMountCleaners === void 0 ? void 0 : runMountCleaners();
|
|
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,13 @@
|
|
|
1
|
+
import { ComponentInstance } from '..';
|
|
2
|
+
type UIClassParam = typeof ComponentInstance<NonNullable<any>>;
|
|
3
|
+
type UIProplessClassParam = typeof ComponentInstance<null>;
|
|
4
|
+
export type UseInstance = {
|
|
5
|
+
<Class extends UIProplessClassParam>(Methods: Class): InstanceType<Class>;
|
|
6
|
+
<Class extends UIClassParam>(Methods: Class, props: InstanceType<Class>['props']): InstanceType<Class>;
|
|
7
|
+
};
|
|
8
|
+
export type UIParams = [
|
|
9
|
+
Class: typeof ComponentInstance<any>,
|
|
10
|
+
props?: object
|
|
11
|
+
];
|
|
12
|
+
export type UIReturn = ComponentInstance<any>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { TCleanState } from '../../base/state';
|
|
2
|
+
import type { UseLogic } from './types/hook';
|
|
3
|
+
/**
|
|
4
|
+
* The base type for the `props` type argument.
|
|
5
|
+
*
|
|
6
|
+
* This is not the type of the `props` property itself.
|
|
7
|
+
* It merely defines the type constraint for the type argument
|
|
8
|
+
* passed when extending any of the logic classes.
|
|
9
|
+
*
|
|
10
|
+
* It accepts null for components that don't take any props.
|
|
11
|
+
*/
|
|
12
|
+
export type TPropsBase = NonPrimitive | null;
|
|
13
|
+
/**
|
|
14
|
+
* Base class for a class that holds methods to be used in a function component.
|
|
15
|
+
*
|
|
16
|
+
* These methods will always have access to the latest copy of
|
|
17
|
+
* the component's state and props via `this.state` and `this.props` respectively.
|
|
18
|
+
*
|
|
19
|
+
* The special {@link Class['useHooks'] | useHooks} method allows you to consume
|
|
20
|
+
* React hooks within this class.
|
|
21
|
+
*
|
|
22
|
+
* Call the {@link useLogic} hook inside your function component to instantiate the class.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam TProps - {@include ./types/tprops.md}
|
|
25
|
+
*/
|
|
26
|
+
export declare class ComponentLogic<TProps extends TPropsBase = null> {
|
|
27
|
+
/**
|
|
28
|
+
* A {@link TCleanState | `CleanState`} object.
|
|
29
|
+
* Holds all of your component's state,
|
|
30
|
+
* and methods for conveniently manipulating those values.
|
|
31
|
+
* Initialiazed with the object returned from your `getInitialState` method.
|
|
32
|
+
*/
|
|
33
|
+
readonly state: TCleanState<ReturnType<this['getInitialState']>>;
|
|
34
|
+
/** The props passed into your component at the time of rendering. */
|
|
35
|
+
readonly props: TProps extends null ? EmptyObject : TProps;
|
|
36
|
+
/**
|
|
37
|
+
* Values received from the hooks your component consumes.
|
|
38
|
+
* This holds the latest copy of the object returned by
|
|
39
|
+
* {@link useHooks}.
|
|
40
|
+
*
|
|
41
|
+
* You should not mutate this object directly.
|
|
42
|
+
* `useHooks` is called on every render and the object it returns
|
|
43
|
+
* will completely overwrite whatever the previous value of `this.hooks` was.
|
|
44
|
+
* `this.hooks` should only be updated through the object returned from `useHooks`.
|
|
45
|
+
*
|
|
46
|
+
* If you need to update a value from outside `useHooks` as well, then consider
|
|
47
|
+
* wrapping it with {@link React.useRef}, since React refs are persisted across rerenders.
|
|
48
|
+
*/
|
|
49
|
+
readonly hooks: ReturnType<this['useHooks']>;
|
|
50
|
+
/**
|
|
51
|
+
* Called before each instance of your component is mounted.
|
|
52
|
+
* It receives the initial `props` object and should return
|
|
53
|
+
* an object with the initial values for your component's state.
|
|
54
|
+
*/
|
|
55
|
+
getInitialState: (props: TProps extends null ? undefined : TProps) => object;
|
|
56
|
+
/**
|
|
57
|
+
* Call React hooks from here. If your component needs
|
|
58
|
+
* access to values return from the hooks you call,
|
|
59
|
+
* expose those values by returning an object with said values.
|
|
60
|
+
*
|
|
61
|
+
* The returned object will be accessible as {@link hooks | `this.hooks`} within
|
|
62
|
+
* your component class.
|
|
63
|
+
*/
|
|
64
|
+
useHooks: () => object | void;
|
|
65
|
+
/**
|
|
66
|
+
* Persist class members during HMR. {@include ./hrm-preserve-keys.md}
|
|
67
|
+
* @privateRemarks
|
|
68
|
+
* @see {@link https://cleanjsweb.github.io/neat-react/classes/API.BaseClasses.ComponentLogic.html#_hmrpreservekeys | Full details}
|
|
69
|
+
*/
|
|
70
|
+
_hmrPreserveKeys: Array<keyof this | (string & {})>;
|
|
71
|
+
/**
|
|
72
|
+
* Run custom logic after HMR update. {@include ./on-hrm-update.md}
|
|
73
|
+
* @privateRemarks
|
|
74
|
+
* @see {@link https://cleanjsweb.github.io/neat-react/classes/API.BaseClasses.ComponentLogic.html#_onhmrupdate | Full details}
|
|
75
|
+
*/
|
|
76
|
+
_onHmrUpdate?: <TInstance extends this>(oldInstance: TInstance) => void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Returns an instance of the provided class, which holds methods for your component and
|
|
80
|
+
* encapsulates hook calls with the special {@link ComponentLogic.useHooks | `useHooks`} method.
|
|
81
|
+
*
|
|
82
|
+
* The class argument must be a subclass of {@link ComponentLogic}.
|
|
83
|
+
*
|
|
84
|
+
* @see https://cleanjsweb.github.io/neat-react/functions/API.useLogic.html
|
|
85
|
+
*/
|
|
86
|
+
export declare const useLogic: UseLogic;
|
|
87
|
+
/** /
|
|
88
|
+
testing: {
|
|
89
|
+
const a: object = {b: ''};
|
|
90
|
+
|
|
91
|
+
type t = keyof typeof a;
|
|
92
|
+
|
|
93
|
+
class MyComponentLogic extends ComponentLogic<{}> {
|
|
94
|
+
getInitialState = () => ({b: 7});
|
|
95
|
+
b = () => 8 + this.state.b;
|
|
96
|
+
|
|
97
|
+
useHooks = () => ({a: 'undefined'});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
type tt = keyof {};
|
|
101
|
+
|
|
102
|
+
const self = useLogic(MyComponentLogic);
|
|
103
|
+
self.hooks;
|
|
104
|
+
self.useHooks();
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
const A = class C extends ComponentLogic {
|
|
108
|
+
getInitialState = () => ({a: 'l'});
|
|
109
|
+
a = () => this.state.a = '';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// const oa = {['a' as unknown as symbol]: 'boo'};
|
|
113
|
+
const oa = {['a']: 'boo'};
|
|
114
|
+
useLogic(A, oa);
|
|
115
|
+
}
|
|
116
|
+
/**/
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLogic = exports.ComponentLogic = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const state_1 = require("../../base/state");
|
|
6
|
+
/**
|
|
7
|
+
* Base class for a class that holds methods to be used in a function component.
|
|
8
|
+
*
|
|
9
|
+
* These methods will always have access to the latest copy of
|
|
10
|
+
* the component's state and props via `this.state` and `this.props` respectively.
|
|
11
|
+
*
|
|
12
|
+
* The special {@link Class['useHooks'] | useHooks} method allows you to consume
|
|
13
|
+
* React hooks within this class.
|
|
14
|
+
*
|
|
15
|
+
* Call the {@link useLogic} hook inside your function component to instantiate the class.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam TProps - {@include ./types/tprops.md}
|
|
18
|
+
*/
|
|
19
|
+
class ComponentLogic {
|
|
20
|
+
constructor() {
|
|
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
|
+
*/
|
|
26
|
+
this.getInitialState = (props) => ({});
|
|
27
|
+
/**
|
|
28
|
+
* Call React hooks from here. If your component needs
|
|
29
|
+
* access to values return from the hooks you call,
|
|
30
|
+
* expose those values by returning an object with said values.
|
|
31
|
+
*
|
|
32
|
+
* The returned object will be accessible as {@link hooks | `this.hooks`} within
|
|
33
|
+
* your component class.
|
|
34
|
+
*/
|
|
35
|
+
this.useHooks = () => { };
|
|
36
|
+
/**
|
|
37
|
+
* Persist class members during HMR. {@include ./hrm-preserve-keys.md}
|
|
38
|
+
* @privateRemarks
|
|
39
|
+
* @see {@link https://cleanjsweb.github.io/neat-react/classes/API.BaseClasses.ComponentLogic.html#_hmrpreservekeys | Full details}
|
|
40
|
+
*/
|
|
41
|
+
this._hmrPreserveKeys = [];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.ComponentLogic = ComponentLogic;
|
|
45
|
+
;
|
|
46
|
+
/**
|
|
47
|
+
* Returns an instance of the provided class, which holds methods for your component and
|
|
48
|
+
* encapsulates hook calls with the special {@link ComponentLogic.useHooks | `useHooks`} method.
|
|
49
|
+
*
|
|
50
|
+
* The class argument must be a subclass of {@link ComponentLogic}.
|
|
51
|
+
*
|
|
52
|
+
* @see https://cleanjsweb.github.io/neat-react/functions/API.useLogic.html
|
|
53
|
+
*/
|
|
54
|
+
const useLogic = (...args) => {
|
|
55
|
+
var _a;
|
|
56
|
+
const [Logic, props = {}] = args;
|
|
57
|
+
// In production, we only use the latestInstance the first time, and it's ignored every other time.
|
|
58
|
+
// This means changing the class at runtime will have no effect in production.
|
|
59
|
+
// latestInstance is only extracted into a separate variable for use in dev mode during HMR.
|
|
60
|
+
const latestInstance = (0, react_1.useMemo)(() => new Logic(), [Logic]);
|
|
61
|
+
// const latestInstance = useMemo(() => new Logic(), []);
|
|
62
|
+
const instanceRef = (0, react_1.useRef)(latestInstance);
|
|
63
|
+
const refreshState = () => {
|
|
64
|
+
var _a;
|
|
65
|
+
// @ts-expect-error
|
|
66
|
+
instanceRef.current.props = props;
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
instanceRef.current.state = (0, state_1.useCleanState)(instanceRef.current.getInitialState, props);
|
|
69
|
+
// @ts-expect-error
|
|
70
|
+
instanceRef.current.hooks = (_a = instanceRef.current.useHooks()) !== null && _a !== void 0 ? _a : {};
|
|
71
|
+
};
|
|
72
|
+
if (process.env.NODE_ENV === 'development' && instanceRef.current !== latestInstance) {
|
|
73
|
+
const oldInstance = instanceRef.current;
|
|
74
|
+
latestInstance._hmrPreserveKeys.forEach((_key) => {
|
|
75
|
+
const key = _key;
|
|
76
|
+
// @ts-expect-error We're assigning to readonly properties. Also, Typescript doesn't know that the type of the left and right side will always match, due to the dynamic access.
|
|
77
|
+
latestInstance[key] = oldInstance[key];
|
|
78
|
+
});
|
|
79
|
+
Reflect.ownKeys(oldInstance).forEach((_key) => {
|
|
80
|
+
const key = _key;
|
|
81
|
+
delete oldInstance[key];
|
|
82
|
+
});
|
|
83
|
+
Object.setPrototypeOf(oldInstance, latestInstance);
|
|
84
|
+
instanceRef.current = latestInstance;
|
|
85
|
+
refreshState();
|
|
86
|
+
(_a = latestInstance._onHmrUpdate) === null || _a === void 0 ? void 0 : _a.call(latestInstance, oldInstance);
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
refreshState();
|
|
90
|
+
return instanceRef.current;
|
|
91
|
+
;
|
|
92
|
+
};
|
|
93
|
+
exports.useLogic = useLogic;
|
|
94
|
+
/** /
|
|
95
|
+
testing: {
|
|
96
|
+
const a: object = {b: ''};
|
|
97
|
+
|
|
98
|
+
type t = keyof typeof a;
|
|
99
|
+
|
|
100
|
+
class MyComponentLogic extends ComponentLogic<{}> {
|
|
101
|
+
getInitialState = () => ({b: 7});
|
|
102
|
+
b = () => 8 + this.state.b;
|
|
103
|
+
|
|
104
|
+
useHooks = () => ({a: 'undefined'});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
type tt = keyof {};
|
|
108
|
+
|
|
109
|
+
const self = useLogic(MyComponentLogic);
|
|
110
|
+
self.hooks;
|
|
111
|
+
self.useHooks();
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
const A = class C extends ComponentLogic {
|
|
115
|
+
getInitialState = () => ({a: 'l'});
|
|
116
|
+
a = () => this.state.a = '';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// const oa = {['a' as unknown as symbol]: 'boo'};
|
|
120
|
+
const oa = {['a']: 'boo'};
|
|
121
|
+
useLogic(A, oa);
|
|
122
|
+
}
|
|
123
|
+
/**/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ComponentLogic } from '..';
|
|
2
|
+
/*************************************
|
|
3
|
+
* # Hooks *
|
|
4
|
+
**************************************/
|
|
5
|
+
type ULClassParam = typeof ComponentLogic<NonNullable<any>>;
|
|
6
|
+
type ULProplessClassParam = typeof ComponentLogic<null>;
|
|
7
|
+
export type UseLogic = {
|
|
8
|
+
<Class extends ULProplessClassParam>(Methods: Class): InstanceType<Class>;
|
|
9
|
+
<Class extends ULClassParam>(Methods: Class, props: InstanceType<Class>['props']): InstanceType<Class>;
|
|
10
|
+
};
|
|
11
|
+
export type ULParams = [
|
|
12
|
+
Class: typeof ComponentLogic<any>,
|
|
13
|
+
props?: object
|
|
14
|
+
];
|
|
15
|
+
export type ULReturn = ComponentLogic<any>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentInstance = exports.ComponentLogic = exports.ComponentMethods = void 0;
|
|
4
|
+
var methods_1 = require("../../base/methods");
|
|
5
|
+
Object.defineProperty(exports, "ComponentMethods", { enumerable: true, get: function () { return methods_1.ComponentMethods; } });
|
|
6
|
+
var logic_1 = require("../../classy/logic");
|
|
7
|
+
Object.defineProperty(exports, "ComponentLogic", { enumerable: true, get: function () { return logic_1.ComponentLogic; } });
|
|
8
|
+
var instance_1 = require("../../classy/instance");
|
|
9
|
+
Object.defineProperty(exports, "ComponentInstance", { enumerable: true, get: function () { return instance_1.ComponentInstance; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API Reference
|
|
3
|
+
* @module API
|
|
4
|
+
*/
|
|
5
|
+
export { useCleanState } from '../../base/state';
|
|
6
|
+
export { useMethods } from '../../base/methods';
|
|
7
|
+
export { useLogic } from '../../classy/logic';
|
|
8
|
+
export { useInstance } from '../../classy/instance';
|
|
9
|
+
export { ClassComponent } from '../../classy/class';
|
|
10
|
+
/** @namespace */
|
|
11
|
+
export * as BaseClasses from './base-classes';
|
|
12
|
+
export * as Helpers from '../../helpers';
|
|
13
|
+
export * as References from './references';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* API Reference
|
|
4
|
+
* @module API
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
23
|
+
if (mod && mod.__esModule) return mod;
|
|
24
|
+
var result = {};
|
|
25
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
26
|
+
__setModuleDefault(result, mod);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.References = exports.Helpers = exports.BaseClasses = exports.ClassComponent = exports.useInstance = exports.useLogic = exports.useMethods = exports.useCleanState = void 0;
|
|
31
|
+
var state_1 = require("../../base/state");
|
|
32
|
+
Object.defineProperty(exports, "useCleanState", { enumerable: true, get: function () { return state_1.useCleanState; } });
|
|
33
|
+
var methods_1 = require("../../base/methods");
|
|
34
|
+
Object.defineProperty(exports, "useMethods", { enumerable: true, get: function () { return methods_1.useMethods; } });
|
|
35
|
+
var logic_1 = require("../../classy/logic");
|
|
36
|
+
Object.defineProperty(exports, "useLogic", { enumerable: true, get: function () { return logic_1.useLogic; } });
|
|
37
|
+
var instance_1 = require("../../classy/instance");
|
|
38
|
+
Object.defineProperty(exports, "useInstance", { enumerable: true, get: function () { return instance_1.useInstance; } });
|
|
39
|
+
var class_1 = require("../../classy/class");
|
|
40
|
+
Object.defineProperty(exports, "ClassComponent", { enumerable: true, get: function () { return class_1.ClassComponent; } });
|
|
41
|
+
/** @namespace */
|
|
42
|
+
exports.BaseClasses = __importStar(require("./base-classes"));
|
|
43
|
+
exports.Helpers = __importStar(require("../../helpers"));
|
|
44
|
+
exports.References = __importStar(require("./references"));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export * as $CleanState from '../../base/state';
|
|
2
|
+
export * as $ComponentMethods from '../../base/methods';
|
|
3
|
+
export * as ComponentLogic from '../../classy/logic';
|
|
4
|
+
export * as ComponentInstance from '../../classy/instance';
|
|
5
|
+
export * as ClassComponent from '../../classy/class';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ClassComponent = exports.ComponentInstance = exports.ComponentLogic = exports.$ComponentMethods = exports.$CleanState = void 0;
|
|
27
|
+
exports.$CleanState = __importStar(require("../../base/state"));
|
|
28
|
+
exports.$ComponentMethods = __importStar(require("../../base/methods"));
|
|
29
|
+
exports.ComponentLogic = __importStar(require("../../classy/logic"));
|
|
30
|
+
exports.ComponentInstance = __importStar(require("../../classy/instance"));
|
|
31
|
+
exports.ClassComponent = __importStar(require("../../classy/class"));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throw an error with the provided message
|
|
3
|
+
* only when `NODE_ENV` is *not* 'production'.
|
|
4
|
+
*
|
|
5
|
+
* In production, this falls back to just a console warning.
|
|
6
|
+
*
|
|
7
|
+
* Useful for enforcing certain conditions in development
|
|
8
|
+
* while failing more gracefully in production.
|
|
9
|
+
*/
|
|
10
|
+
export declare const throwDevError: (message: string) => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throwDevError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Throw an error with the provided message
|
|
6
|
+
* only when `NODE_ENV` is *not* 'production'.
|
|
7
|
+
*
|
|
8
|
+
* In production, this falls back to just a console warning.
|
|
9
|
+
*
|
|
10
|
+
* Useful for enforcing certain conditions in development
|
|
11
|
+
* while failing more gracefully in production.
|
|
12
|
+
*/
|
|
13
|
+
const throwDevError = (message) => {
|
|
14
|
+
if (process.env.NODE_ENV === 'production') {
|
|
15
|
+
console.warn(message);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
throw new Error(message);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.throwDevError = throwDevError;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <!-- @ mergeModuleWith API -->
|
|
3
|
+
* @module Helpers
|
|
4
|
+
*/
|
|
5
|
+
export * from './mount-state';
|
|
6
|
+
export * from './rerender';
|
|
7
|
+
export * from './use-component';
|
|
8
|
+
export * from './type-guards';
|
|
9
|
+
/**
|
|
10
|
+
* An empty function.
|
|
11
|
+
* It returns (void) without performing any operations.
|
|
12
|
+
*/
|
|
13
|
+
export declare const noOp: () => void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* <!-- @ mergeModuleWith API -->
|
|
4
|
+
* @module Helpers
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.noOp = void 0;
|
|
22
|
+
__exportStar(require("./mount-state"), exports);
|
|
23
|
+
__exportStar(require("./rerender"), exports);
|
|
24
|
+
__exportStar(require("./use-component"), exports);
|
|
25
|
+
__exportStar(require("./type-guards"), exports);
|
|
26
|
+
/**
|
|
27
|
+
* An empty function.
|
|
28
|
+
* It returns (void) without performing any operations.
|
|
29
|
+
*/
|
|
30
|
+
const noOp = () => { };
|
|
31
|
+
exports.noOp = noOp;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useMountState = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* Returns a value that is false before the component has been mounted,
|
|
7
|
+
* then true during all subsequent rerenders.
|
|
8
|
+
*/
|
|
9
|
+
const useMountState = () => {
|
|
10
|
+
/**
|
|
11
|
+
* This must not be a state value. It should not be the cause of a rerender.
|
|
12
|
+
* It merely provides information about the render count,
|
|
13
|
+
* without influencing that count itself.
|
|
14
|
+
* So `mounted` should never be created with `useState`.
|
|
15
|
+
*/
|
|
16
|
+
const mounted = (0, react_1.useRef)(false);
|
|
17
|
+
(0, react_1.useEffect)(() => {
|
|
18
|
+
mounted.current = true;
|
|
19
|
+
return () => {
|
|
20
|
+
mounted.current = false;
|
|
21
|
+
};
|
|
22
|
+
}, []);
|
|
23
|
+
return () => mounted.current;
|
|
24
|
+
};
|
|
25
|
+
exports.useMountState = useMountState;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
interface ICountRef {
|
|
2
|
+
current: number;
|
|
3
|
+
}
|
|
4
|
+
interface IRefresherReturn {
|
|
5
|
+
/** The last render count just before the rerender was triggered. */
|
|
6
|
+
previousCount: number;
|
|
7
|
+
/** A {@link useRef | RefObject} whose `current` property always has the latest render count. */
|
|
8
|
+
latestCountRef: ICountRef;
|
|
9
|
+
}
|
|
10
|
+
interface IRefresher {
|
|
11
|
+
(): Promise<IRefresherReturn>;
|
|
12
|
+
}
|
|
13
|
+
interface IUseRender {
|
|
14
|
+
(): IRefresher & {
|
|
15
|
+
/** The number of times this instance of the component has been (re)rendered. */
|
|
16
|
+
currentCount: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns a function that can be called to manually trigger
|
|
21
|
+
* a rerender of your component.
|
|
22
|
+
*/
|
|
23
|
+
export declare const useRerender: IUseRender;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRerender = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const mount_state_1 = require("../helpers/mount-state");
|
|
6
|
+
;
|
|
7
|
+
/**
|
|
8
|
+
* Returns a function that can be called to manually trigger
|
|
9
|
+
* a rerender of your component.
|
|
10
|
+
*/
|
|
11
|
+
const useRerender = () => {
|
|
12
|
+
const isMounted = (0, mount_state_1.useMountState)();
|
|
13
|
+
const renderCount = (0, react_1.useRef)(0);
|
|
14
|
+
const [, forceRerender] = (0, react_1.useState)(renderCount.current);
|
|
15
|
+
renderCount.current++;
|
|
16
|
+
const rerender = (0, react_1.useCallback)(() => {
|
|
17
|
+
let resolve;
|
|
18
|
+
const promise = new Promise((_r) => resolve = _r);
|
|
19
|
+
const execute = () => {
|
|
20
|
+
forceRerender(renderCount.current);
|
|
21
|
+
resolve({
|
|
22
|
+
previousCount: renderCount.current,
|
|
23
|
+
latestCountRef: renderCount,
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
if (isMounted())
|
|
27
|
+
execute();
|
|
28
|
+
else {
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
if (isMounted())
|
|
31
|
+
execute();
|
|
32
|
+
else
|
|
33
|
+
console.log('Cannot rerender an unmounted component.');
|
|
34
|
+
}, 1000);
|
|
35
|
+
}
|
|
36
|
+
return promise;
|
|
37
|
+
}, [forceRerender, renderCount]);
|
|
38
|
+
const refresher = () => rerender();
|
|
39
|
+
refresher.currentCount = renderCount.current;
|
|
40
|
+
return refresher;
|
|
41
|
+
};
|
|
42
|
+
exports.useRerender = useRerender;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const canIndex: <T extends object>(key: keyof any, targetObject: T) => key is keyof T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canIndex = void 0;
|
|
4
|
+
const canIndex = (key, targetObject) => {
|
|
5
|
+
const test = typeof key === 'number' ? `${key}` : key;
|
|
6
|
+
return Reflect.ownKeys(targetObject).includes(test);
|
|
7
|
+
};
|
|
8
|
+
exports.canIndex = canIndex;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Use = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* A component you can use to consume React hooks
|
|
7
|
+
* in a {@link Component | React.Component} class.
|
|
8
|
+
*/
|
|
9
|
+
const Use = (params) => {
|
|
10
|
+
const { hook: useGenericHook, argumentsList, onUpdate } = params;
|
|
11
|
+
const output = useGenericHook(...argumentsList);
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
|
+
onUpdate(output);
|
|
14
|
+
}, [output]);
|
|
15
|
+
return null;
|
|
16
|
+
};
|
|
17
|
+
exports.Use = Use;
|