@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.
Files changed (64) hide show
  1. package/README.md +242 -187
  2. package/README.old.md +342 -0
  3. package/build/base/merged-state.d.ts +1 -0
  4. package/build/base/merged-state.js +3 -2
  5. package/build/base/methods.d.ts +40 -7
  6. package/build/base/methods.js +45 -81
  7. package/build/base/state/class-types.d.ts +17 -0
  8. package/build/base/state/class-types.js +2 -0
  9. package/build/base/state/class.d.ts +14 -0
  10. package/build/base/{state.js → state/class.js} +4 -55
  11. package/build/base/state/hook-types.d.ts +11 -0
  12. package/build/base/state/hook-types.js +2 -0
  13. package/build/base/state/hooks.d.ts +11 -0
  14. package/build/base/state/hooks.js +57 -0
  15. package/build/base/state/index.d.ts +4 -0
  16. package/build/base/state/index.js +9 -0
  17. package/build/classy/class/index.d.ts +102 -0
  18. package/build/classy/class/index.js +147 -0
  19. package/build/classy/class/types/class/instance.d.ts +12 -0
  20. package/build/classy/class/types/class/instance.js +2 -0
  21. package/build/classy/class/types/class/static.d.ts +9 -0
  22. package/build/classy/class/types/class/static.js +12 -0
  23. package/build/classy/class/types/extractor.d.ts +6 -0
  24. package/build/classy/class/types/extractor.js +2 -0
  25. package/build/classy/class/utils/function-name.d.ts +2 -0
  26. package/build/classy/class/utils/function-name.js +17 -0
  27. package/build/classy/class/utils/rerender.d.ts +1 -0
  28. package/build/classy/class/utils/rerender.js +11 -0
  29. package/build/classy/class/utils/use-component/index.d.ts +6 -0
  30. package/build/classy/class/utils/use-component/index.js +17 -0
  31. package/build/classy/class/utils/use-component/types.d.ts +22 -0
  32. package/build/classy/class/utils/use-component/types.js +2 -0
  33. package/build/classy/instance/index.d.ts +94 -0
  34. package/build/classy/{instance.js → instance/index.js} +62 -33
  35. package/build/classy/instance/mount-callbacks.d.ts +4 -0
  36. package/build/classy/instance/mount-callbacks.js +30 -0
  37. package/build/classy/instance/types/hook.d.ts +16 -0
  38. package/build/classy/instance/types/hook.js +2 -0
  39. package/build/classy/instance/types/instance.d.ts +11 -0
  40. package/build/classy/instance/types/instance.js +2 -0
  41. package/build/classy/instance/types/static.d.ts +11 -0
  42. package/build/classy/instance/types/static.js +17 -0
  43. package/build/classy/logic/index.d.ts +42 -0
  44. package/build/classy/logic/index.js +122 -0
  45. package/build/classy/logic/types/hook.d.ts +24 -0
  46. package/build/classy/logic/types/hook.js +2 -0
  47. package/build/classy/logic/types/instance.d.ts +18 -0
  48. package/build/classy/logic/types/instance.js +2 -0
  49. package/build/classy/logic/types/static.d.ts +17 -0
  50. package/build/classy/logic/types/static.js +2 -0
  51. package/build/globals.d.ts +23 -33
  52. package/build/globals.js +2 -20
  53. package/build/index.d.ts +1 -1
  54. package/build/index.js +2 -1
  55. package/build/tsconfig.json +3 -0
  56. package/package.json +8 -6
  57. package/build/base/state.d.ts +0 -29
  58. package/build/classy/class.d.ts +0 -22
  59. package/build/classy/class.js +0 -118
  60. package/build/classy/instance.d.ts +0 -60
  61. package/build/classy/logic.d.ts +0 -20
  62. package/build/classy/logic.js +0 -79
  63. package/build/globals.private.d.ts +0 -44
  64. package/build/globals.private.js +0 -34
