@cleanweb/oore 1.0.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 (60) hide show
  1. package/README.md +374 -0
  2. package/README.old.md +342 -0
  3. package/build/base/index.d.ts +3 -0
  4. package/build/base/index.js +19 -0
  5. package/build/base/merged-state.d.ts +20 -0
  6. package/build/base/merged-state.js +84 -0
  7. package/build/base/methods.d.ts +59 -0
  8. package/build/base/methods.js +100 -0
  9. package/build/base/state/class-types.d.ts +20 -0
  10. package/build/base/state/class-types.js +2 -0
  11. package/build/base/state/class.d.ts +16 -0
  12. package/build/base/state/class.js +100 -0
  13. package/build/base/state/hook-types.d.ts +32 -0
  14. package/build/base/state/hook-types.js +2 -0
  15. package/build/base/state/hooks.d.ts +12 -0
  16. package/build/base/state/hooks.js +45 -0
  17. package/build/base/state/index.d.ts +8 -0
  18. package/build/base/state/index.js +35 -0
  19. package/build/classy/class/index.d.ts +115 -0
  20. package/build/classy/class/index.js +161 -0
  21. package/build/classy/class/types/extractor.d.ts +5 -0
  22. package/build/classy/class/types/extractor.js +2 -0
  23. package/build/classy/class/utils/function-name.d.ts +2 -0
  24. package/build/classy/class/utils/function-name.js +17 -0
  25. package/build/classy/index.d.ts +3 -0
  26. package/build/classy/index.js +19 -0
  27. package/build/classy/instance/index.d.ts +144 -0
  28. package/build/classy/instance/index.js +202 -0
  29. package/build/classy/instance/mount-callbacks.d.ts +5 -0
  30. package/build/classy/instance/mount-callbacks.js +30 -0
  31. package/build/classy/instance/types/hook.d.ts +13 -0
  32. package/build/classy/instance/types/hook.js +2 -0
  33. package/build/classy/logic/index.d.ts +116 -0
  34. package/build/classy/logic/index.js +128 -0
  35. package/build/classy/logic/types/hook.d.ts +16 -0
  36. package/build/classy/logic/types/hook.js +2 -0
  37. package/build/docs-src/api/base-classes.d.ts +3 -0
  38. package/build/docs-src/api/base-classes.js +9 -0
  39. package/build/docs-src/api/index.d.ts +13 -0
  40. package/build/docs-src/api/index.js +44 -0
  41. package/build/docs-src/api/references.d.ts +5 -0
  42. package/build/docs-src/api/references.js +31 -0
  43. package/build/globals.d.ts +84 -0
  44. package/build/globals.js +4 -0
  45. package/build/helpers/index.d.ts +13 -0
  46. package/build/helpers/index.js +31 -0
  47. package/build/helpers/mount-state.d.ts +5 -0
  48. package/build/helpers/mount-state.js +25 -0
  49. package/build/helpers/rerender.d.ts +5 -0
  50. package/build/helpers/rerender.js +29 -0
  51. package/build/helpers/type-guards.d.ts +1 -0
  52. package/build/helpers/type-guards.js +8 -0
  53. package/build/helpers/use-component/index.d.ts +6 -0
  54. package/build/helpers/use-component/index.js +17 -0
  55. package/build/helpers/use-component/types.d.ts +22 -0
  56. package/build/helpers/use-component/types.js +2 -0
  57. package/build/index.d.ts +4 -0
  58. package/build/index.js +19 -0
  59. package/build/tsconfig.json +49 -0
  60. package/package.json +87 -0
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.CleanState = exports.CleanStateBase = void 0;
15
+ var react_1 = require("react");
16
+ /** @internal */
17
+ var CleanStateBase = /** @class */ (function () {
18
+ function CleanStateBase(initialState) {
19
+ var _this = this;
20
+ this._values_ = {};
21
+ this._setters_ = {};
22
+ // readonly putMany = (newValues: Partial<TState>) => {
23
+ this.putMany = function (newValues) {
24
+ Object.entries(newValues).forEach(function (entry) {
25
+ var _a = entry, key = _a[0], value = _a[1];
26
+ _this.put[key](value);
27
+ });
28
+ };
29
+ this.reservedKeys = Object.keys(this);
30
+ /**
31
+ * The keys from the initial state object.
32
+ * By capturing and storing the value once, we ensure that any potential changes to the object,
33
+ * or irregularities in the order of keys returned by Object.keys,
34
+ * will not affect the order of subsequent useState calls.
35
+ * Only keys provided on the initial call will be recognized,
36
+ * since CleanState is instantiated only once with useMemo,
37
+ * and they will always be processed in a consistent order during rerenders.
38
+ */
39
+ this.valueKeys = Object.keys(initialState);
40
+ this._initialValues_ = __assign({}, initialState);
41
+ this.valueKeys.forEach(function (key) {
42
+ if (_this.reservedKeys.includes(key))
43
+ throw new Error("The name \"".concat(key, "\" is reserved by CleanState and cannot be used to index state variables. Please use a different key."));
44
+ var self = _this;
45
+ Object.defineProperty(_this, key, {
46
+ get: function () {
47
+ return self._values_[key];
48
+ },
49
+ set: function (value) {
50
+ self._setters_[key](value);
51
+ },
52
+ enumerable: true,
53
+ });
54
+ });
55
+ }
56
+ Object.defineProperty(CleanStateBase.prototype, "put", {
57
+ get: function () {
58
+ return __assign({}, this._setters_);
59
+ },
60
+ enumerable: false,
61
+ configurable: true
62
+ });
63
+ Object.defineProperty(CleanStateBase.prototype, "initialState", {
64
+ get: function () {
65
+ return __assign({}, this._initialValues_);
66
+ },
67
+ enumerable: false,
68
+ configurable: true
69
+ });
70
+ CleanStateBase.update = function update() {
71
+ var _this = this;
72
+ if (!(this instanceof exports.CleanState))
73
+ throw new Error('CleanState.update must be called with `this` value set to a CleanState instance. Did you forget to use `.call` or `.apply`? Example: CleanState.update.call(cleanState);');
74
+ /**
75
+ * Linters complain about the use of a React hook within a loop because:
76
+ * > By following this rule, you ensure that Hooks are called in the same order each time a component renders.
77
+ * > That’s what allows React to correctly preserve the state of Hooks between multiple useState and useEffect calls.
78
+ * To resolve this, we're calling `useState` via an alias `retrieveState`.
79
+ * Bypassing this rule is safe here because `useCleanState` is a special case,
80
+ * and it guarantees that the same useState calls will be made on every render in the exact same order.
81
+ * Therefore, it is safe to silence the linters, and required for this implementation to work smoothly.
82
+ */
83
+ var retrieveState = react_1.useState;
84
+ this.valueKeys.forEach(function (key) {
85
+ var _a;
86
+ // @todo Make state updates accessible immediately. Use state.staged to access the scheduled updates.
87
+ var setter;
88
+ _a = retrieveState(_this.initialState[key]), _this._values_[key] = _a[0], setter = _a[1];
89
+ _this._setters_[key] = (function (valueOrCallback) {
90
+ // this._staged_[key] = value;
91
+ setter(valueOrCallback);
92
+ });
93
+ });
94
+ };
95
+ return CleanStateBase;
96
+ }());
97
+ exports.CleanStateBase = CleanStateBase;
98
+ ;
99
+ /** @internal */
100
+ exports.CleanState = (CleanStateBase);
@@ -0,0 +1,32 @@
1
+ import { CleanStateBase } from './class';
2
+ /**
3
+ * Base type for an `initialState` object.
4
+ * It is a regular object type, with some reserved keys excluded.
5
+ */
6
+ export type TStateData = object & {
7
+ [Key in keyof CleanStateBase<{}>]?: never;
8
+ };
9
+ /**
10
+ * Describes a `CleanState` object instantiated with an `initialState`
11
+ * object of type `TState`.
12
+ *
13
+ * @typeParam TState - The type of your `initialState` object.
14
+ */
15
+ export type TCleanState<TState extends TStateData> = (CleanStateBase<TState> & Omit<TState, keyof CleanStateBase<{}>>);
16
+ /**
17
+ * Takes a `TCleanState` type and returns the `initialState` type
18
+ * associated with the provided `TCleanState`.
19
+ *
20
+ * This is useful to isolate the type of your actual state data without
21
+ * any of the reserved keys provided by the Clean State utility.
22
+ */
23
+ export type ExtractCleanStateData<YourCleanState extends CleanStateBase<{}>> = Omit<YourCleanState, keyof CleanStateBase<{}>>;
24
+ type StateInitFunction = (...args: any[]) => object;
25
+ type StateInit = object | StateInitFunction;
26
+ export type TInitialState<Initializer extends StateInit> = Initializer extends (...args: any[]) => (infer TState extends object) ? TState : Initializer;
27
+ /**
28
+ * @typeParam TInit - An initial state object, or a function that
29
+ * returns the initial state object.
30
+ */
31
+ export type TUseCleanState = <TInit extends StateInit>(_initialState: TInit, ...props: TInit extends (...args: infer TProps extends any[]) => (infer TState extends object) ? TProps : []) => TCleanState<TInitialState<TInit>>;
32
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { TUseCleanState } from './hook-types';
2
+ /**
3
+ * Creates a state object, which includes the provided values,
4
+ * as well as helper methods for updating those values and automatically
5
+ * rerendering your component's UI to reflect the updates.
6
+ *
7
+ * Uses {@link React.useState} under the hood, with a separate call
8
+ * to `useState` for each top-level key in the provided object.
9
+ *
10
+ * Discussion: [When to `useCleanState`](https://cleanjsweb.github.io/neat-react/documents/Clean_State.html).
11
+ */
12
+ export declare const useCleanState: TUseCleanState;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useCleanState = void 0;
4
+ var react_1 = require("react");
5
+ var class_1 = require("./class");
6
+ /**
7
+ * Creates a state object, which includes the provided values,
8
+ * as well as helper methods for updating those values and automatically
9
+ * rerendering your component's UI to reflect the updates.
10
+ *
11
+ * Uses {@link React.useState} under the hood, with a separate call
12
+ * to `useState` for each top-level key in the provided object.
13
+ *
14
+ * Discussion: [When to `useCleanState`](https://cleanjsweb.github.io/neat-react/documents/Clean_State.html).
15
+ */
16
+ var useCleanState = function (_initialState) {
17
+ var props = [];
18
+ for (var _i = 1; _i < arguments.length; _i++) {
19
+ props[_i - 1] = arguments[_i];
20
+ }
21
+ var initialState = typeof _initialState === 'function'
22
+ ? (0, react_1.useMemo)(function () { return _initialState.apply(void 0, props); }, [])
23
+ : _initialState;
24
+ ;
25
+ var cleanState = (0, react_1.useRef)((0, react_1.useMemo)(function () {
26
+ return new class_1.CleanState(initialState);
27
+ }, [])).current;
28
+ class_1.CleanState.update.call(cleanState);
29
+ return cleanState;
30
+ };
31
+ exports.useCleanState = useCleanState;
32
+ // Should be valid.
33
+ // useCleanState((a: number) => ({b: a.toString(), q: 1}), 6);
34
+ // useCleanState((a: boolean) => ({b: a.toString()}), true);
35
+ // useCleanState((a: number, c?: string) => ({ b: `${a}` }), 6);
36
+ // useCleanState((a: number, c?: string) => ({ b: `${a}` }), 6, 'word');
37
+ // useCleanState((a: number, c: string) => ({ b: a + c, f: true }), 6, 'text');
38
+ // useCleanState({ d: 5000 });
39
+ // Should fail.
40
+ // useCleanState((a: number) => ({b: a.toString(), q: 1}), 6, false);
41
+ // useCleanState((a: boolean) => ({b: a.toString()}));
42
+ // useCleanState((a: number, c?: string) => ({ b: `${a}` }), '6');
43
+ // useCleanState((a: number, c?: string) => ({ b: `${a}` }));
44
+ // useCleanState((a: number, c: string) => ({ b: a + c, f: true }), 6, 7);
45
+ // useCleanState({ d: 5000 }, true);
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @module CleanState
3
+ */
4
+ import '../../globals';
5
+ export { CleanState } from './class';
6
+ export { useCleanState } from './hooks';
7
+ export type { TCleanState, TStateData, ExtractCleanStateData } from './hook-types';
8
+ export * as MergedState from '../../base/merged-state';
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ /**
3
+ * @module CleanState
4
+ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.MergedState = exports.useCleanState = exports.CleanState = void 0;
30
+ require("../../globals");
31
+ var class_1 = require("./class");
32
+ Object.defineProperty(exports, "CleanState", { enumerable: true, get: function () { return class_1.CleanState; } });
33
+ var hooks_1 = require("./hooks");
34
+ Object.defineProperty(exports, "useCleanState", { enumerable: true, get: function () { return hooks_1.useCleanState; } });
35
+ exports.MergedState = __importStar(require("../../base/merged-state"));
@@ -0,0 +1,115 @@
1
+ import type { TPropsBase } from '../logic';
2
+ import type { Extractor } from './types/extractor';
3
+ import { ComponentInstance } from '../instance';
4
+ /**
5
+ * @summary
6
+ * A modern class component for React that is fully compatible with
7
+ * React Hooks and all of React's latest features.
8
+ *
9
+ * It is a superset of {@link ComponentInstance} that allows defining your
10
+ * component's JSX template directly inside the class.
11
+ *
12
+ * @remarks
13
+ * In essence, this is a class wrapper around an underlying function component.
14
+ * It acts as syntactic sugar, allowing you to create a regular function
15
+ * component, while writing in an object-oriented format.
16
+ *
17
+ * This is designed to closely resemble the old {@link React.Component} class,
18
+ * making it easier to migrate older class components to the newer hooks-based system
19
+ * with little to no changes to their existing semantics/implementation.
20
+ */
21
+ export declare class ClassComponent<TProps extends TPropsBase = null> extends ComponentInstance<TProps> {
22
+ /**
23
+ * Analogous to {@link React.Component.render}. A function that returns
24
+ * your component's JSX template.
25
+ *
26
+ * ******
27
+ *
28
+ * Ideally the template method should only be concerned with defining the HTML/JSX structure of
29
+ * your component's UI.
30
+ *
31
+ * If you need to transform some data for display,
32
+ * do so in [beforeRender]({@link ComponentInstance.beforeRender}),
33
+ * and return an object with transformed data that can be rendered directly.
34
+ *
35
+ * The returned object will be passed to your template method
36
+ * as a `context` object.
37
+ *
38
+ * ******
39
+ *
40
+ * @example Using a template function that returns JSX.
41
+ *
42
+ * ```tsx
43
+ * beforeRender = () => {
44
+ * return {
45
+ * title: `My Site | ${this.props.title}`,
46
+ * };
47
+ * }
48
+ * template = (ctx) => {
49
+ * return (
50
+ * <h1>
51
+ * {ctx.title}
52
+ * </h1>
53
+ * <p>{this.props.description}</p>
54
+ * );
55
+ * }
56
+ * ```
57
+ */
58
+ template: (context: this['templateContext']) => JSX.Element | null;
59
+ /**
60
+ * Manually trigger a rerender of your component.
61
+ * You should rarely ever need this. But if you are migrating
62
+ * an older React.Component class, this should provide similar functionality
63
+ * to the {@link React.Component.forceUpdate | `forceUpdate`} method provided there.
64
+ *
65
+ * Note that the callback argument is currently not supported.
66
+ */
67
+ readonly forceUpdate: VoidFunction;
68
+ /*************************************
69
+ * Function Component Extractor *
70
+ **************************************/
71
+ /**
72
+ * Extract a Function Component (FC) which can be used to render
73
+ * your ClassComponent just like any other React component.
74
+ *
75
+ * Each JSX reference to the returned component will render with
76
+ * a separate instance of your class.
77
+ *
78
+ * So you only need to call `YourClassComponent.extract()` (or `*.FC()`) once,
79
+ * then use the returned function component as many times as you need.
80
+ *
81
+ * It is recommended to store this returned value as a static member of
82
+ * your ClassComponent. While this value may be given any name, the name
83
+ * RC (for "React Component") is the recommended convention.
84
+ *
85
+ * @example <caption>Calling `extract` in your ClassComponent</caption>
86
+ * class Button extends ClassComponent {
87
+ * static readonly RC = this.extract(); // or this.FC();
88
+ * // Because of the static keyword, `this` here refers to the class itself, same as calling `Button.extract()`.
89
+ * }
90
+ *
91
+ * // Render with `<Button.RC />`, or export RC to use the component in other files.
92
+ * export default Button.RC;
93
+ */
94
+ static readonly extract: Extractor;
95
+ /** @see {@link ClassComponent.extract} */
96
+ static readonly FC: Extractor;
97
+ }
98
+ export { ClassComponent as Component };
99
+ /** /
100
+ testing: {
101
+ const a: object = {b: ''};
102
+
103
+ type t = keyof typeof a;
104
+
105
+ class MyComponentLogic extends ClassComponent<{a: ''}> {
106
+ getInitialState = () => ({a: '' as const});
107
+ // a = () => this.hooks.a = '';
108
+
109
+ useHooks = () => {
110
+ this.state.a;
111
+ };
112
+ };
113
+
114
+ const Template = MyComponentLogic.FC();
115
+ }/**/
@@ -0,0 +1,161 @@
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.Component = exports.ClassComponent = void 0;
19
+ var react_1 = require("react");
20
+ var instance_1 = require("../instance");
21
+ var function_name_1 = require("./utils/function-name");
22
+ var rerender_1 = require("../../helpers/rerender");
23
+ /**
24
+ * @summary
25
+ * A modern class component for React that is fully compatible with
26
+ * React Hooks and all of React's latest features.
27
+ *
28
+ * It is a superset of {@link ComponentInstance} that allows defining your
29
+ * component's JSX template directly inside the class.
30
+ *
31
+ * @remarks
32
+ * In essence, this is a class wrapper around an underlying function component.
33
+ * It acts as syntactic sugar, allowing you to create a regular function
34
+ * component, while writing in an object-oriented format.
35
+ *
36
+ * This is designed to closely resemble the old {@link React.Component} class,
37
+ * making it easier to migrate older class components to the newer hooks-based system
38
+ * with little to no changes to their existing semantics/implementation.
39
+ */
40
+ var ClassComponent = /** @class */ (function (_super) {
41
+ __extends(ClassComponent, _super);
42
+ function ClassComponent() {
43
+ var _this = _super !== null && _super.apply(this, arguments) || this;
44
+ /**
45
+ * Analogous to {@link React.Component.render}. A function that returns
46
+ * your component's JSX template.
47
+ *
48
+ * ******
49
+ *
50
+ * Ideally the template method should only be concerned with defining the HTML/JSX structure of
51
+ * your component's UI.
52
+ *
53
+ * If you need to transform some data for display,
54
+ * do so in [beforeRender]({@link ComponentInstance.beforeRender}),
55
+ * and return an object with transformed data that can be rendered directly.
56
+ *
57
+ * The returned object will be passed to your template method
58
+ * as a `context` object.
59
+ *
60
+ * ******
61
+ *
62
+ * @example Using a template function that returns JSX.
63
+ *
64
+ * ```tsx
65
+ * beforeRender = () => {
66
+ * return {
67
+ * title: `My Site | ${this.props.title}`,
68
+ * };
69
+ * }
70
+ * template = (ctx) => {
71
+ * return (
72
+ * <h1>
73
+ * {ctx.title}
74
+ * </h1>
75
+ * <p>{this.props.description}</p>
76
+ * );
77
+ * }
78
+ * ```
79
+ */
80
+ _this.template = function () { return null; };
81
+ return _this;
82
+ }
83
+ var _a;
84
+ _a = ClassComponent;
85
+ /*************************************
86
+ * Function Component Extractor *
87
+ **************************************/
88
+ /**
89
+ * Extract a Function Component (FC) which can be used to render
90
+ * your ClassComponent just like any other React component.
91
+ *
92
+ * Each JSX reference to the returned component will render with
93
+ * a separate instance of your class.
94
+ *
95
+ * So you only need to call `YourClassComponent.extract()` (or `*.FC()`) once,
96
+ * then use the returned function component as many times as you need.
97
+ *
98
+ * It is recommended to store this returned value as a static member of
99
+ * your ClassComponent. While this value may be given any name, the name
100
+ * RC (for "React Component") is the recommended convention.
101
+ *
102
+ * @example <caption>Calling `extract` in your ClassComponent</caption>
103
+ * class Button extends ClassComponent {
104
+ * static readonly RC = this.extract(); // or this.FC();
105
+ * // Because of the static keyword, `this` here refers to the class itself, same as calling `Button.extract()`.
106
+ * }
107
+ *
108
+ * // Render with `<Button.RC />`, or export RC to use the component in other files.
109
+ * export default Button.RC;
110
+ */
111
+ ClassComponent.extract = function FC(_Component) {
112
+ var Component = _Component !== null && _Component !== void 0 ? _Component : this;
113
+ var isClassComponentType = Component.prototype instanceof _a;
114
+ if (!isClassComponentType)
115
+ throw new Error('Attempted to initialize ClassComponent with invalid Class type. Either pass, as an argument to FC(), a class that extends ClassComponent (e.g `export FC(MyComponent);`), or ensure FC() is called as a method on a ClassComponent constructor type (e.g `export MyComponent.FC()`).');
116
+ /*************************************
117
+ * Begin Function Component *
118
+ **************************************/
119
+ /** A class-based, React function component created with `@cleanweb/react`. {@link ClassComponent} */
120
+ var Wrapper = function (props) {
121
+ var instance = (0, instance_1.useInstance)(Component, props);
122
+ var template = instance.template, templateContext = instance.templateContext;
123
+ var _forceUpdate;
124
+ // @ts-expect-error (Cannot assign to 'forceUpdate' because it is a read-only property.ts(2540))
125
+ instance.forceUpdate = (_forceUpdate = (0, rerender_1.useRerender)() // Moved this to separate line to allow TS errors. Use proxy local variable to regain some type checking for the assignment to `instance.forceUpdate`.
126
+ );
127
+ // Add calling component name to template function name in stack traces.
128
+ (0, react_1.useMemo)(function () {
129
+ (0, function_name_1.setFunctionName)(template, "".concat(Component.name, ".template"));
130
+ }, [template]);
131
+ return template(templateContext);
132
+ };
133
+ /**************************************
134
+ * End Function Component *
135
+ **************************************/
136
+ (0, function_name_1.setFunctionName)(Wrapper, "$".concat(Component.name, "$"));
137
+ return Wrapper;
138
+ };
139
+ /** @see {@link ClassComponent.extract} */
140
+ ClassComponent.FC = _a.extract;
141
+ return ClassComponent;
142
+ }(instance_1.ComponentInstance));
143
+ exports.ClassComponent = ClassComponent;
144
+ exports.Component = ClassComponent;
145
+ /** /
146
+ testing: {
147
+ const a: object = {b: ''};
148
+
149
+ type t = keyof typeof a;
150
+
151
+ class MyComponentLogic extends ClassComponent<{a: ''}> {
152
+ getInitialState = () => ({a: '' as const});
153
+ // a = () => this.hooks.a = '';
154
+
155
+ useHooks = () => {
156
+ this.state.a;
157
+ };
158
+ };
159
+
160
+ const Template = MyComponentLogic.FC();
161
+ }/**/
@@ -0,0 +1,5 @@
1
+ import type { VoidFunctionComponent } from 'react';
2
+ import type { ClassComponent } from '..';
3
+ type BaseCCConstructor = typeof ClassComponent<object>;
4
+ export type Extractor = <TComponentClass extends BaseCCConstructor>(this: TComponentClass, Component?: TComponentClass) => VoidFunctionComponent<InstanceType<TComponentClass>['props']>;
5
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ /** Provide more useful stack traces for otherwise non-specific function names. */
2
+ export declare const setFunctionName: (func: FunctionType, newName: string) => void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setFunctionName = void 0;
4
+ /** Provide more useful stack traces for otherwise non-specific function names. */
5
+ var setFunctionName = function (func, newName) {
6
+ try {
7
+ // Must use try block, as `name` is not configurable on older browsers, and may yield a TypeError.
8
+ Object.defineProperty(func, 'name', {
9
+ writable: true,
10
+ value: newName,
11
+ });
12
+ }
13
+ catch (error) {
14
+ console.warn(error);
15
+ }
16
+ };
17
+ exports.setFunctionName = setFunctionName;
@@ -0,0 +1,3 @@
1
+ export * from './logic';
2
+ export * from './instance';
3
+ export * from './class';
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./logic"), exports);
18
+ __exportStar(require("./instance"), exports);
19
+ __exportStar(require("./class"), exports);