@cleanweb/oore 2.0.0-alpha.34 → 2.0.0-alpha.35
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/base/index.d.ts +3 -3
- package/build/base/index.js +19 -3
- package/build/base/merged-state.d.ts +1 -0
- package/build/base/merged-state.js +58 -30
- package/build/base/methods.d.ts +6 -5
- package/build/base/methods.js +28 -19
- package/build/base/state/class-types.d.ts +2 -2
- package/build/base/state/class-types.js +2 -1
- package/build/base/state/class.d.ts +1 -1
- package/build/base/state/class.js +72 -45
- package/build/base/state/hook-types.d.ts +1 -1
- package/build/base/state/hook-types.js +2 -1
- package/build/base/state/hooks.d.ts +1 -1
- package/build/base/state/hooks.js +16 -8
- package/build/base/state/index.d.ts +6 -5
- package/build/base/state/index.js +32 -3
- package/build/classy/class/index.d.ts +5 -18
- package/build/classy/class/index.js +87 -98
- package/build/classy/class/types/extractor.d.ts +1 -1
- package/build/classy/class/types/extractor.js +2 -1
- package/build/classy/class/utils/function-name.js +5 -1
- package/build/classy/index.d.ts +3 -3
- package/build/classy/index.js +19 -3
- package/build/classy/instance/index.d.ts +4 -4
- package/build/classy/instance/index.js +88 -58
- package/build/classy/instance/mount-callbacks.d.ts +1 -1
- package/build/classy/instance/mount-callbacks.js +12 -8
- package/build/classy/instance/types/hook.d.ts +1 -1
- package/build/classy/instance/types/hook.js +2 -1
- package/build/classy/logic/index.d.ts +2 -2
- package/build/classy/logic/index.js +32 -22
- package/build/classy/logic/types/hook.d.ts +1 -1
- package/build/classy/logic/types/hook.js +2 -1
- package/build/docs-src/api/base-classes.d.ts +3 -3
- package/build/docs-src/api/base-classes.js +9 -3
- package/build/docs-src/api/index.d.ts +8 -8
- package/build/docs-src/api/index.js +39 -8
- package/build/docs-src/api/references.d.ts +5 -5
- package/build/docs-src/api/references.js +31 -5
- package/build/globals.d.ts +83 -130
- package/build/globals.js +4 -0
- package/build/helpers/errors.js +5 -1
- package/build/helpers/index.d.ts +4 -7
- package/build/helpers/index.js +23 -8
- 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.d.ts +1 -1
- package/build/helpers/use-component/index.js +9 -5
- package/build/helpers/use-component/types.js +2 -1
- package/build/index.d.ts +4 -3
- package/build/index.js +19 -3
- package/build/slots/hook.d.ts +2 -2
- package/build/slots/hook.js +78 -44
- package/build/slots/index.d.ts +1 -1
- package/build/slots/index.js +17 -1
- package/build/slots/types.d.ts +14 -11
- package/build/slots/types.js +2 -1
- package/build/tsconfig.json +6 -9
- package/package.json +11 -31
- package/build/_cjs/base/index.d.ts +0 -3
- package/build/_cjs/base/index.js +0 -19
- package/build/_cjs/base/merged-state.d.ts +0 -19
- package/build/_cjs/base/merged-state.js +0 -60
- package/build/_cjs/base/methods.d.ts +0 -58
- package/build/_cjs/base/methods.js +0 -95
- package/build/_cjs/base/state/class-types.d.ts +0 -20
- package/build/_cjs/base/state/class-types.js +0 -2
- package/build/_cjs/base/state/class.d.ts +0 -69
- package/build/_cjs/base/state/class.js +0 -129
- package/build/_cjs/base/state/hook-types.d.ts +0 -32
- package/build/_cjs/base/state/hook-types.js +0 -2
- package/build/_cjs/base/state/hooks.d.ts +0 -12
- package/build/_cjs/base/state/hooks.js +0 -41
- package/build/_cjs/base/state/index.d.ts +0 -8
- package/build/_cjs/base/state/index.js +0 -34
- package/build/_cjs/classy/class/index.d.ts +0 -128
- package/build/_cjs/classy/class/index.js +0 -176
- package/build/_cjs/classy/class/types/extractor.d.ts +0 -5
- package/build/_cjs/classy/class/types/extractor.js +0 -2
- package/build/_cjs/classy/class/utils/function-name.d.ts +0 -2
- package/build/_cjs/classy/class/utils/function-name.js +0 -17
- package/build/_cjs/classy/index.d.ts +0 -3
- package/build/_cjs/classy/index.js +0 -19
- package/build/_cjs/classy/instance/index.d.ts +0 -144
- package/build/_cjs/classy/instance/index.js +0 -177
- package/build/_cjs/classy/instance/mount-callbacks.d.ts +0 -5
- package/build/_cjs/classy/instance/mount-callbacks.js +0 -30
- package/build/_cjs/classy/instance/types/hook.d.ts +0 -13
- package/build/_cjs/classy/instance/types/hook.js +0 -2
- package/build/_cjs/classy/logic/index.d.ts +0 -116
- package/build/_cjs/classy/logic/index.js +0 -123
- package/build/_cjs/classy/logic/types/hook.d.ts +0 -16
- package/build/_cjs/classy/logic/types/hook.js +0 -2
- package/build/_cjs/docs-src/api/base-classes.d.ts +0 -3
- package/build/_cjs/docs-src/api/base-classes.js +0 -9
- package/build/_cjs/docs-src/api/index.d.ts +0 -13
- package/build/_cjs/docs-src/api/index.js +0 -44
- package/build/_cjs/docs-src/api/references.d.ts +0 -5
- package/build/_cjs/docs-src/api/references.js +0 -31
- package/build/_cjs/helpers/debounce/index.d.ts +0 -55
- package/build/_cjs/helpers/debounce/index.js +0 -111
- package/build/_cjs/helpers/debounce/react-state.d.ts +0 -14
- package/build/_cjs/helpers/debounce/react-state.js +0 -32
- package/build/_cjs/helpers/errors.d.ts +0 -10
- package/build/_cjs/helpers/errors.js +0 -21
- package/build/_cjs/helpers/index.d.ts +0 -16
- package/build/_cjs/helpers/index.js +0 -34
- package/build/_cjs/helpers/mount-state.d.ts +0 -5
- package/build/_cjs/helpers/mount-state.js +0 -25
- package/build/_cjs/helpers/object-gate.d.ts +0 -74
- package/build/_cjs/helpers/object-gate.js +0 -67
- package/build/_cjs/helpers/rerender.d.ts +0 -24
- package/build/_cjs/helpers/rerender.js +0 -42
- package/build/_cjs/helpers/type-guards.d.ts +0 -1
- package/build/_cjs/helpers/type-guards.js +0 -8
- package/build/_cjs/helpers/use-component/index.d.ts +0 -6
- package/build/_cjs/helpers/use-component/index.js +0 -17
- package/build/_cjs/helpers/use-component/types.d.ts +0 -22
- package/build/_cjs/helpers/use-component/types.js +0 -2
- package/build/_cjs/index.d.ts +0 -3
- package/build/_cjs/index.js +0 -19
- package/build/_cjs/slots/hook.d.ts +0 -20
- package/build/_cjs/slots/hook.js +0 -147
- package/build/_cjs/slots/index.d.ts +0 -1
- package/build/_cjs/slots/index.js +0 -17
- package/build/_cjs/slots/types.d.ts +0 -128
- package/build/_cjs/slots/types.js +0 -2
- package/build/helpers/debounce/index.d.ts +0 -55
- package/build/helpers/debounce/index.js +0 -107
- package/build/helpers/debounce/react-state.d.ts +0 -14
- package/build/helpers/debounce/react-state.js +0 -29
- package/build/helpers/object-gate.d.ts +0 -74
- package/build/helpers/object-gate.js +0 -64
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import type { TCleanState } from '../../base/state/index.js';
|
|
2
|
-
import type { UseLogic } from './types/hook.js';
|
|
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
|
-
/**/
|
|
@@ -1,123 +0,0 @@
|
|
|
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/index.js");
|
|
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
|
-
/**/
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ComponentLogic } from '../index.js';
|
|
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 {};
|
|
@@ -1,9 +0,0 @@
|
|
|
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.js");
|
|
5
|
-
Object.defineProperty(exports, "ComponentMethods", { enumerable: true, get: function () { return methods_1.ComponentMethods; } });
|
|
6
|
-
var logic_1 = require("../../classy/logic/index.js");
|
|
7
|
-
Object.defineProperty(exports, "ComponentLogic", { enumerable: true, get: function () { return logic_1.ComponentLogic; } });
|
|
8
|
-
var instance_1 = require("../../classy/instance/index.js");
|
|
9
|
-
Object.defineProperty(exports, "ComponentInstance", { enumerable: true, get: function () { return instance_1.ComponentInstance; } });
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API Reference
|
|
3
|
-
* @module API
|
|
4
|
-
*/
|
|
5
|
-
export { useCleanState } from '../../base/state/index.js';
|
|
6
|
-
export { useMethods } from '../../base/methods.js';
|
|
7
|
-
export { useLogic } from '../../classy/logic/index.js';
|
|
8
|
-
export { useInstance } from '../../classy/instance/index.js';
|
|
9
|
-
export { ClassComponent } from '../../classy/class/index.js';
|
|
10
|
-
/** @namespace */
|
|
11
|
-
export * as BaseClasses from './base-classes.js';
|
|
12
|
-
export * as Helpers from '../../helpers/index.js';
|
|
13
|
-
export * as References from './references.js';
|
|
@@ -1,44 +0,0 @@
|
|
|
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/index.js");
|
|
32
|
-
Object.defineProperty(exports, "useCleanState", { enumerable: true, get: function () { return state_1.useCleanState; } });
|
|
33
|
-
var methods_1 = require("../../base/methods.js");
|
|
34
|
-
Object.defineProperty(exports, "useMethods", { enumerable: true, get: function () { return methods_1.useMethods; } });
|
|
35
|
-
var logic_1 = require("../../classy/logic/index.js");
|
|
36
|
-
Object.defineProperty(exports, "useLogic", { enumerable: true, get: function () { return logic_1.useLogic; } });
|
|
37
|
-
var instance_1 = require("../../classy/instance/index.js");
|
|
38
|
-
Object.defineProperty(exports, "useInstance", { enumerable: true, get: function () { return instance_1.useInstance; } });
|
|
39
|
-
var class_1 = require("../../classy/class/index.js");
|
|
40
|
-
Object.defineProperty(exports, "ClassComponent", { enumerable: true, get: function () { return class_1.ClassComponent; } });
|
|
41
|
-
/** @namespace */
|
|
42
|
-
exports.BaseClasses = __importStar(require("./base-classes.js"));
|
|
43
|
-
exports.Helpers = __importStar(require("../../helpers/index.js"));
|
|
44
|
-
exports.References = __importStar(require("./references.js"));
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export * as $CleanState from '../../base/state/index.js';
|
|
2
|
-
export * as $ComponentMethods from '../../base/methods.js';
|
|
3
|
-
export * as ComponentLogic from '../../classy/logic/index.js';
|
|
4
|
-
export * as ComponentInstance from '../../classy/instance/index.js';
|
|
5
|
-
export * as ClassComponent from '../../classy/class/index.js';
|
|
@@ -1,31 +0,0 @@
|
|
|
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/index.js"));
|
|
28
|
-
exports.$ComponentMethods = __importStar(require("../../base/methods.js"));
|
|
29
|
-
exports.ComponentLogic = __importStar(require("../../classy/logic/index.js"));
|
|
30
|
-
exports.ComponentInstance = __importStar(require("../../classy/instance/index.js"));
|
|
31
|
-
exports.ClassComponent = __importStar(require("../../classy/class/index.js"));
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
interface IDebouncedFunction<TFunc extends AnyFunction> {
|
|
2
|
-
(...args: Parameters<TFunc>): Promise<ReturnType<TFunc>>;
|
|
3
|
-
/**
|
|
4
|
-
* Called internally to trigger the callback with the most recent args
|
|
5
|
-
* after the delay expires. Can be used to manually trigger the callback
|
|
6
|
-
* before the normal delay time. If no pending call exists, flush() becomes a no-op.
|
|
7
|
-
*/
|
|
8
|
-
flush: (isEager?: true) => void;
|
|
9
|
-
}
|
|
10
|
-
export interface IDelayConfig {
|
|
11
|
-
/**
|
|
12
|
-
* A non-zero delay in milliseconds.
|
|
13
|
-
* @default 0
|
|
14
|
-
*/
|
|
15
|
-
delay?: number;
|
|
16
|
-
/**
|
|
17
|
-
* The 'last-call' value specifies that the timer should be applied from the time of the most recent call.
|
|
18
|
-
* That means each new call while a delay is active will reset the timer, thereby extending the delay.
|
|
19
|
-
* In other words, it is a "time after inactivity" delay.
|
|
20
|
-
* Specifying 'first-call' instead will make it use a "time after initial call" delay strategy.
|
|
21
|
-
*/
|
|
22
|
-
anchor?: 'first-call' | 'last-call';
|
|
23
|
-
/**
|
|
24
|
-
* Controls eager execution behavior:
|
|
25
|
-
* - `false`: Initial call waits for the delay period before executing.
|
|
26
|
-
* - `'no-queue'`: Initial call fires immediately. Subsequent calls during the delay period
|
|
27
|
-
* are skipped and return the promise from the initial call. Ideal for preventing
|
|
28
|
-
* duplicate actions like clicking a download button twice.
|
|
29
|
-
* - `'with-queue'`: Initial call fires immediately. After the initial flush, the promise
|
|
30
|
-
* is discarded. The next call during the delay period creates a new workorder that will
|
|
31
|
-
* be maintained until the next flush. Ideal for debounced search inputs and similar use cases.
|
|
32
|
-
* @default 'with-queue'
|
|
33
|
-
*/
|
|
34
|
-
eager?: false | 'no-queue' | 'with-queue';
|
|
35
|
-
}
|
|
36
|
-
interface IDebounce {
|
|
37
|
-
<TFunc extends AnyFunction>(callback: TFunc, delayConfigArg?: number | IDelayConfig): IDebouncedFunction<TFunc>;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Wraps the provided function with a debounce.
|
|
41
|
-
*
|
|
42
|
-
* Behavior during the delay period depends on the `eager` configuration:
|
|
43
|
-
* - `eager: false`: All calls wait for the delay. New calls overwrite the existing call.
|
|
44
|
-
* - `eager: 'no-queue'`: First call fires immediately. Subsequent calls during the delay
|
|
45
|
-
* period are skipped and return the same promise as the initial call.
|
|
46
|
-
* - `eager: 'with-queue'` (default): First call fires immediately. After the flush, the next call
|
|
47
|
-
* creates a new workorder that will be fired after the delay. New calls overwrite queued args.
|
|
48
|
-
*
|
|
49
|
-
* Once the timer expires, the most recent call is fired.
|
|
50
|
-
*
|
|
51
|
-
* Note: Returned promises may resolve with values from calls made with
|
|
52
|
-
* different arguments. Avoid using this for functions where argument-specific results matter.
|
|
53
|
-
*/
|
|
54
|
-
export declare const debounce: IDebounce;
|
|
55
|
-
export {};
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.debounce = void 0;
|
|
13
|
-
/**
|
|
14
|
-
* Wraps the provided function with a debounce.
|
|
15
|
-
*
|
|
16
|
-
* Behavior during the delay period depends on the `eager` configuration:
|
|
17
|
-
* - `eager: false`: All calls wait for the delay. New calls overwrite the existing call.
|
|
18
|
-
* - `eager: 'no-queue'`: First call fires immediately. Subsequent calls during the delay
|
|
19
|
-
* period are skipped and return the same promise as the initial call.
|
|
20
|
-
* - `eager: 'with-queue'` (default): First call fires immediately. After the flush, the next call
|
|
21
|
-
* creates a new workorder that will be fired after the delay. New calls overwrite queued args.
|
|
22
|
-
*
|
|
23
|
-
* Once the timer expires, the most recent call is fired.
|
|
24
|
-
*
|
|
25
|
-
* Note: Returned promises may resolve with values from calls made with
|
|
26
|
-
* different arguments. Avoid using this for functions where argument-specific results matter.
|
|
27
|
-
*/
|
|
28
|
-
const debounce = (...init) => {
|
|
29
|
-
const [callback, delayArg] = init;
|
|
30
|
-
const delayConfig = {
|
|
31
|
-
delay: 1000,
|
|
32
|
-
anchor: 'first-call',
|
|
33
|
-
eager: 'with-queue',
|
|
34
|
-
};
|
|
35
|
-
if (typeof delayArg === 'number') {
|
|
36
|
-
delayConfig.delay = delayArg || 1000;
|
|
37
|
-
}
|
|
38
|
-
else if (delayArg) {
|
|
39
|
-
for (const _key in delayArg) {
|
|
40
|
-
const key = _key;
|
|
41
|
-
if (delayArg[key] !== undefined) {
|
|
42
|
-
// @ts-expect-error
|
|
43
|
-
delayConfig[key] = delayArg[key];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
let nextCall = null;
|
|
48
|
-
const debouncedFunction = (...args) => {
|
|
49
|
-
let currentWork;
|
|
50
|
-
if (nextCall) {
|
|
51
|
-
if (delayConfig.eager !== 'no-queue') {
|
|
52
|
-
nextCall = Object.assign(Object.assign({}, nextCall), { args, work: nextCall.work || Promise.withResolvers() });
|
|
53
|
-
}
|
|
54
|
-
currentWork = nextCall.work;
|
|
55
|
-
if (delayConfig.anchor === 'last-call') {
|
|
56
|
-
clearTimeout(nextCall.timeout);
|
|
57
|
-
nextCall.timeout = setTimeout(debouncedFunction.flush, delayConfig.delay);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
// No active delay, create new call
|
|
62
|
-
nextCall = {
|
|
63
|
-
args,
|
|
64
|
-
timeout: setTimeout(debouncedFunction.flush, delayConfig.delay),
|
|
65
|
-
work: Promise.withResolvers(),
|
|
66
|
-
};
|
|
67
|
-
currentWork = nextCall.work;
|
|
68
|
-
// Fire immediately if eager mode is enabled (no-queue or with-queue)
|
|
69
|
-
if (delayConfig.eager !== false) {
|
|
70
|
-
debouncedFunction.flush(true);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (!currentWork) {
|
|
74
|
-
throw new Error('[debounce] `currentWork` was not initialized.');
|
|
75
|
-
}
|
|
76
|
-
return currentWork.promise;
|
|
77
|
-
};
|
|
78
|
-
debouncedFunction.flush = (isEager) => {
|
|
79
|
-
if (!(nextCall === null || nextCall === void 0 ? void 0 : nextCall.args)) {
|
|
80
|
-
nextCall = null;
|
|
81
|
-
// console.log('Queue is empty. Nothing to flush.');
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
// Capture queue values.
|
|
85
|
-
const { resolve, reject } = nextCall.work || {};
|
|
86
|
-
const args = nextCall.args;
|
|
87
|
-
// Clear the queue for new debounced calls.
|
|
88
|
-
if (isEager) {
|
|
89
|
-
delete nextCall.args;
|
|
90
|
-
if (delayConfig.eager === 'with-queue') {
|
|
91
|
-
delete nextCall.work;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
nextCall = null;
|
|
96
|
-
}
|
|
97
|
-
// Execute the pending call.
|
|
98
|
-
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
-
try {
|
|
100
|
-
// const result = (await callback(...args)) ?? {};
|
|
101
|
-
// result.__debounceFlushedWithArgs = args;
|
|
102
|
-
resolve === null || resolve === void 0 ? void 0 : resolve(yield callback(...args));
|
|
103
|
-
}
|
|
104
|
-
catch (reason) {
|
|
105
|
-
reject === null || reject === void 0 ? void 0 : reject(reason);
|
|
106
|
-
}
|
|
107
|
-
}))();
|
|
108
|
-
};
|
|
109
|
-
return debouncedFunction;
|
|
110
|
-
};
|
|
111
|
-
exports.debounce = debounce;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { SetStateAction } from 'react';
|
|
2
|
-
import { debounce } from './index.js';
|
|
3
|
-
type TDebounceConfig = Exclude<Parameters<typeof debounce>[1], number>;
|
|
4
|
-
type TDelayConfig = number | TDebounceConfig & {
|
|
5
|
-
staging?: boolean;
|
|
6
|
-
};
|
|
7
|
-
export declare function useDebouncedState<T extends any>(init: T, config: TDelayConfig): readonly [T, {
|
|
8
|
-
(value: SetStateAction<T>): void;
|
|
9
|
-
flush: (isEager?: true) => void;
|
|
10
|
-
pause(): void;
|
|
11
|
-
resume(): void;
|
|
12
|
-
paused: boolean;
|
|
13
|
-
}, T];
|
|
14
|
-
export {};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useDebouncedState = useDebouncedState;
|
|
4
|
-
const react_1 = require("react");
|
|
5
|
-
const _1 = require("./index.js");
|
|
6
|
-
function useDebouncedState(init, config) {
|
|
7
|
-
const [debouncedValue, setDebouncedValue] = (0, react_1.useState)(init);
|
|
8
|
-
const [stagedValue, setStagedValue] = (0, react_1.useState)(init);
|
|
9
|
-
const [paused, setPaused] = (0, react_1.useState)(false);
|
|
10
|
-
const enableStaging = typeof config === 'object' && config.staging === true;
|
|
11
|
-
const debounceArgs = [setDebouncedValue, config];
|
|
12
|
-
const debouncedSetter = (0, react_1.useCallback)((0, _1.debounce)(...debounceArgs), debounceArgs);
|
|
13
|
-
const setter = (0, react_1.useMemo)(() => {
|
|
14
|
-
const _setter = (value) => {
|
|
15
|
-
if (enableStaging) {
|
|
16
|
-
setStagedValue(value);
|
|
17
|
-
}
|
|
18
|
-
if (paused) {
|
|
19
|
-
console.warn('[useDebouncedState] Skipping debounced state update. Updates were paused with `setter.pause()`. Call `setter.play()` to resume.');
|
|
20
|
-
}
|
|
21
|
-
else
|
|
22
|
-
debouncedSetter(value);
|
|
23
|
-
};
|
|
24
|
-
_setter.flush = debouncedSetter.flush;
|
|
25
|
-
_setter.pause = () => setPaused(true);
|
|
26
|
-
_setter.resume = () => setPaused(false);
|
|
27
|
-
_setter.paused = paused;
|
|
28
|
-
return _setter;
|
|
29
|
-
}, [enableStaging, debouncedSetter]);
|
|
30
|
-
setter.paused = paused;
|
|
31
|
-
return [debouncedValue, setter, stagedValue];
|
|
32
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
|
@@ -1,21 +0,0 @@
|
|
|
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;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* <!-- @ mergeModuleWith API -->
|
|
3
|
-
* @module Helpers
|
|
4
|
-
*/
|
|
5
|
-
export * from './mount-state.js';
|
|
6
|
-
export * from './rerender.js';
|
|
7
|
-
export * from './use-component/index.js';
|
|
8
|
-
export * from './object-gate.js';
|
|
9
|
-
export * from './debounce/index.js';
|
|
10
|
-
export * from './debounce/react-state.js';
|
|
11
|
-
export * from './type-guards.js';
|
|
12
|
-
/**
|
|
13
|
-
* An empty function.
|
|
14
|
-
* It returns (void) without performing any operations.
|
|
15
|
-
*/
|
|
16
|
-
export declare const noOp: () => void;
|