@@ -1,29 +0,0 @@
1
- /**
2
- * Returns a value that is false before the component has been mounted,
3
- * then true during all subsequent rerenders.
4
- */
5
- export declare const useMountState: () => boolean;
6
- type PutState<TState extends object> = {
7
- [Key in keyof TState]: React.Dispatch<React.SetStateAction<TState[Key]>>;
8
- };
9
- declare class CleanStateBase<TState extends Record<string, any>> {
10
- reservedKeys: string[];
11
- valueKeys: string[];
12
- private _values_;
13
- private _initialValues_;
14
- private _setters_;
15
- constructor(initialState: TState);
16
- static update: <TState_1 extends object>(this: CleanStateBase<TState_1>) => void;
17
- get put(): PutState<TState>;
18
- get initialState(): TState;
19
- putMany: (newValues: Partial<TState>) => void;
20
- }
21
- type TCleanStateInstance<TState extends object> = TState & CleanStateBase<TState>;
22
- export type TCleanState<TState extends object> = TCleanStateInstance<TState>;
23
- export type TState<YourCleanState extends CleanStateBase<{}>> = Omit<YourCleanState, keyof CleanStateBase<{}>>;
24
- type StateInitFunction = (...args: any[]) => object;
25
- type StateInit = object | StateInitFunction;
26
- type TInitialState<Initializer extends StateInit> = Initializer extends (...args: any[]) => (infer TState extends object) ? TState : Initializer;
27
- type TUseCleanState = <TInit extends StateInit>(_initialState: TInit, ...props: TInit extends (...args: infer TProps extends any[]) => (infer TState extends object) ? TProps : []) => TCleanStateInstance<TInitialState<TInit>>;
28
- export declare const useCleanState: TUseCleanState;
29
- export {};
@@ -1,22 +0,0 @@
1
- import type { VoidFunctionComponent } from 'react';
2
- import type { IComponentInstanceClass } from './instance';
3
- import { ComponentInstance } from './instance';
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']>;
9
- export declare class ClassComponent<TProps extends o = EmptyObject, TState extends o = EmptyObject, THooks extends o = EmptyObject> extends ComponentInstance<TProps, TState, THooks> {
10
- Render: VoidFunctionComponent<{}>;
11
- readonly forceUpdate: VoidFunction;
12
- static renderAs: 'component' | 'template';
13
- static readonly FC: Extractor;
14
- }
15
- interface HookWrapperProps<THookFunction extends AnyFunction> {
16
- hook: THookFunction;
17
- argumentsList: Parameters<THookFunction>;
18
- onUpdate: (output: ReturnType<THookFunction>) => void;
19
- }
20
- type ClassComponentHookWrapper = <Hook extends AnyFunction>(props: HookWrapperProps<Hook>) => null;
21
- export declare const Use: ClassComponentHookWrapper;
22
- export {};
@@ -1,118 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.Use = exports.ClassComponent = void 0;
19
- var jsx_runtime_1 = require("react/jsx-runtime");
20
- var react_1 = require("react");
21
- var instance_1 = require("./instance");
22
- /** Provide more useful stack traces for otherwise non-specific function names. */
23
- var setFunctionName = function (func, newName) {
24
- try {
25
- // Must use try block, as `name` is not configurable on older browsers, and may yield a TypeError.
26
- Object.defineProperty(func, 'name', {
27
- writable: true,
28
- value: newName,
29
- });
30
- }
31
- catch (error) {
32
- console.warn(error);
33
- }
34
- };
35
- var useRerender = function () {
36
- /*
37
- * Skip the value, we don't need it.
38
- * Grab just the setter function.
39
- */
40
- var _a = (0, react_1.useState)(Date.now()), _forceRerender = _a[1];
41
- var rerender = function () { return _forceRerender(Date.now()); };
42
- return rerender;
43
- };
44
- ;
45
- var ClassComponent = /** @class */ (function (_super) {
46
- __extends(ClassComponent, _super);
47
- function ClassComponent() {
48
- return _super !== null && _super.apply(this, arguments) || this;
49
- }
50
- ClassComponent.renderAs = 'component';
51
- ClassComponent.FC = function FC(_Component) {
52
- var Component = _Component !== null && _Component !== void 0 ? _Component : this;
53
- var isClassComponentType = Component.prototype instanceof ClassComponent;
54
- if (!Component.getInitialState || !isClassComponentType)
55
- throw new Error('Attempted to initialize ClassComponent with invalid Class type. Either pass a class that extends ClassComponent to FC (e.g `export FC(MyComponent);`), or ensure it is called as a method on a ClassComponent constructor type (e.g `export MyComponent.FC()`).');
56
- var Wrapper = function (props, context) {
57
- var instance = (0, instance_1.useInstance)(Component, props);
58
- var Render = instance.Render;
59
- var _forceUpdate;
60
- // @ts-expect-error (Cannot assign to 'forceUpdate' because it is a read-only property.ts(2540))
61
- instance.forceUpdate = (_forceUpdate = useRerender() // Moved this to separate line to allow TS errors. Use proxy local variable to regain some type checking for the assignment.
62
- );
63
- // Add calling component name to Render function name in stack traces.
64
- (0, react_1.useMemo)(function () { return setFunctionName(Render, "".concat(Component.name, ".Render")); }, [Render]);
65
- /**
66
- * Normally a component can update it's own state in the "before-render" stage to
67
- * skip DOM updates and trigger and immediate rerun of the rendering with the new state.
68
- *
69
- * It may be impossible to do this within the body of Render, if we call it as JSX here,
70
- * since technically, the Wrapper component owns the state and not the Render component.
71
- * Using it as JSX establishes a component boundary, and React will throw an error if we try to set
72
- * state in the "before-render" stage of `Render`, since it will be attempting to update it's parent's
73
- * state (i.e `Wrapper` component) rather than it's own state.
74
- *
75
- * Consider using this as a function call instead of JSX to avoid that. This way, we avoid
76
- * establishing a component boundary between `Wrapper` and `Render`.
77
- *
78
- * Although, since beforeRender() is called earlier from a hook, this is probably
79
- * a non-issue. It will only force users to move their logic into `beforeRender` instead
80
- * of doing it directly in `Render`. This might mean cleaner Render functions,
81
- * so there's probably no real value lost if we keep the component boundary.
82
- **/
83
- if (Component.renderAs === 'template')
84
- return Render({}, context);
85
- // With the existence of useContext(),
86
- // what exactly does the context argument to FunctionComponent represent?
87
- // Do we need to find a way to pass that context value to <Render /> here?
88
- return (0, jsx_runtime_1.jsx)(Render, {});
89
- };
90
- // Include calling component name in wrapper function name on stack traces.
91
- setFunctionName(Wrapper, "".concat(Component.name, " < Wrapper")); // ${Wrapper.name}
92
- return Wrapper;
93
- };
94
- return ClassComponent;
95
- }(instance_1.ComponentInstance));
96
- exports.ClassComponent = ClassComponent;
97
- var Use = function (params) {
98
- var useGenericHook = params.hook, argumentsList = params.argumentsList, onUpdate = params.onUpdate;
99
- var output = useGenericHook.apply(void 0, argumentsList);
100
- (0, react_1.useEffect)(function () {
101
- onUpdate(output);
102
- }, [output]);
103
- return null;
104
- };
105
- exports.Use = Use;
106
- testing: {
107
- var a = { b: '' };
108
- var MyComponentLogic = /** @class */ (function (_super) {
109
- __extends(MyComponentLogic, _super);
110
- function MyComponentLogic() {
111
- return _super !== null && _super.apply(this, arguments) || this;
112
- }
113
- MyComponentLogic.getInitialState = function () { return ({ a: '' }); };
114
- return MyComponentLogic;
115
- }(ClassComponent));
116
- ;
117
- var Template = MyComponentLogic.FC();
118
- }
@@ -1,60 +0,0 @@
1
- import { ComponentLogic, IComponentLogicClass } from './logic';
2
- type AsyncAllowedEffectCallback = () => Awaitable<IVoidFunction>;
3
- type UseMountCallbacks = <TInstance extends ComponentInstance<any, any, any>>(instance: TInstance) => void;
4
- export declare const useMountCallbacks: UseMountCallbacks;
5
- export declare const noOp: () => void;
6
- export declare class ComponentInstance<TProps extends o = EmptyObject, TState extends o = EmptyObject, THooks extends o = EmptyObject> extends ComponentLogic<TProps, TState, THooks> {
7
- /**
8
- * Runs only _before_ first render, i.e before the component instance is mounted.
9
- * Useful for logic that is involved in determining what to render.
10
- *
11
- * Updating local state from in here will abort the render cycle early, before changes are committed to the DOM,
12
- * and prompt React to immediately rerender the component with the updated state value(s).
13
- *
14
- * Ignored on subsequent rerenders.
15
- */
16
- beforeMount: IVoidFunction;
17
- /**
18
- * Runs only **_after_** first render, i.e after the component instance is mounted.
19
- *
20
- * Should usually only be used for logic that does not directly take part in determining what to render, like
21
- * synchronize your component with some external system.
22
- *
23
- * Ignored on subsequent rerenders.
24
- *
25
- * Returns a cleanup function.
26
- */
27
- onMount: AsyncAllowedEffectCallback;
28
- /**
29
- * Runs _before_ every render cycle, including the first.
30
- * Useful for logic that is involved in determining what to render.
31
- *
32
- * Updating local state from in here will abort the render cycle early, before changes are committed to the DOM,
33
- * and prompt React to immediately rerender the component with the updated state value(s).
34
- */
35
- beforeRender: IVoidFunction;
36
- /**
37
- * Runs **_after_** every render cycle, including the first.
38
- *
39
- * Should usually only be used for logic that does not directly take part in determining what to render, like
40
- * synchronize your component with some external system.
41
- *
42
- * Returns a cleanup function.
43
- */
44
- onRender: AsyncAllowedEffectCallback;
45
- /**
46
- * Runs when the component is unmounted.
47
- * It is called _after_ the cleanup function returned by onMount.
48
- */
49
- cleanUp: IVoidFunction;
50
- }
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 UseInstance2 = {
56
- <Class extends typeof ComponentInstance<EmptyObject, o, o>>(Methods: Class & IComponentInstanceClass<InstanceType<Class>>, ...props: ([] | [EmptyObject])): InstanceType<Class>;
57
- <Class extends typeof ComponentInstance<o, o, o>>(Methods: Class & IComponentInstanceClass<InstanceType<Class>>, ...props: [InstanceType<Class>['props']]): InstanceType<Class>;
58
- };
59
- export declare const useInstance: UseInstance2;
60
- export {};
@@ -1,20 +0,0 @@
1
- import type { TCleanState, TState } from '../base/state';
2
- export type Empty = EmptyObject;
3
- type o = object;
4
- export declare class ComponentLogic<TProps extends o = Empty, TState extends o = Empty, THooks extends o = Empty> {
5
- state: TCleanState<TState>;
6
- props: TProps;
7
- hooks: THooks;
8
- static getInitialState: (p?: o) => {};
9
- useHooks?: () => THooks;
10
- }
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
- getInitialState: (props?: Instance['props']) => TState<Instance['state']>;
14
- }
15
- type UseLogic2 = {
16
- <Class extends typeof ComponentLogic<Empty, o, o>>(Methods: Class & IComponentLogicClass<InstanceType<Class>>, ...props: ([] | [EmptyObject])): InstanceType<Class>;
17
- <Class extends typeof ComponentLogic<o, o, o>>(Methods: Class & IComponentLogicClass<InstanceType<Class>>, ...props: [InstanceType<Class>['props']]): InstanceType<Class>;
18
- };
19
- declare const useLogic: UseLogic2;
20
- export { useLogic };
@@ -1,79 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.useLogic = exports.ComponentLogic = void 0;
19
- var react_1 = require("react");
20
- var state_1 = require("../base/state");
21
- var ComponentLogic = /** @class */ (function () {
22
- function ComponentLogic() {
23
- }
24
- ComponentLogic.getInitialState = function (p) { return ({}); };
25
- return ComponentLogic;
26
- }());
27
- exports.ComponentLogic = ComponentLogic;
28
- ;
29
- var useLogic = function () {
30
- var _a, _b;
31
- var args = [];
32
- for (var _i = 0; _i < arguments.length; _i++) {
33
- args[_i] = arguments[_i];
34
- }
35
- var Methods = args[0], _c = args[1], props = _c === void 0 ? {} : _c;
36
- var state = (0, state_1.useCleanState)(Methods.getInitialState, props);
37
- var methods = (0, react_1.useRef)((0, react_1.useMemo)(function () {
38
- return new Methods();
39
- }, [])).current;
40
- methods.state = state;
41
- methods.props = props;
42
- methods.hooks = (_b = (_a = methods.useHooks) === null || _a === void 0 ? void 0 : _a.call(methods)) !== null && _b !== void 0 ? _b : {};
43
- return methods;
44
- };
45
- exports.useLogic = useLogic;
46
- testing: {
47
- var a = { b: '' };
48
- var MyComponentLogic = /** @class */ (function (_super) {
49
- __extends(MyComponentLogic, _super);
50
- function MyComponentLogic() {
51
- var _this = _super !== null && _super.apply(this, arguments) || this;
52
- _this.b = _this.state.a;
53
- return _this;
54
- }
55
- MyComponentLogic.getInitialState = function (p) { return ({ a: '' }); };
56
- return MyComponentLogic;
57
- }(ComponentLogic));
58
- ;
59
- MyComponentLogic.getInitialState;
60
- var self_1 = useLogic(MyComponentLogic);
61
- }
62
- testing: {
63
- var A = /** @class */ (function (_super) {
64
- __extends(C, _super);
65
- function C() {
66
- return _super !== null && _super.apply(this, arguments) || this;
67
- }
68
- return C;
69
- }(ComponentLogic));
70
- A.getInitialState();
71
- var self_2 = useLogic(A, { a: 'boo' });
72
- }
73
- // export type ComponentClassStatics<Instance extends ComponentLogic<object, object, object>> = {
74
- // getInitialState: (props?: Instance['props']) => TState<Instance['state']>;
75
- // }
76
- // export type TComponentClass<
77
- // Instance extends ComponentLogic<object, object, object>,
78
- // Params extends CnstPrm = CnstPrm
79
- // > = ComponentClassStatics<Instance> & Constructor<Instance, Params>;
@@ -1,44 +0,0 @@
1
- /**
2
- * @file
3
- * This file is created specifically to augment the declarations in
4
- * [globals.d.ts]({@link ./globals.d.ts}).
5
- *
6
- * **You should not import this file directly.**
7
- */
8
- /** */
9
- declare const UniqueSecretSymbolKey: unique symbol;
10
- declare class CEmptyObject2 {
11
- [UniqueSecretSymbolKey]?: never;
12
- }
13
- declare class CEmptyObject3 {
14
- /**
15
- * It appears keys of the base `symbol` type are excluded from
16
- * excess property checks. This is likely a bug in TypeScript.
17
- * Even the "has no properties in common" error disappears if the
18
- * value being placed into a variable has a key typed as `symbol`.
19
- * This only applies to the base `symbol` type. Specifc `'unique symbol'`
20
- * types are unaffected.
21
- *
22
- * @example
23
- * // Consider the following object:
24
- * const myUniqueSymbol = Symbol('lkjhgfc');
25
- * let myObj = { [myUniqueSymbol]?: 'a string value' };
26
- *
27
- * // We can attempt to reassign `myObj` with the expectation that TS will
28
- * // warn if any key other than `myUniqueSymbol` is used in the new object.
29
- * // But this breaks in one specific scenario.
30
- *
31
- * // No excess property check when this is used as a key.
32
- * // Error "no properties in common" also suppressed when this is used as a key.
33
- * const differentBasicSymbol = Symbol('qwertiop[') as symbol;
34
- * myObj = { [differentBasicSymbol]: 5 };
35
- *
36
- * // Errors emitted as expected when this is used as a key.
37
- * const differentUniqueSymbol = Symbol('zxcvbnm');
38
- * myObj = { [differentUniqueSymbol]: 5 };
39
- */
40
- [key: symbol]: never;
41
- }
42
- export declare const EmptyObject2: CEmptyObject2;
43
- export declare const EmptyObject3: CEmptyObject3;
44
- export {};
@@ -1,34 +0,0 @@
1
- "use strict";
2
- /**
3
- * @file
4
- * This file is created specifically to augment the declarations in
5
- * [globals.d.ts]({@link ./globals.d.ts}).
6
- *
7
- * **You should not import this file directly.**
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.EmptyObject3 = exports.EmptyObject2 = void 0;
11
- /** */
12
- var UniqueSecretSymbolKey = Symbol('asdfghjkliuytrewqaxcvb,nb');
13
- var CEmptyObject2 = /** @class */ (function () {
14
- function CEmptyObject2() {
15
- }
16
- return CEmptyObject2;
17
- }());
18
- var CEmptyObject3 = /** @class */ (function () {
19
- function CEmptyObject3() {
20
- }
21
- return CEmptyObject3;
22
- }());
23
- exports.EmptyObject2 = new CEmptyObject2();
24
- exports.EmptyObject3 = new CEmptyObject3();
25
- testing: {
26
- var mySymbol = Symbol('asdfgh');
27
- var tt = {
28
- // [mySymbol]: '' as never,
29
- // [UniqueSecretSymbolKey]: '',
30
- // '': '',
31
- };
32
- var TT = new CEmptyObject2();
33
- TT = tt;
34
- }