@cleanweb/react 1.1.1-beta.2 → 1.1.1-beta.4
Sign up to get free protection for your applications and to get access to all the features.
- package/build/base/methods.d.ts +2 -1
- package/build/classy/class.d.ts +7 -2
- package/build/classy/class.js +13 -1
- package/build/classy/instance.d.ts +8 -13
- package/build/classy/instance.js +28 -28
- package/build/classy/logic.d.ts +8 -13
- package/build/classy/logic.js +25 -15
- package/build/globals.d.ts +3 -1
- package/build/globals.private.d.ts +0 -4
- package/build/globals.private.js +2 -8
- package/build/tsconfig.json +1 -1
- package/package.json +1 -1
package/build/base/methods.d.ts
CHANGED
@@ -3,6 +3,7 @@ export declare class ComponentMethods<TState extends object, TProps extends obje
|
|
3
3
|
state: TCleanState<TState>;
|
4
4
|
props: TProps;
|
5
5
|
}
|
6
|
-
type UseMethods = <
|
6
|
+
type UseMethods = <Class extends TypeofClass & Constructor<InstanceType<TypeofClass>>, // = TMethods & Cons,
|
7
|
+
TypeofClass extends typeof ComponentMethods<object, object>>(Methods: Class, state: InstanceType<Class>['state'], props: InstanceType<Class>['props']) => InstanceType<Class>;
|
7
8
|
export declare const useMethods: UseMethods;
|
8
9
|
export {};
|
package/build/classy/class.d.ts
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
import type { VoidFunctionComponent } from 'react';
|
2
|
+
import type { IComponentInstanceClass } from './instance';
|
2
3
|
import { ComponentInstance } from './instance';
|
3
|
-
type
|
4
|
+
type ComponentClassParams = ConstructorParameters<typeof ClassComponent>;
|
5
|
+
type o = object;
|
6
|
+
export interface IComponentClass<Instance extends ClassComponent<o, o, o> = ClassComponent, Params extends ComponentClassParams = ComponentClassParams> extends IComponentInstanceClass<Instance, Params> {
|
7
|
+
}
|
8
|
+
type Extractor = <TComponent extends typeof ClassComponent<o, o, o>>(this: NonNullable<typeof _Component>, _Component?: TComponent & IComponentClass<InstanceType<TComponent>>) => VoidFunctionComponent<InstanceType<TComponent>['props']>;
|
4
9
|
export declare class ClassComponent<TState extends object = EmptyObject, TProps extends object = EmptyObject, THooks extends object = EmptyObject> extends ComponentInstance<TState, TProps, THooks> {
|
5
10
|
Render: VoidFunctionComponent<{}>;
|
6
11
|
static renderAs: 'component' | 'template';
|
7
|
-
static FC: Extractor;
|
12
|
+
static readonly FC: Extractor;
|
8
13
|
}
|
9
14
|
interface HookWrapperProps<THookFunction extends AnyFunction> {
|
10
15
|
hook: THookFunction;
|
package/build/classy/class.js
CHANGED
@@ -32,7 +32,7 @@ var setFunctionName = function (func, newName) {
|
|
32
32
|
console.warn(error);
|
33
33
|
}
|
34
34
|
};
|
35
|
-
|
35
|
+
;
|
36
36
|
var ClassComponent = /** @class */ (function (_super) {
|
37
37
|
__extends(ClassComponent, _super);
|
38
38
|
function ClassComponent() {
|
@@ -89,3 +89,15 @@ var Use = function (params) {
|
|
89
89
|
return null;
|
90
90
|
};
|
91
91
|
exports.Use = Use;
|
92
|
+
testing: {
|
93
|
+
var a = { b: '' };
|
94
|
+
var MyComponentLogic = /** @class */ (function (_super) {
|
95
|
+
__extends(MyComponentLogic, _super);
|
96
|
+
function MyComponentLogic() {
|
97
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
98
|
+
}
|
99
|
+
MyComponentLogic.getInitialState = function () { return ({}); };
|
100
|
+
return MyComponentLogic;
|
101
|
+
}(ClassComponent));
|
102
|
+
;
|
103
|
+
}
|
@@ -1,5 +1,7 @@
|
|
1
|
-
import { ComponentLogic } from './logic';
|
1
|
+
import { ComponentLogic, IComponentLogicClass } from './logic';
|
2
2
|
type AsyncAllowedEffectCallback = () => Awaitable<IVoidFunction>;
|
3
|
+
type UseMountCallbacks = <TInstance extends ComponentInstance<any, any, any>>(instance: TInstance) => void;
|
4
|
+
export declare const useMountCallbacks: UseMountCallbacks;
|
3
5
|
export declare const noOp: () => void;
|
4
6
|
export declare class ComponentInstance<TState extends object = EmptyObject, TProps extends object = EmptyObject, THooks extends object = EmptyObject> extends ComponentLogic<TState, TProps, THooks> {
|
5
7
|
/**
|
@@ -46,17 +48,10 @@ export declare class ComponentInstance<TState extends object = EmptyObject, TPro
|
|
46
48
|
*/
|
47
49
|
cleanUp: IVoidFunction;
|
48
50
|
}
|
49
|
-
type
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
* retrieve the second argument directly causes an error when that argument is passed on to `useLogic`.
|
55
|
-
* But directly working with the rest array bypasses the problem. Also note that the issue persists even when
|
56
|
-
* the second param is given `{}` as a default follow to account for the empty tuple case. TypeScript
|
57
|
-
* just wants us to use the rest parameter explicitly by force.
|
58
|
-
*/
|
51
|
+
type o = object;
|
52
|
+
type InstanceClassParams = ConstructorParameters<typeof ComponentInstance<o, o, o>>;
|
53
|
+
export interface IComponentInstanceClass<Instance extends ComponentInstance<o, o, o> = ComponentInstance, Params extends InstanceClassParams = InstanceClassParams> extends IComponentLogicClass<Instance, Params> {
|
54
|
+
}
|
55
|
+
type UseInstance = <TClass extends typeof ComponentInstance<object, object, object>>(Class: TClass & IComponentInstanceClass<InstanceType<TClass>>, ...props: valueof<InstanceType<TClass>['props']> extends never ? ([] | [EmptyObject] | [InstanceType<TClass>['props']]) : [InstanceType<TClass>['props']]) => InstanceType<TClass>;
|
59
56
|
export declare const useInstance: UseInstance;
|
60
|
-
type UseMountCallbacks = <TInstance extends ComponentInstance<any, any, any>>(instance: TInstance) => void;
|
61
|
-
export declare const useMountCallbacks: UseMountCallbacks;
|
62
57
|
export {};
|
package/build/classy/instance.js
CHANGED
@@ -24,10 +24,35 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
24
24
|
return to.concat(ar || Array.prototype.slice.call(from));
|
25
25
|
};
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
27
|
-
exports.
|
27
|
+
exports.useInstance = exports.ComponentInstance = exports.noOp = exports.useMountCallbacks = void 0;
|
28
28
|
var react_1 = require("react");
|
29
29
|
var state_1 = require("../base/state");
|
30
30
|
var logic_1 = require("./logic");
|
31
|
+
var useMountCallbacks = function (instance) {
|
32
|
+
var _a;
|
33
|
+
var mounted = (0, state_1.useMountState)();
|
34
|
+
if (!mounted)
|
35
|
+
(_a = instance.beforeMount) === null || _a === void 0 ? void 0 : _a.call(instance);
|
36
|
+
(0, react_1.useEffect)(function () {
|
37
|
+
var _a;
|
38
|
+
var mountHandlerCleanUp = (_a = instance.onMount) === null || _a === void 0 ? void 0 : _a.call(instance);
|
39
|
+
return function () {
|
40
|
+
var doCleanUp = function (runMountCleaners) {
|
41
|
+
var _a;
|
42
|
+
runMountCleaners === null || runMountCleaners === void 0 ? void 0 : runMountCleaners();
|
43
|
+
// onDismount? willUnmount?
|
44
|
+
(_a = instance.cleanUp) === null || _a === void 0 ? void 0 : _a.call(instance);
|
45
|
+
};
|
46
|
+
if (typeof mountHandlerCleanUp === 'function') {
|
47
|
+
doCleanUp(mountHandlerCleanUp);
|
48
|
+
}
|
49
|
+
else {
|
50
|
+
mountHandlerCleanUp === null || mountHandlerCleanUp === void 0 ? void 0 : mountHandlerCleanUp.then(doCleanUp);
|
51
|
+
}
|
52
|
+
};
|
53
|
+
}, []);
|
54
|
+
};
|
55
|
+
exports.useMountCallbacks = useMountCallbacks;
|
31
56
|
var noOp = function () { };
|
32
57
|
exports.noOp = noOp;
|
33
58
|
var ComponentInstance = /** @class */ (function (_super) {
|
@@ -83,7 +108,8 @@ var ComponentInstance = /** @class */ (function (_super) {
|
|
83
108
|
}(logic_1.ComponentLogic));
|
84
109
|
exports.ComponentInstance = ComponentInstance;
|
85
110
|
;
|
86
|
-
|
111
|
+
;
|
112
|
+
/*
|
87
113
|
* To ensure successful type checking, the second parameter must be written with spread syntax.
|
88
114
|
* Likely because of the `exactOptionalPropertyTypes` config option turned on,
|
89
115
|
* and `UseInstance` using an empty tuple in its rest parameter type, attempting to simply
|
@@ -115,7 +141,6 @@ var useInstance = function (Component) {
|
|
115
141
|
'
|
116
142
|
*/
|
117
143
|
// beforeMount, onMount, cleanUp.
|
118
|
-
// eslint-disable-next-line no-use-before-define
|
119
144
|
(0, exports.useMountCallbacks)(instance);
|
120
145
|
// beforeRender.
|
121
146
|
(_a = instance.beforeRender) === null || _a === void 0 ? void 0 : _a.call(instance);
|
@@ -133,28 +158,3 @@ var useInstance = function (Component) {
|
|
133
158
|
return instance;
|
134
159
|
};
|
135
160
|
exports.useInstance = useInstance;
|
136
|
-
var useMountCallbacks = function (instance) {
|
137
|
-
var _a;
|
138
|
-
var mounted = (0, state_1.useMountState)();
|
139
|
-
if (!mounted)
|
140
|
-
(_a = instance.beforeMount) === null || _a === void 0 ? void 0 : _a.call(instance);
|
141
|
-
(0, react_1.useEffect)(function () {
|
142
|
-
var _a;
|
143
|
-
var mountHandlerCleanUp = (_a = instance.onMount) === null || _a === void 0 ? void 0 : _a.call(instance);
|
144
|
-
return function () {
|
145
|
-
var doCleanUp = function (runMountCleaners) {
|
146
|
-
var _a;
|
147
|
-
runMountCleaners === null || runMountCleaners === void 0 ? void 0 : runMountCleaners();
|
148
|
-
// onDismount? willUnmount?
|
149
|
-
(_a = instance.cleanUp) === null || _a === void 0 ? void 0 : _a.call(instance);
|
150
|
-
};
|
151
|
-
if (typeof mountHandlerCleanUp === 'function') {
|
152
|
-
doCleanUp(mountHandlerCleanUp);
|
153
|
-
}
|
154
|
-
else {
|
155
|
-
mountHandlerCleanUp === null || mountHandlerCleanUp === void 0 ? void 0 : mountHandlerCleanUp.then(doCleanUp);
|
156
|
-
}
|
157
|
-
};
|
158
|
-
}, []);
|
159
|
-
};
|
160
|
-
exports.useMountCallbacks = useMountCallbacks;
|
package/build/classy/logic.d.ts
CHANGED
@@ -1,23 +1,18 @@
|
|
1
1
|
import type { TCleanState, TState } from '../base/state';
|
2
|
+
export type Empty = EmptyObject;
|
2
3
|
type o = object;
|
3
|
-
export declare class ComponentLogic<
|
4
|
-
state: TCleanState<
|
4
|
+
export declare class ComponentLogic<TState extends o = Empty, TProps extends o = Empty, THooks extends o = Empty> {
|
5
|
+
state: TCleanState<TState>;
|
5
6
|
props: TProps;
|
6
7
|
hooks: THooks;
|
7
|
-
static getInitialState:
|
8
|
+
static getInitialState: TBaseComponentLogic['getInitialState'];
|
8
9
|
useHooks?: () => THooks;
|
9
10
|
}
|
10
|
-
type
|
11
|
-
export interface
|
12
|
-
new (...params: CnstPrm): Instance;
|
11
|
+
type LogicClassParams = ConstructorParameters<typeof ComponentLogic>;
|
12
|
+
export interface IComponentLogicClass<Instance extends ComponentLogic<o, o, o> = ComponentLogic, Params extends LogicClassParams = LogicClassParams> extends Constructor<Instance, Params> {
|
13
13
|
getInitialState: (props?: Instance['props']) => TState<Instance['state']>;
|
14
14
|
}
|
15
|
-
export type
|
16
|
-
|
17
|
-
};
|
18
|
-
export type TComponentClass<Instance extends ComponentLogic<object, object, object>, Statics extends ComponentClassStatics<Instance> = ComponentClassStatics<Instance>, Params extends CnstPrm = CnstPrm> = Statics & Constructor<Instance, Params>;
|
19
|
-
export interface IEmpty extends EmptyObject {
|
20
|
-
}
|
21
|
-
type UseLogic = <Class extends typeof ComponentLogic<object, object, object>, Instance extends InstanceType<Class> = InstanceType<Class>>(Methods: Class & Constructor<Instance>, ...props: valueof<Instance['props']> extends never ? ([] | [EmptyObject] | [Instance['props']]) : [Instance['props']]) => Instance;
|
15
|
+
export type TBaseComponentLogic = IComponentLogicClass<ComponentLogic<any, any, any>>;
|
16
|
+
type UseLogic = <Class extends TypeofClass & IComponentLogicClass<InstanceType<TypeofClass>>, TypeofClass extends typeof ComponentLogic<o, o, o>>(Methods: Class, ...props: valueof<InstanceType<Class>['props']> extends never ? ([] | [EmptyObject] | [InstanceType<Class>['props']]) : [InstanceType<Class>['props']]) => InstanceType<Class>;
|
22
17
|
export declare const useLogic: UseLogic;
|
23
18
|
export {};
|
package/build/classy/logic.js
CHANGED
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.useLogic = exports.ComponentLogic = void 0;
|
20
20
|
var react_1 = require("react");
|
21
21
|
var state_1 = require("../base/state");
|
22
|
+
// React.Component
|
22
23
|
var ComponentLogic = /** @class */ (function () {
|
23
24
|
function ComponentLogic() {
|
24
25
|
}
|
@@ -26,21 +27,8 @@ var ComponentLogic = /** @class */ (function () {
|
|
26
27
|
}());
|
27
28
|
exports.ComponentLogic = ComponentLogic;
|
28
29
|
;
|
29
|
-
testing: {
|
30
|
-
var A = (_a = /** @class */ (function (_super) {
|
31
|
-
__extends(C, _super);
|
32
|
-
function C() {
|
33
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
34
|
-
}
|
35
|
-
return C;
|
36
|
-
}(ComponentLogic)),
|
37
|
-
_a.getInitialState = function () { return ({}); },
|
38
|
-
_a);
|
39
|
-
A.getInitialState();
|
40
|
-
}
|
41
|
-
;
|
42
30
|
var useLogic = function (Methods, props) {
|
43
|
-
var _b;
|
31
|
+
var _b, _c;
|
44
32
|
if (props === void 0) { props = {}; }
|
45
33
|
var state = (0, state_1.useCleanState)(Methods.getInitialState, props);
|
46
34
|
var methods = (0, react_1.useRef)((0, react_1.useMemo)(function () {
|
@@ -48,7 +36,7 @@ var useLogic = function (Methods, props) {
|
|
48
36
|
}, [])).current;
|
49
37
|
methods.state = state;
|
50
38
|
methods.props = props;
|
51
|
-
methods.hooks = ((_b = methods.useHooks) === null || _b === void 0 ? void 0 : _b.call(methods))
|
39
|
+
methods.hooks = (_c = (_b = methods.useHooks) === null || _b === void 0 ? void 0 : _b.call(methods)) !== null && _c !== void 0 ? _c : {};
|
52
40
|
return methods;
|
53
41
|
};
|
54
42
|
exports.useLogic = useLogic;
|
@@ -65,3 +53,25 @@ testing: {
|
|
65
53
|
;
|
66
54
|
var self_1 = (0, exports.useLogic)(MyComponentLogic);
|
67
55
|
}
|
56
|
+
testing: {
|
57
|
+
var A = (_a = /** @class */ (function (_super) {
|
58
|
+
__extends(C, _super);
|
59
|
+
function C() {
|
60
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
61
|
+
_this.b = _this.state.a;
|
62
|
+
return _this;
|
63
|
+
}
|
64
|
+
return C;
|
65
|
+
}(ComponentLogic)),
|
66
|
+
_a.getInitialState = function () { return ({ a: 'l' }); },
|
67
|
+
_a);
|
68
|
+
A.getInitialState();
|
69
|
+
// const self = useLogic(A);
|
70
|
+
}
|
71
|
+
// export type ComponentClassStatics<Instance extends ComponentLogic<object, object, object>> = {
|
72
|
+
// getInitialState: (props?: Instance['props']) => TState<Instance['state']>;
|
73
|
+
// }
|
74
|
+
// export type TComponentClass<
|
75
|
+
// Instance extends ComponentLogic<object, object, object>,
|
76
|
+
// Params extends CnstPrm = CnstPrm
|
77
|
+
// > = ComponentClassStatics<Instance> & Constructor<Instance, Params>;
|
package/build/globals.d.ts
CHANGED
@@ -57,7 +57,9 @@ declare global {
|
|
57
57
|
''?: never;
|
58
58
|
};
|
59
59
|
type TEmptyObject2 = Record<symbol, never>;
|
60
|
-
type EmptyObject =
|
60
|
+
type EmptyObject = {
|
61
|
+
[key: keyof any]: never;
|
62
|
+
};
|
61
63
|
type EmptyObject2 = __FromPrivateHelpers['EmptyObject2'];
|
62
64
|
type EmptyObject3 = __FromPrivateHelpers['EmptyObject3'];
|
63
65
|
type valueof<TObject> = TObject[keyof TObject];
|
@@ -7,9 +7,6 @@
|
|
7
7
|
*/
|
8
8
|
/** */
|
9
9
|
declare const UniqueSecretSymbolKey: unique symbol;
|
10
|
-
declare class CEmptyObject {
|
11
|
-
[key: keyof any]: never;
|
12
|
-
}
|
13
10
|
declare class CEmptyObject2 {
|
14
11
|
[UniqueSecretSymbolKey]?: never;
|
15
12
|
}
|
@@ -42,7 +39,6 @@ declare class CEmptyObject3 {
|
|
42
39
|
*/
|
43
40
|
[key: symbol]: never;
|
44
41
|
}
|
45
|
-
export declare const EmptyObject: CEmptyObject;
|
46
42
|
export declare const EmptyObject2: CEmptyObject2;
|
47
43
|
export declare const EmptyObject3: CEmptyObject3;
|
48
44
|
export {};
|
package/build/globals.private.js
CHANGED
@@ -7,14 +7,9 @@
|
|
7
7
|
* **You should not import this file directly.**
|
8
8
|
*/
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
10
|
-
exports.EmptyObject3 = exports.EmptyObject2 =
|
10
|
+
exports.EmptyObject3 = exports.EmptyObject2 = void 0;
|
11
11
|
/** */
|
12
12
|
var UniqueSecretSymbolKey = Symbol('asdfghjkliuytrewqaxcvb,nb');
|
13
|
-
var CEmptyObject = /** @class */ (function () {
|
14
|
-
function CEmptyObject() {
|
15
|
-
}
|
16
|
-
return CEmptyObject;
|
17
|
-
}());
|
18
13
|
var CEmptyObject2 = /** @class */ (function () {
|
19
14
|
function CEmptyObject2() {
|
20
15
|
}
|
@@ -25,7 +20,6 @@ var CEmptyObject3 = /** @class */ (function () {
|
|
25
20
|
}
|
26
21
|
return CEmptyObject3;
|
27
22
|
}());
|
28
|
-
exports.EmptyObject = new CEmptyObject();
|
29
23
|
exports.EmptyObject2 = new CEmptyObject2();
|
30
24
|
exports.EmptyObject3 = new CEmptyObject3();
|
31
25
|
testing: {
|
@@ -35,6 +29,6 @@ testing: {
|
|
35
29
|
// [UniqueSecretSymbolKey]: '',
|
36
30
|
// '': '',
|
37
31
|
};
|
38
|
-
var TT = new
|
32
|
+
var TT = new CEmptyObject2();
|
39
33
|
TT = tt;
|
40
34
|
}
|
package/build/tsconfig.json
CHANGED