@cleanweb/react 1.1.1-beta.8 → 2.0.1-beta.0
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/README.md +242 -187
- package/README.old.md +342 -0
- package/build/base/merged-state.d.ts +1 -0
- package/build/base/merged-state.js +3 -2
- package/build/base/methods.d.ts +40 -7
- package/build/base/methods.js +45 -81
- package/build/base/state/class-types.d.ts +17 -0
- package/build/base/state/class-types.js +2 -0
- package/build/base/state/class.d.ts +14 -0
- package/build/base/{state.js → state/class.js} +4 -55
- package/build/base/state/hook-types.d.ts +11 -0
- package/build/base/state/hook-types.js +2 -0
- package/build/base/state/hooks.d.ts +11 -0
- package/build/base/state/hooks.js +57 -0
- package/build/base/state/index.d.ts +4 -0
- package/build/base/state/index.js +9 -0
- package/build/classy/class/index.d.ts +102 -0
- package/build/classy/class/index.js +147 -0
- package/build/classy/class/types/class/instance.d.ts +12 -0
- package/build/classy/class/types/class/instance.js +2 -0
- package/build/classy/class/types/class/static.d.ts +9 -0
- package/build/classy/class/types/class/static.js +12 -0
- package/build/classy/class/types/extractor.d.ts +6 -0
- package/build/classy/class/types/extractor.js +2 -0
- package/build/classy/class/utils/function-name.d.ts +2 -0
- package/build/classy/class/utils/function-name.js +17 -0
- package/build/classy/class/utils/rerender.d.ts +1 -0
- package/build/classy/class/utils/rerender.js +11 -0
- package/build/classy/class/utils/use-component/index.d.ts +6 -0
- package/build/classy/class/utils/use-component/index.js +17 -0
- package/build/classy/class/utils/use-component/types.d.ts +22 -0
- package/build/classy/class/utils/use-component/types.js +2 -0
- package/build/classy/instance/index.d.ts +94 -0
- package/build/classy/{instance.js → instance/index.js} +62 -33
- package/build/classy/instance/mount-callbacks.d.ts +4 -0
- package/build/classy/instance/mount-callbacks.js +30 -0
- package/build/classy/instance/types/hook.d.ts +16 -0
- package/build/classy/instance/types/hook.js +2 -0
- package/build/classy/instance/types/instance.d.ts +11 -0
- package/build/classy/instance/types/instance.js +2 -0
- package/build/classy/instance/types/static.d.ts +11 -0
- package/build/classy/instance/types/static.js +17 -0
- package/build/classy/logic/index.d.ts +42 -0
- package/build/classy/logic/index.js +122 -0
- package/build/classy/logic/types/hook.d.ts +24 -0
- package/build/classy/logic/types/hook.js +2 -0
- package/build/classy/logic/types/instance.d.ts +18 -0
- package/build/classy/logic/types/instance.js +2 -0
- package/build/classy/logic/types/static.d.ts +17 -0
- package/build/classy/logic/types/static.js +2 -0
- package/build/globals.d.ts +23 -33
- package/build/globals.js +2 -20
- package/build/index.d.ts +1 -1
- package/build/index.js +2 -1
- package/build/tsconfig.json +3 -0
- package/package.json +8 -6
- package/build/base/state.d.ts +0 -29
- package/build/classy/class.d.ts +0 -22
- package/build/classy/class.js +0 -118
- package/build/classy/instance.d.ts +0 -60
- package/build/classy/logic.d.ts +0 -20
- package/build/classy/logic.js +0 -79
- package/build/globals.private.d.ts +0 -44
- package/build/globals.private.js +0 -34
@@ -15,37 +15,18 @@ var __extends = (this && this.__extends) || (function () {
|
|
15
15
|
};
|
16
16
|
})();
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
18
|
-
exports.useInstance = exports.ComponentInstance = exports.noOp =
|
18
|
+
exports.useInstance = exports.ComponentInstance = exports.noOp = void 0;
|
19
19
|
var react_1 = require("react");
|
20
|
-
var
|
21
|
-
var
|
22
|
-
|
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
|
-
};
|
46
|
-
exports.useMountCallbacks = useMountCallbacks;
|
20
|
+
var logic_1 = require("../../classy/logic");
|
21
|
+
var mount_callbacks_1 = require("./mount-callbacks");
|
22
|
+
/** An empty function. It returns (void) without performing any operations. */
|
47
23
|
var noOp = function () { };
|
48
24
|
exports.noOp = noOp;
|
25
|
+
/**
|
26
|
+
* A superset of {@link ComponentLogic} that adds support for lifecycle methods.
|
27
|
+
* This provides a declarative API for working with your React function component's lifecycle,
|
28
|
+
* a simpler alternative to the imperative approach with `useEffect` and/or `useMemo`.
|
29
|
+
*/
|
49
30
|
var ComponentInstance = /** @class */ (function (_super) {
|
50
31
|
__extends(ComponentInstance, _super);
|
51
32
|
function ComponentInstance() {
|
@@ -95,11 +76,17 @@ var ComponentInstance = /** @class */ (function (_super) {
|
|
95
76
|
_this.cleanUp = function () { };
|
96
77
|
return _this;
|
97
78
|
}
|
79
|
+
Object.defineProperty(ComponentInstance.prototype, "templateContext", {
|
80
|
+
get: function () {
|
81
|
+
return this._templateContext;
|
82
|
+
},
|
83
|
+
enumerable: false,
|
84
|
+
configurable: true
|
85
|
+
});
|
98
86
|
return ComponentInstance;
|
99
|
-
}(logic_1.ComponentLogic));
|
87
|
+
}(logic_1.ComponentLogic.Class));
|
100
88
|
exports.ComponentInstance = ComponentInstance;
|
101
89
|
;
|
102
|
-
;
|
103
90
|
/*
|
104
91
|
* To ensure successful type checking, the second parameter must be written with spread syntax.
|
105
92
|
* Likely because of the `exactOptionalPropertyTypes` config option turned on,
|
@@ -117,7 +104,7 @@ var useInstance = function () {
|
|
117
104
|
}
|
118
105
|
var Component = args[0], _b = args[1], props = _b === void 0 ? {} : _b;
|
119
106
|
// useHooks.
|
120
|
-
var instance = (0, logic_1.useLogic)(Component, props);
|
107
|
+
var instance = (0, logic_1.useLogic)(Component, props);
|
121
108
|
/**
|
122
109
|
* Argument of type '
|
123
110
|
* [
|
@@ -133,9 +120,15 @@ var useInstance = function () {
|
|
133
120
|
'
|
134
121
|
*/
|
135
122
|
// beforeMount, onMount, cleanUp.
|
136
|
-
(0,
|
123
|
+
(0, mount_callbacks_1.useMountCallbacks)(instance);
|
137
124
|
// beforeRender.
|
138
|
-
|
125
|
+
/**
|
126
|
+
* A proxy variable to allow typechecking of the assignment
|
127
|
+
* to `self.templateContext` despite the need for "readonly" error suppression.
|
128
|
+
*/
|
129
|
+
var _templateContextProxy_;
|
130
|
+
// @ts-expect-error
|
131
|
+
instance._templateContext = (_templateContextProxy_ = (_a = instance.beforeRender) === null || _a === void 0 ? void 0 : _a.call(instance));
|
139
132
|
// onRender.
|
140
133
|
(0, react_1.useEffect)(function () {
|
141
134
|
var _a;
|
@@ -150,3 +143,39 @@ var useInstance = function () {
|
|
150
143
|
return instance;
|
151
144
|
};
|
152
145
|
exports.useInstance = useInstance;
|
146
|
+
(function (ComponentInstance) {
|
147
|
+
var Class = /** @class */ (function (_super) {
|
148
|
+
__extends(Class, _super);
|
149
|
+
function Class() {
|
150
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
151
|
+
}
|
152
|
+
return Class;
|
153
|
+
}(ComponentInstance));
|
154
|
+
ComponentInstance.Class = Class;
|
155
|
+
;
|
156
|
+
})(ComponentInstance || (exports.ComponentInstance = ComponentInstance = {}));
|
157
|
+
/** /
|
158
|
+
testing: {
|
159
|
+
class A extends ComponentInstance<{}, {}> {
|
160
|
+
static getInitialState: (p?: object) => ({putan: ''});
|
161
|
+
// k = this.props.o
|
162
|
+
a = this.state['_initialValues_'];
|
163
|
+
|
164
|
+
beforeRender = () => '';
|
165
|
+
|
166
|
+
useHooks = () => {
|
167
|
+
type a = typeof this._templateContext;
|
168
|
+
};
|
169
|
+
// hard empty has every key
|
170
|
+
// weak empty has no key
|
171
|
+
// weak empty is not assignable to hard empty
|
172
|
+
}
|
173
|
+
|
174
|
+
const a = useInstance(A, {o: ''});
|
175
|
+
a.a;
|
176
|
+
|
177
|
+
// a.props['o'];
|
178
|
+
type bbbb = A['state'];
|
179
|
+
type ttt = bbbb['put'];
|
180
|
+
}
|
181
|
+
/**/
|
@@ -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,16 @@
|
|
1
|
+
import type { CIBaseType, IComponentInstance } from './instance';
|
2
|
+
import type { IComponentInstanceClass } from './static';
|
3
|
+
import { ComponentInstance } from '..';
|
4
|
+
type o = object;
|
5
|
+
type UIClassParam = IComponentInstanceClass<IComponentInstance<CIBaseType>>;
|
6
|
+
type UIProplessClassParam = IComponentInstanceClass<IComponentInstance<ComponentInstance<HardEmptyObject, o>>>;
|
7
|
+
export type UseInstance = {
|
8
|
+
<Class extends UIProplessClassParam>(Methods: Class & Constructor<InstanceType<Class>>): InstanceType<Class>;
|
9
|
+
<Class extends UIClassParam>(Methods: Class & Constructor<InstanceType<Class>>, props: InstanceType<Class>['props']): InstanceType<Class>;
|
10
|
+
};
|
11
|
+
export type UIParams = [
|
12
|
+
Class: IComponentInstanceClass<IComponentInstance<CIBaseType>>,
|
13
|
+
props?: object
|
14
|
+
];
|
15
|
+
export type UIReturn = CIBaseType;
|
16
|
+
export {};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { InstanceOverrides as CLInstanceOverrides } from '../../../classy/logic/types/instance';
|
2
|
+
import type { ExtractCleanStateData } from '../../../base';
|
3
|
+
import { ComponentInstance } from '../../../classy/instance';
|
4
|
+
export type CIBaseType = Omit<ComponentInstance<object, object>, never>;
|
5
|
+
type CIFromSubType<SubType extends CIBaseType> = ComponentInstance<SubType['props'], ExtractCleanStateData<SubType['state']>>;
|
6
|
+
export interface InstanceOverrides<Instance extends CIBaseType = ComponentInstance> extends CLInstanceOverrides<Instance> {
|
7
|
+
}
|
8
|
+
type BaseInstance<Instance extends CIBaseType = ComponentInstance> = Omit<CIFromSubType<Instance>, keyof InstanceOverrides>;
|
9
|
+
export interface IComponentInstance<Instance extends CIBaseType = ComponentInstance> extends BaseInstance<Instance>, InstanceOverrides<Instance> {
|
10
|
+
}
|
11
|
+
export {};
|
@@ -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> = ComponentInstance,
|
13
|
+
// > extends
|
14
|
+
// Constructor<IComponentInstance<Instance>>,
|
15
|
+
// ComponentInstanceOwnStatics,
|
16
|
+
// ComponentLogic.ClassType<Instance>
|
17
|
+
// {};
|
@@ -0,0 +1,42 @@
|
|
1
|
+
import type { TCleanState, TStateData } from '../../base/state';
|
2
|
+
import type { IComponentLogicClass } from './types/static';
|
3
|
+
import type { CLBaseType, IComponentLogic } from './types/instance';
|
4
|
+
import type { UseLogic } from './types/hook';
|
5
|
+
export type HardEmpty = HardEmptyObject;
|
6
|
+
export type WeakEmpty = WeakEmptyObject;
|
7
|
+
/**
|
8
|
+
* Base class for a class that holds methods intended for use in a function component,
|
9
|
+
* as well as a static method for initializing state.
|
10
|
+
*
|
11
|
+
* These methods will have access to the components state and props via
|
12
|
+
* `this.state` and `this.props` respectively.
|
13
|
+
*
|
14
|
+
* The special {@link Class['useHooks'] | useHooks} method allows you to consume
|
15
|
+
* React hooks within this class.
|
16
|
+
*
|
17
|
+
* Call the {@link useLogic} hook inside your function component to instantiate the class.
|
18
|
+
*/
|
19
|
+
export declare class ComponentLogic<TProps extends object = {}, TState extends TStateData = WeakEmpty> {
|
20
|
+
readonly state: TCleanState<TState>;
|
21
|
+
readonly props: TProps;
|
22
|
+
readonly hooks: ReturnType<this['useHooks']>;
|
23
|
+
/**
|
24
|
+
* Called before each instance of your component is mounted.
|
25
|
+
* It receives the initial `props` object and should return
|
26
|
+
* an object with the initial values for your component's state.
|
27
|
+
*/
|
28
|
+
static getInitialState: (p?: any) => object;
|
29
|
+
/**
|
30
|
+
* Call React hooks and expose any values your component
|
31
|
+
* needs by returning an object with said values. The returned
|
32
|
+
* object will be accessible as `this.hooks`;
|
33
|
+
*/
|
34
|
+
useHooks: () => object | void;
|
35
|
+
}
|
36
|
+
export declare const useLogic: UseLogic;
|
37
|
+
export declare namespace ComponentLogic {
|
38
|
+
class Class<TProps extends object = {}, TState extends TStateData = WeakEmpty> extends ComponentLogic<TProps, TState> {
|
39
|
+
}
|
40
|
+
type Instance<Instance extends CLBaseType = Class> = IComponentLogic<Instance>;
|
41
|
+
type ClassType<Instance extends CLBaseType = Class> = IComponentLogicClass<Instance>;
|
42
|
+
}
|
@@ -0,0 +1,122 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
3
|
+
var extendStatics = function (d, b) {
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
7
|
+
return extendStatics(d, b);
|
8
|
+
};
|
9
|
+
return function (d, b) {
|
10
|
+
if (typeof b !== "function" && b !== null)
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
12
|
+
extendStatics(d, b);
|
13
|
+
function __() { this.constructor = d; }
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
15
|
+
};
|
16
|
+
})();
|
17
|
+
var _a;
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
19
|
+
exports.useLogic = exports.ComponentLogic = void 0;
|
20
|
+
var react_1 = require("react");
|
21
|
+
var state_1 = require("../../base/state");
|
22
|
+
/**
|
23
|
+
* Base class for a class that holds methods intended for use in a function component,
|
24
|
+
* as well as a static method for initializing state.
|
25
|
+
*
|
26
|
+
* These methods will have access to the components state and props via
|
27
|
+
* `this.state` and `this.props` respectively.
|
28
|
+
*
|
29
|
+
* The special {@link Class['useHooks'] | useHooks} method allows you to consume
|
30
|
+
* React hooks within this class.
|
31
|
+
*
|
32
|
+
* Call the {@link useLogic} hook inside your function component to instantiate the class.
|
33
|
+
*/
|
34
|
+
var ComponentLogic = /** @class */ (function () {
|
35
|
+
function ComponentLogic() {
|
36
|
+
// * PS: `p?: object` wierdly causes TS error in v^5.5.4; object is not assignable to the component's TProps.
|
37
|
+
/**
|
38
|
+
* Call React hooks and expose any values your component
|
39
|
+
* needs by returning an object with said values. The returned
|
40
|
+
* object will be accessible as `this.hooks`;
|
41
|
+
*/
|
42
|
+
this.useHooks = function () { };
|
43
|
+
}
|
44
|
+
/**
|
45
|
+
* Called before each instance of your component is mounted.
|
46
|
+
* It receives the initial `props` object and should return
|
47
|
+
* an object with the initial values for your component's state.
|
48
|
+
*/
|
49
|
+
ComponentLogic.getInitialState = function (p) { return ({}); };
|
50
|
+
return ComponentLogic;
|
51
|
+
}());
|
52
|
+
exports.ComponentLogic = ComponentLogic;
|
53
|
+
;
|
54
|
+
var useLogic = function () {
|
55
|
+
var _a;
|
56
|
+
var args = [];
|
57
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
58
|
+
args[_i] = arguments[_i];
|
59
|
+
}
|
60
|
+
var Logic = args[0], _b = args[1], props = _b === void 0 ? {} : _b;
|
61
|
+
var state = (0, state_1.useCleanState)(Logic.getInitialState, props);
|
62
|
+
var self = (0, react_1.useRef)((0, react_1.useMemo)(function () {
|
63
|
+
return new Logic();
|
64
|
+
}, [])).current;
|
65
|
+
/** A proxy variable to allow typechecking of the assignment to `self.props` despite the need for "readonly" error suppression. */
|
66
|
+
var _propsProxy_;
|
67
|
+
/** A proxy variable to allow typechecking of the assignment to `self.state` despite the need for "readonly" error suppression. */
|
68
|
+
var _stateProxy_;
|
69
|
+
/** A proxy variable to allow typechecking of the assignment to `self.hooks` despite the need for "readonly" error suppression. */
|
70
|
+
var _hooksProxy_;
|
71
|
+
// @ts-expect-error
|
72
|
+
self.props = (_propsProxy_ = props);
|
73
|
+
// @ts-expect-error
|
74
|
+
self.state = (_stateProxy_ = state);
|
75
|
+
// @ts-expect-error
|
76
|
+
self.hooks = (_hooksProxy_ = (_a = self.useHooks()) !== null && _a !== void 0 ? _a : {});
|
77
|
+
return self;
|
78
|
+
};
|
79
|
+
exports.useLogic = useLogic;
|
80
|
+
(function (ComponentLogic) {
|
81
|
+
var Class = /** @class */ (function (_super) {
|
82
|
+
__extends(Class, _super);
|
83
|
+
function Class() {
|
84
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
85
|
+
}
|
86
|
+
return Class;
|
87
|
+
}(ComponentLogic));
|
88
|
+
ComponentLogic.Class = Class;
|
89
|
+
;
|
90
|
+
})(ComponentLogic || (exports.ComponentLogic = ComponentLogic = {}));
|
91
|
+
/**/
|
92
|
+
testing: {
|
93
|
+
var a = { b: '' };
|
94
|
+
var MyComponentLogic = /** @class */ (function (_super) {
|
95
|
+
__extends(MyComponentLogic, _super);
|
96
|
+
function MyComponentLogic() {
|
97
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
98
|
+
// b = this.state.put[''] + this.props.b;
|
99
|
+
_this.useHooks = function () { return ({ a: 'undefined' }); };
|
100
|
+
return _this;
|
101
|
+
}
|
102
|
+
MyComponentLogic.getInitialState = function () { return ({ b: 7 }); };
|
103
|
+
return MyComponentLogic;
|
104
|
+
}(ComponentLogic.Class));
|
105
|
+
;
|
106
|
+
MyComponentLogic.getInitialState;
|
107
|
+
var self_1 = (0, exports.useLogic)(MyComponentLogic);
|
108
|
+
self_1.hooks;
|
109
|
+
self_1.useHooks();
|
110
|
+
var A = /** @class */ (function (_super) {
|
111
|
+
__extends(C, _super);
|
112
|
+
function C() {
|
113
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
114
|
+
}
|
115
|
+
return C;
|
116
|
+
}(ComponentLogic.Class));
|
117
|
+
A.getInitialState();
|
118
|
+
// const oa = {['a' as unknown as symbol]: 'boo'};
|
119
|
+
var oa = (_a = {}, _a['a'] = 'boo', _a);
|
120
|
+
(0, exports.useLogic)(A, oa);
|
121
|
+
}
|
122
|
+
/**/
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import type { ComponentLogic } from '..';
|
2
|
+
import type { CLBaseType, IComponentLogic } from './instance';
|
3
|
+
import type { IComponentLogicClass } from './static';
|
4
|
+
/*************************************
|
5
|
+
* # Utils *
|
6
|
+
**************************************/
|
7
|
+
/** */
|
8
|
+
type o = object;
|
9
|
+
/*************************************
|
10
|
+
* # Hooks *
|
11
|
+
**************************************/
|
12
|
+
/** */
|
13
|
+
type ULClassParam = IComponentLogicClass<IComponentLogic<CLBaseType>>;
|
14
|
+
type ULProplessClassParam = IComponentLogicClass<IComponentLogic<ComponentLogic<HardEmptyObject, o>>>;
|
15
|
+
export type UseLogic = {
|
16
|
+
<Class extends ULProplessClassParam>(Methods: Class & Constructor<IComponentLogic<InstanceType<Class>>>): InstanceType<Class>;
|
17
|
+
<Class extends ULClassParam>(Methods: Class & Constructor<IComponentLogic<InstanceType<Class>>>, props: InstanceType<Class>['props']): InstanceType<Class>;
|
18
|
+
};
|
19
|
+
export type ULParams = [
|
20
|
+
Class: ComponentLogic.ClassType<ComponentLogic.Instance<CLBaseType>>,
|
21
|
+
props?: object
|
22
|
+
];
|
23
|
+
export type ULReturn = CLBaseType;
|
24
|
+
export {};
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import type { ExtractCleanStateData } from '../../../base';
|
2
|
+
import type { ComponentLogic } from '../../../classy/logic';
|
3
|
+
/*************************************
|
4
|
+
* # Utils *
|
5
|
+
**************************************/
|
6
|
+
/** */
|
7
|
+
export type CLBaseType = ComponentLogic<object, object>;
|
8
|
+
type CLFromSubType<SubType extends CLBaseType> = ComponentLogic<SubType['props'], ExtractCleanStateData<SubType['state']>>;
|
9
|
+
/*************************************
|
10
|
+
* # Instance Type *
|
11
|
+
**************************************/
|
12
|
+
/** */
|
13
|
+
export interface InstanceOverrides<Instance extends CLBaseType = ComponentLogic> {
|
14
|
+
}
|
15
|
+
type BaseInstance<Instance extends CLBaseType = ComponentLogic> = Omit<CLFromSubType<Instance>, keyof InstanceOverrides>;
|
16
|
+
export interface IComponentLogic<Instance extends CLBaseType = ComponentLogic> extends BaseInstance<Instance>, InstanceOverrides<Instance> {
|
17
|
+
}
|
18
|
+
export {};
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import type { ExtractCleanStateData } from '../../../base';
|
2
|
+
import type { ComponentLogic } from '../../../classy/logic';
|
3
|
+
import type { CLBaseType } from './instance';
|
4
|
+
/*************************************
|
5
|
+
* # Utils *
|
6
|
+
**************************************/
|
7
|
+
type o = object;
|
8
|
+
/*************************************
|
9
|
+
* # Class Static Side *
|
10
|
+
**************************************/
|
11
|
+
export interface StaticOverrides<Instance extends CLBaseType = ComponentLogic> extends Constructor<Instance> {
|
12
|
+
getInitialState: (props?: Instance['props']) => ExtractCleanStateData<Instance['state']>;
|
13
|
+
}
|
14
|
+
type BaseStatics = Omit<typeof ComponentLogic, 'prototype' | keyof StaticOverrides>;
|
15
|
+
export interface IComponentLogicClass<Instance extends ComponentLogic<o, o> = ComponentLogic> extends BaseStatics, StaticOverrides<Instance> {
|
16
|
+
}
|
17
|
+
export {};
|
package/build/globals.d.ts
CHANGED
@@ -1,24 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
* @example
|
15
|
-
* declare global {
|
16
|
-
* interface Window {
|
17
|
-
* ethereum: any
|
18
|
-
* }
|
19
|
-
* }
|
20
|
-
**/
|
21
|
-
/** */
|
1
|
+
declare const UniqueSecretSymbolKey: unique symbol;
|
2
|
+
/** /testing: {
|
3
|
+
const mySymbol = Symbol('asdfgh') as symbol;
|
4
|
+
|
5
|
+
const tt = {
|
6
|
+
// [mySymbol]: '' as never,
|
7
|
+
// [UniqueSecretSymbolKey]: '',
|
8
|
+
// '': '',
|
9
|
+
}
|
10
|
+
|
11
|
+
let TT: WeakEmptyObject = {};
|
12
|
+
TT = tt;
|
13
|
+
}/**/
|
22
14
|
declare global {
|
23
15
|
type Optional<BaseType, AllowNull extends boolean = true> = (AllowNull extends true ? BaseType | undefined | null : BaseType | undefined);
|
24
16
|
type Awaitable<Type> = Type | Promise<Type>;
|
@@ -37,11 +29,20 @@ declare global {
|
|
37
29
|
* Pass a type argument to set whether `async` and/or `sync` functions are allowed.
|
38
30
|
*/
|
39
31
|
interface IVoidFunction<AsyncType extends 'async' | 'sync' | 'both' = 'both'> {
|
40
|
-
(): AsyncType extends 'async' ? Promise<void> : AsyncType extends 'sync' ? void :
|
32
|
+
(): AsyncType extends 'async' ? Promise<void> : AsyncType extends 'sync' ? void : void | Promise<void>;
|
41
33
|
}
|
42
34
|
type AnyFunction = (...args: any) => any;
|
43
35
|
type FunctionType = AnyFunction;
|
44
36
|
type TFunction = AnyFunction;
|
37
|
+
type NotNullish = {};
|
38
|
+
type NonPrimitive = object;
|
39
|
+
interface WeakEmptyObject {
|
40
|
+
[UniqueSecretSymbolKey]?: never;
|
41
|
+
}
|
42
|
+
interface HardEmptyObject {
|
43
|
+
[key: keyof any]: never;
|
44
|
+
}
|
45
|
+
type valueof<TObject> = TObject[keyof TObject];
|
45
46
|
interface Window {
|
46
47
|
}
|
47
48
|
namespace JSX {
|
@@ -52,16 +53,5 @@ declare global {
|
|
52
53
|
interface ProcessEnv {
|
53
54
|
}
|
54
55
|
}
|
55
|
-
type __FromPrivateHelpers = typeof import('./globals.private');
|
56
|
-
type TEmptyObject1 = {
|
57
|
-
''?: never;
|
58
|
-
};
|
59
|
-
type TEmptyObject2 = Record<symbol, never>;
|
60
|
-
type EmptyObject = __FromPrivateHelpers['EmptyObject2'];
|
61
|
-
type EmptyObject2 = __FromPrivateHelpers['EmptyObject2'];
|
62
|
-
type EmptyObject3 = __FromPrivateHelpers['EmptyObject3'];
|
63
|
-
type valueof<TObject> = TObject[keyof TObject];
|
64
|
-
interface T extends __FromPrivateHelpers {
|
65
|
-
}
|
66
56
|
}
|
67
57
|
export {};
|
package/build/globals.js
CHANGED
@@ -1,22 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
/**
|
3
|
-
* @file
|
4
|
-
* This file is an "Ambient declarations file". The types defined here are available globally.
|
5
|
-
* More info here: https://stackoverflow.com/a/73389225/985454
|
6
|
-
*
|
7
|
-
* Don't use `import` and `export` in this file directly! It breaks ambience.
|
8
|
-
* To import external types in an ambient declarations file (this file) use the following:
|
9
|
-
*
|
10
|
-
* @example
|
11
|
-
* declare type React = typeof import('react');
|
12
|
-
*
|
13
|
-
* To contribute ambient declarations from any file, even non-ambient ones, use this:
|
14
|
-
*
|
15
|
-
* @example
|
16
|
-
* declare global {
|
17
|
-
* interface Window {
|
18
|
-
* ethereum: any
|
19
|
-
* }
|
20
|
-
* }
|
21
|
-
**/
|
22
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
/////////////
|
4
|
+
var UniqueSecretSymbolKey = Symbol('asdfghjkliuytrewqaxcvb,nb');
|
package/build/index.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from
|
1
|
+
export * from './classy';
|
package/build/index.js
CHANGED
@@ -16,7 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./classy"), exports);
|
18
18
|
// PS: Document component inheritance pattern with lifecycle callback arrays and namespaces.
|
19
|
-
// Due to react's remounting behaviour, components must externally track when some logic has run,
|
19
|
+
// Due to react's remounting behaviour, components must externally track when some logic has run,
|
20
|
+
// if it really really must only ever run once per mounted instance. Tricky to get right for components that may have multiple instance rendered simultaneously at different parts of a page.
|
20
21
|
// useCleanState => useState, separate call for each key
|
21
22
|
// useMergedState => useState, same call for all keys
|
22
23
|
// useMethods => useCallback
|
package/build/tsconfig.json
CHANGED
@@ -29,16 +29,19 @@
|
|
29
29
|
"isolatedModules": true,
|
30
30
|
"jsx": "react-jsx",
|
31
31
|
"strictNullChecks": true,
|
32
|
+
"strictPropertyInitialization": true,
|
32
33
|
"noImplicitAny": true,
|
33
34
|
"noUncheckedIndexedAccess": true,
|
34
35
|
"strictBindCallApply": true,
|
35
36
|
"exactOptionalPropertyTypes": true,
|
36
37
|
},
|
37
38
|
"include": [
|
39
|
+
// "**/[!globals].ts",
|
38
40
|
"**/*.ts",
|
39
41
|
"**/*.tsx"
|
40
42
|
],
|
41
43
|
"exclude": [
|
44
|
+
"**/globals.ts",
|
42
45
|
"node_modules/**/**.*",
|
43
46
|
"build/**/**.*",
|
44
47
|
"mirror-pkg/**/**.*"
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cleanweb/react",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.1-beta.0",
|
4
4
|
"description": "A suite of helpers for writing cleaner React function components.",
|
5
5
|
"engines": {
|
6
6
|
"node": ">=18"
|
@@ -22,15 +22,17 @@
|
|
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
|
-
"./
|
27
|
-
"./
|
28
|
-
"./
|
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",
|
32
34
|
"build": "tsc && tsc-alias",
|
33
|
-
"postbuild": "copyfiles
|
35
|
+
"postbuild": "copyfiles tsconfig.json build",
|
34
36
|
"_": "",
|
35
37
|
"prepublishOnly": "npm run build",
|
36
38
|
"publish:patch": "npm version patch && npm publish",
|