@cleanweb/oore 2.0.0-alpha.34 → 2.0.0-alpha.36

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 (134) hide show
  1. package/build/base/index.d.ts +3 -3
  2. package/build/base/index.js +19 -3
  3. package/build/base/merged-state.d.ts +1 -0
  4. package/build/base/merged-state.js +58 -30
  5. package/build/base/methods.d.ts +6 -5
  6. package/build/base/methods.js +28 -19
  7. package/build/base/state/class-types.d.ts +2 -2
  8. package/build/base/state/class-types.js +2 -1
  9. package/build/base/state/class.d.ts +1 -1
  10. package/build/base/state/class.js +72 -45
  11. package/build/base/state/hook-types.d.ts +1 -1
  12. package/build/base/state/hook-types.js +2 -1
  13. package/build/base/state/hooks.d.ts +1 -1
  14. package/build/base/state/hooks.js +16 -8
  15. package/build/base/state/index.d.ts +6 -5
  16. package/build/base/state/index.js +32 -3
  17. package/build/classy/class/index.d.ts +5 -18
  18. package/build/classy/class/index.js +87 -98
  19. package/build/classy/class/types/extractor.d.ts +1 -1
  20. package/build/classy/class/types/extractor.js +2 -1
  21. package/build/classy/class/utils/function-name.js +5 -1
  22. package/build/classy/index.d.ts +3 -3
  23. package/build/classy/index.js +19 -3
  24. package/build/classy/instance/index.d.ts +4 -4
  25. package/build/classy/instance/index.js +88 -58
  26. package/build/classy/instance/mount-callbacks.d.ts +1 -1
  27. package/build/classy/instance/mount-callbacks.js +12 -8
  28. package/build/classy/instance/types/hook.d.ts +1 -1
  29. package/build/classy/instance/types/hook.js +2 -1
  30. package/build/classy/logic/index.d.ts +2 -2
  31. package/build/classy/logic/index.js +32 -22
  32. package/build/classy/logic/types/hook.d.ts +1 -1
  33. package/build/classy/logic/types/hook.js +2 -1
  34. package/build/docs-src/api/base-classes.d.ts +3 -3
  35. package/build/docs-src/api/base-classes.js +9 -3
  36. package/build/docs-src/api/index.d.ts +8 -8
  37. package/build/docs-src/api/index.js +39 -8
  38. package/build/docs-src/api/references.d.ts +5 -5
  39. package/build/docs-src/api/references.js +31 -5
  40. package/build/globals.d.ts +83 -130
  41. package/build/globals.js +4 -0
  42. package/build/helpers/errors.js +5 -1
  43. package/build/helpers/index.d.ts +4 -7
  44. package/build/helpers/index.js +23 -8
  45. package/build/helpers/mount-state.js +10 -6
  46. package/build/helpers/rerender.js +16 -12
  47. package/build/helpers/type-guards.js +6 -2
  48. package/build/helpers/use-component/index.d.ts +1 -1
  49. package/build/helpers/use-component/index.js +9 -5
  50. package/build/helpers/use-component/types.js +2 -1
  51. package/build/index.d.ts +4 -3
  52. package/build/index.js +19 -3
  53. package/build/slots/hook.d.ts +2 -2
  54. package/build/slots/hook.js +78 -44
  55. package/build/slots/index.d.ts +1 -1
  56. package/build/slots/index.js +17 -1
  57. package/build/slots/types.d.ts +16 -13
  58. package/build/slots/types.js +2 -1
  59. package/build/tsconfig.json +6 -9
  60. package/package.json +11 -31
  61. package/build/_cjs/base/index.d.ts +0 -3
  62. package/build/_cjs/base/index.js +0 -19
  63. package/build/_cjs/base/merged-state.d.ts +0 -19
  64. package/build/_cjs/base/merged-state.js +0 -60
  65. package/build/_cjs/base/methods.d.ts +0 -58
  66. package/build/_cjs/base/methods.js +0 -95
  67. package/build/_cjs/base/state/class-types.d.ts +0 -20
  68. package/build/_cjs/base/state/class-types.js +0 -2
  69. package/build/_cjs/base/state/class.d.ts +0 -69
  70. package/build/_cjs/base/state/class.js +0 -129
  71. package/build/_cjs/base/state/hook-types.d.ts +0 -32
  72. package/build/_cjs/base/state/hook-types.js +0 -2
  73. package/build/_cjs/base/state/hooks.d.ts +0 -12
  74. package/build/_cjs/base/state/hooks.js +0 -41
  75. package/build/_cjs/base/state/index.d.ts +0 -8
  76. package/build/_cjs/base/state/index.js +0 -34
  77. package/build/_cjs/classy/class/index.d.ts +0 -128
  78. package/build/_cjs/classy/class/index.js +0 -176
  79. package/build/_cjs/classy/class/types/extractor.d.ts +0 -5
  80. package/build/_cjs/classy/class/types/extractor.js +0 -2
  81. package/build/_cjs/classy/class/utils/function-name.d.ts +0 -2
  82. package/build/_cjs/classy/class/utils/function-name.js +0 -17
  83. package/build/_cjs/classy/index.d.ts +0 -3
  84. package/build/_cjs/classy/index.js +0 -19
  85. package/build/_cjs/classy/instance/index.d.ts +0 -144
  86. package/build/_cjs/classy/instance/index.js +0 -177
  87. package/build/_cjs/classy/instance/mount-callbacks.d.ts +0 -5
  88. package/build/_cjs/classy/instance/mount-callbacks.js +0 -30
  89. package/build/_cjs/classy/instance/types/hook.d.ts +0 -13
  90. package/build/_cjs/classy/instance/types/hook.js +0 -2
  91. package/build/_cjs/classy/logic/index.d.ts +0 -116
  92. package/build/_cjs/classy/logic/index.js +0 -123
  93. package/build/_cjs/classy/logic/types/hook.d.ts +0 -16
  94. package/build/_cjs/classy/logic/types/hook.js +0 -2
  95. package/build/_cjs/docs-src/api/base-classes.d.ts +0 -3
  96. package/build/_cjs/docs-src/api/base-classes.js +0 -9
  97. package/build/_cjs/docs-src/api/index.d.ts +0 -13
  98. package/build/_cjs/docs-src/api/index.js +0 -44
  99. package/build/_cjs/docs-src/api/references.d.ts +0 -5
  100. package/build/_cjs/docs-src/api/references.js +0 -31
  101. package/build/_cjs/helpers/debounce/index.d.ts +0 -55
  102. package/build/_cjs/helpers/debounce/index.js +0 -111
  103. package/build/_cjs/helpers/debounce/react-state.d.ts +0 -14
  104. package/build/_cjs/helpers/debounce/react-state.js +0 -32
  105. package/build/_cjs/helpers/errors.d.ts +0 -10
  106. package/build/_cjs/helpers/errors.js +0 -21
  107. package/build/_cjs/helpers/index.d.ts +0 -16
  108. package/build/_cjs/helpers/index.js +0 -34
  109. package/build/_cjs/helpers/mount-state.d.ts +0 -5
  110. package/build/_cjs/helpers/mount-state.js +0 -25
  111. package/build/_cjs/helpers/object-gate.d.ts +0 -74
  112. package/build/_cjs/helpers/object-gate.js +0 -67
  113. package/build/_cjs/helpers/rerender.d.ts +0 -24
  114. package/build/_cjs/helpers/rerender.js +0 -42
  115. package/build/_cjs/helpers/type-guards.d.ts +0 -1
  116. package/build/_cjs/helpers/type-guards.js +0 -8
  117. package/build/_cjs/helpers/use-component/index.d.ts +0 -6
  118. package/build/_cjs/helpers/use-component/index.js +0 -17
  119. package/build/_cjs/helpers/use-component/types.d.ts +0 -22
  120. package/build/_cjs/helpers/use-component/types.js +0 -2
  121. package/build/_cjs/index.d.ts +0 -3
  122. package/build/_cjs/index.js +0 -19
  123. package/build/_cjs/slots/hook.d.ts +0 -20
  124. package/build/_cjs/slots/hook.js +0 -147
  125. package/build/_cjs/slots/index.d.ts +0 -1
  126. package/build/_cjs/slots/index.js +0 -17
  127. package/build/_cjs/slots/types.d.ts +0 -128
  128. package/build/_cjs/slots/types.js +0 -2
  129. package/build/helpers/debounce/index.d.ts +0 -55
  130. package/build/helpers/debounce/index.js +0 -107
  131. package/build/helpers/debounce/react-state.d.ts +0 -14
  132. package/build/helpers/debounce/react-state.js +0 -29
  133. package/build/helpers/object-gate.d.ts +0 -74
  134. package/build/helpers/object-gate.js +0 -64
@@ -1,3 +1,3 @@
1
- export * from './state/index.js';
2
- export * from './methods.js';
3
- export * from './merged-state.js';
1
+ export * from './state';
2
+ export * from './methods';
3
+ export * from './merged-state';
@@ -1,3 +1,19 @@
1
- export * from './state/index.js';
2
- export * from './methods.js';
3
- export * from './merged-state.js';
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("./state"), exports);
18
+ __exportStar(require("./methods"), exports);
19
+ __exportStar(require("./merged-state"), exports);
@@ -1,3 +1,4 @@
1
+ import '../globals';
1
2
  declare class MergedState<TState extends object> {
2
3
  static useRefresh<TState extends object>(this: MergedState<TState>): void;
3
4
  reservedKeys: string[];
@@ -1,56 +1,84 @@
1
- import { useMemo, useRef, useState } from 'react';
2
- class MergedState {
3
- static useRefresh() {
4
- [this._values_, this.setState] = useState(this.initialState);
5
- }
6
- get put() {
7
- return Object.assign({}, this._setters_);
8
- }
9
- get initialState() {
10
- return Object.assign({}, this._initialValues_);
11
- }
12
- constructor(initialState) {
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.useMergedState = void 0;
15
+ require("../globals");
16
+ var react_1 = require("react");
17
+ var MergedState = /** @class */ (function () {
18
+ function MergedState(initialState) {
19
+ var _this = this;
13
20
  this._initialValues_ = {};
14
21
  this._values_ = {};
15
22
  this._setters_ = {};
16
- this.putMany = (newValues) => {
17
- this.setState(Object.assign(Object.assign({}, this._values_), newValues));
23
+ this.putMany = function (newValues) {
24
+ _this.setState(__assign(__assign({}, _this._values_), newValues));
18
25
  };
19
26
  this.reservedKeys = Object.keys(this);
20
27
  this.valueKeys = [];
21
- this._initialValues_ = Object.assign({}, initialState);
22
- this._values_ = Object.assign({}, initialState);
23
- Object.keys(initialState).forEach((_key) => {
24
- const key = _key;
25
- if (this.reservedKeys.includes(key)) {
26
- throw new Error(`The name "${key}" is reserved by CleanState and cannot be used to index state variables. Please use a different key.`);
28
+ this._initialValues_ = __assign({}, initialState);
29
+ this._values_ = __assign({}, initialState);
30
+ Object.keys(initialState).forEach(function (_key) {
31
+ var key = _key;
32
+ if (_this.reservedKeys.includes(key)) {
33
+ throw new Error("The name \"".concat(key, "\" is reserved by CleanState and cannot be used to index state variables. Please use a different key."));
27
34
  }
28
- this.valueKeys.push(key);
29
- this._setters_[key] = (value) => {
35
+ _this.valueKeys.push(key);
36
+ _this._setters_[key] = function (value) {
37
+ var _a;
30
38
  // this._values_[key] = value;
31
- this.setState(Object.assign(Object.assign({}, this._values_), { [key]: value }));
39
+ _this.setState(__assign(__assign({}, _this._values_), (_a = {}, _a[key] = value, _a)));
32
40
  };
33
- const self = this;
34
- Object.defineProperty(this, key, {
35
- get() {
41
+ var self = _this;
42
+ Object.defineProperty(_this, key, {
43
+ get: function () {
36
44
  return self._values_[key];
37
45
  },
38
- set(value) {
46
+ set: function (value) {
39
47
  self._setters_[key](value);
40
48
  },
41
49
  enumerable: true,
42
50
  });
43
51
  });
44
52
  }
45
- }
53
+ MergedState.useRefresh = function () {
54
+ var _a;
55
+ _a = (0, react_1.useState)(this.initialState), this._values_ = _a[0], this.setState = _a[1];
56
+ };
57
+ Object.defineProperty(MergedState.prototype, "put", {
58
+ get: function () {
59
+ return __assign({}, this._setters_);
60
+ },
61
+ enumerable: false,
62
+ configurable: true
63
+ });
64
+ Object.defineProperty(MergedState.prototype, "initialState", {
65
+ get: function () {
66
+ return __assign({}, this._initialValues_);
67
+ },
68
+ enumerable: false,
69
+ configurable: true
70
+ });
71
+ return MergedState;
72
+ }());
46
73
  /**
47
74
  * Similar to {@link useCleanState},
48
75
  * but uses a single `useState` call for the entire state object.
49
76
  */
50
- export const useMergedState = (initialState) => {
51
- const cleanState = useRef(useMemo(() => {
77
+ var useMergedState = function (initialState) {
78
+ var cleanState = (0, react_1.useRef)((0, react_1.useMemo)(function () {
52
79
  return new MergedState(initialState);
53
80
  }, [])).current;
54
81
  MergedState.useRefresh.call(cleanState);
55
82
  return cleanState;
56
83
  };
84
+ exports.useMergedState = useMergedState;
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @module ComponentMethods
3
3
  */
4
+ import type { TCleanState, TStateData } from './state';
4
5
  /**
5
6
  * @summary
6
7
  * Base class for a class that holds methods for a function component.
@@ -11,9 +12,9 @@
11
12
  *
12
13
  * Call the {@link useMethods} hook inside your function component to instantiate the class.
13
14
  */
14
- export declare class ComponentMethods<TProps extends object = {}, TState extends object | null = null> {
15
+ export declare class ComponentMethods<TProps extends object = {}, TState extends TStateData | null = null> {
15
16
  readonly props: TProps;
16
- readonly state: TState;
17
+ readonly state: TState extends TStateData ? TCleanState<TState> : null;
17
18
  /**
18
19
  * Persist class members during HMR. {@include ../classy/logic/hrm-preserve-keys.md}
19
20
  * @privateRemarks
@@ -28,9 +29,9 @@ export declare class ComponentMethods<TProps extends object = {}, TState extends
28
29
  _onHmrUpdate?: <TInstance extends this>(oldInstance: TInstance) => void;
29
30
  }
30
31
  type UseMethods = {
31
- <Class extends typeof ComponentMethods<object, object>>(Methods: Class, props: InstanceType<Class>['props'], state: InstanceType<Class>['state']): InstanceType<Class>;
32
- <Class extends typeof ComponentMethods<object, null>>(Methods: Class, props: InstanceType<Class>['props'], state?: null): InstanceType<Class>;
33
- <Class extends typeof ComponentMethods<NeverObject, null>>(Methods: Class): InstanceType<Class>;
32
+ <Class extends typeof ComponentMethods<object, object>>(Methods: Class & Constructor<InstanceType<Class>>, props: InstanceType<Class>['props'], state: InstanceType<Class>['state']): InstanceType<Class>;
33
+ <Class extends typeof ComponentMethods<object, null>>(Methods: Class & Constructor<InstanceType<Class>>, props: InstanceType<Class>['props'], state?: null): InstanceType<Class>;
34
+ <Class extends typeof ComponentMethods<NeverObject, null>>(Methods: Class & Constructor<InstanceType<Class>>): InstanceType<Class>;
34
35
  };
35
36
  /**
36
37
  * Returns an instance of the provided class,
@@ -1,8 +1,11 @@
1
+ "use strict";
1
2
  /**
2
3
  * @module ComponentMethods
3
4
  */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useMethods = exports.ComponentMethods = void 0;
4
7
  // Values
5
- import { useMemo, useRef } from 'react';
8
+ var react_1 = require("react");
6
9
  /**
7
10
  * @summary
8
11
  * Base class for a class that holds methods for a function component.
@@ -13,8 +16,8 @@ import { useMemo, useRef } from 'react';
13
16
  *
14
17
  * Call the {@link useMethods} hook inside your function component to instantiate the class.
15
18
  */
16
- export class ComponentMethods {
17
- constructor() {
19
+ var ComponentMethods = /** @class */ (function () {
20
+ function ComponentMethods() {
18
21
  /**
19
22
  * Persist class members during HMR. {@include ../classy/logic/hrm-preserve-keys.md}
20
23
  * @privateRemarks
@@ -22,7 +25,9 @@ export class ComponentMethods {
22
25
  */
23
26
  this._hmrPreserveKeys = []; // @todo Keep undefined. Update to empty array after instantiation in dev env.
24
27
  }
25
- }
28
+ return ComponentMethods;
29
+ }());
30
+ exports.ComponentMethods = ComponentMethods;
26
31
  ;
27
32
  /**
28
33
  * Returns an instance of the provided class,
@@ -30,9 +35,13 @@ export class ComponentMethods {
30
35
  *
31
36
  * `state` should be an instance of `CleanState` created with {@link useCleanState}.
32
37
  */
33
- const useMethods = (...args) => {
38
+ var useMethods = function () {
34
39
  var _a;
35
- const [Methods, props = {}, state] = args;
40
+ var args = [];
41
+ for (var _i = 0; _i < arguments.length; _i++) {
42
+ args[_i] = arguments[_i];
43
+ }
44
+ var Methods = args[0], _b = args[1], props = _b === void 0 ? {} : _b, state = args[2];
36
45
  // Vite HMR seems to sometimes reinitialize useMemo calls after a hot update,
37
46
  // causing the instance to be unexpectedly recreated in the middle of the component's lifecycle.
38
47
  // But useRef and useState values appear to always be preserved whenever this happens.
@@ -40,9 +49,9 @@ const useMethods = (...args) => {
40
49
  // In production, we only use the latestInstance the first time, and it's ignored every other time.
41
50
  // This means changing the class at runtime will have no effect in production.
42
51
  // latestInstance is only extracted into a separate variable for use in dev mode during HMR.
43
- const latestInstance = useMemo(() => new Methods(), [Methods]);
44
- const instanceRef = useRef(latestInstance);
45
- const refreshState = () => {
52
+ var latestInstance = (0, react_1.useMemo)(function () { return new Methods(); }, [Methods]);
53
+ var instanceRef = (0, react_1.useRef)(latestInstance);
54
+ var refreshState = function () {
46
55
  // @ts-expect-error
47
56
  instanceRef.current.props = props;
48
57
  // @ts-expect-error
@@ -50,29 +59,29 @@ const useMethods = (...args) => {
50
59
  instanceRef.current.state = state;
51
60
  };
52
61
  if (process.env.NODE_ENV === 'development' && instanceRef.current !== latestInstance) {
53
- const oldInstance = instanceRef.current;
54
- latestInstance._hmrPreserveKeys.forEach((_key) => {
55
- const key = _key;
62
+ var oldInstance_1 = instanceRef.current;
63
+ latestInstance._hmrPreserveKeys.forEach(function (_key) {
64
+ var key = _key;
56
65
  // @ts-expect-error We're assigning to readonly properties. Also, Typescript doesn't know that the type of the left and right side will always match, due to the dynamic access.
57
- latestInstance[key] = oldInstance[key];
66
+ latestInstance[key] = oldInstance_1[key];
58
67
  });
59
68
  // Ensure that any stale references to oldInstance within the app
60
69
  // will end up retrieving up-to-date values from latestInstance
61
70
  // through the prototype chain.
62
- Reflect.ownKeys(oldInstance).forEach((_key) => {
63
- const key = _key;
64
- delete oldInstance[key];
71
+ Reflect.ownKeys(oldInstance_1).forEach(function (_key) {
72
+ var key = _key;
73
+ delete oldInstance_1[key];
65
74
  });
66
- Object.setPrototypeOf(oldInstance, latestInstance);
75
+ Object.setPrototypeOf(oldInstance_1, latestInstance);
67
76
  instanceRef.current = latestInstance;
68
77
  refreshState();
69
- (_a = latestInstance._onHmrUpdate) === null || _a === void 0 ? void 0 : _a.call(latestInstance, oldInstance);
78
+ (_a = latestInstance._onHmrUpdate) === null || _a === void 0 ? void 0 : _a.call(latestInstance, oldInstance_1);
70
79
  }
71
80
  else
72
81
  refreshState();
73
82
  return instanceRef.current;
74
83
  };
75
- export { useMethods };
84
+ exports.useMethods = useMethods;
76
85
  /** /type_testing: {
77
86
  let a = async () => {
78
87
  const a: object = {b: ''};
@@ -1,5 +1,5 @@
1
- import { CleanStateBase } from './class.js';
2
- import { TCleanState, TStateData } from './hook-types.js';
1
+ import { CleanStateBase } from './class';
2
+ import { TCleanState, TStateData } from './hook-types';
3
3
  export type TCleanStateBase = typeof CleanStateBase;
4
4
  export type TCleanStateBaseKeys = keyof TCleanStateBase;
5
5
  export type PutState<TState extends TStateData> = {
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import type { ICleanStateClass, ICleanStateConstructor, PutManyPayload, PutState } from './class-types.js';
1
+ import type { ICleanStateClass, ICleanStateConstructor, PutManyPayload, PutState } from './class-types';
2
2
  /** @internal */
3
3
  export declare class CleanStateBase<TState extends Record<string, any>> {
4
4
  readonly reservedKeys: string[];
@@ -1,7 +1,22 @@
1
- import { useState } from 'react';
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");
2
16
  /** @internal */
3
- export class CleanStateBase {
4
- constructor(initialState) {
17
+ var CleanStateBase = /** @class */ (function () {
18
+ function CleanStateBase(initialState) {
19
+ var _this = this;
5
20
  this._values_ = {};
6
21
  this._setters_ = {};
7
22
  /**
@@ -57,10 +72,10 @@ export class CleanStateBase {
57
72
  * </>;
58
73
  * };
59
74
  */
60
- this.putMany = (newValues) => {
61
- Object.entries(newValues).forEach((entry) => {
62
- const [key, value] = entry;
63
- this.put[key](value);
75
+ this.putMany = function (newValues) {
76
+ Object.entries(newValues).forEach(function (entry) {
77
+ var _a = entry, key = _a[0], value = _a[1];
78
+ _this.put[key](value);
64
79
  });
65
80
  };
66
81
  this.reservedKeys = Object.keys(this);
@@ -74,52 +89,64 @@ export class CleanStateBase {
74
89
  * and they will always be processed in a consistent order during rerenders.
75
90
  */
76
91
  this.valueKeys = Object.keys(initialState);
77
- this._initialValues_ = Object.assign({}, initialState);
78
- this.valueKeys.forEach((key) => {
79
- if (this.reservedKeys.includes(key))
80
- throw new Error(`The name "${key}" is reserved by CleanState and cannot be used to index state variables. Please use a different key.`);
81
- const self = this;
82
- Object.defineProperty(this, key, {
83
- get() {
92
+ this._initialValues_ = __assign({}, initialState);
93
+ this.valueKeys.forEach(function (key) {
94
+ if (_this.reservedKeys.includes(key))
95
+ throw new Error("The name \"".concat(key, "\" is reserved by CleanState and cannot be used to index state variables. Please use a different key."));
96
+ var self = _this;
97
+ Object.defineProperty(_this, key, {
98
+ get: function () {
84
99
  return self._values_[key];
85
100
  },
86
- set(value) {
101
+ set: function (value) {
87
102
  self._setters_[key](value);
88
103
  },
89
104
  enumerable: true,
90
105
  });
91
106
  });
92
107
  }
93
- get put() {
94
- return Object.assign({}, this._setters_);
95
- }
96
- get initialState() {
97
- return Object.assign({}, this._initialValues_);
98
- }
99
- }
100
- CleanStateBase.update = function update() {
101
- if (!(this instanceof CleanState))
102
- 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);');
103
- /**
104
- * Linters complain about the use of a React hook within a loop because:
105
- * > By following this rule, you ensure that Hooks are called in the same order each time a component renders.
106
- * > That’s what allows React to correctly preserve the state of Hooks between multiple useState and useEffect calls.
107
- * To resolve this, we're calling `useState` via an alias `retrieveState`.
108
- * Bypassing this rule is safe here because `useCleanState` is a special case,
109
- * and it guarantees that the same useState calls will be made on every render in the exact same order.
110
- * Therefore, it is safe to silence the linters, and required for this implementation to work smoothly.
111
- */
112
- const retrieveState = useState;
113
- this.valueKeys.forEach((key) => {
114
- // @todo Make state updates accessible immediately. Use state.staged to access the scheduled updates.
115
- let setter;
116
- [this._values_[key], setter] = retrieveState(this.initialState[key]);
117
- this._setters_[key] = ((valueOrCallback) => {
118
- // this._staged_[key] = value;
119
- setter(valueOrCallback);
120
- });
108
+ Object.defineProperty(CleanStateBase.prototype, "put", {
109
+ get: function () {
110
+ return __assign({}, this._setters_);
111
+ },
112
+ enumerable: false,
113
+ configurable: true
121
114
  });
122
- };
115
+ Object.defineProperty(CleanStateBase.prototype, "initialState", {
116
+ get: function () {
117
+ return __assign({}, this._initialValues_);
118
+ },
119
+ enumerable: false,
120
+ configurable: true
121
+ });
122
+ CleanStateBase.update = function update() {
123
+ var _this = this;
124
+ if (!(this instanceof exports.CleanState))
125
+ 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);');
126
+ /**
127
+ * Linters complain about the use of a React hook within a loop because:
128
+ * > By following this rule, you ensure that Hooks are called in the same order each time a component renders.
129
+ * > That’s what allows React to correctly preserve the state of Hooks between multiple useState and useEffect calls.
130
+ * To resolve this, we're calling `useState` via an alias `retrieveState`.
131
+ * Bypassing this rule is safe here because `useCleanState` is a special case,
132
+ * and it guarantees that the same useState calls will be made on every render in the exact same order.
133
+ * Therefore, it is safe to silence the linters, and required for this implementation to work smoothly.
134
+ */
135
+ var retrieveState = react_1.useState;
136
+ this.valueKeys.forEach(function (key) {
137
+ var _a;
138
+ // @todo Make state updates accessible immediately. Use state.staged to access the scheduled updates.
139
+ var setter;
140
+ _a = retrieveState(_this.initialState[key]), _this._values_[key] = _a[0], setter = _a[1];
141
+ _this._setters_[key] = (function (valueOrCallback) {
142
+ // this._staged_[key] = value;
143
+ setter(valueOrCallback);
144
+ });
145
+ });
146
+ };
147
+ return CleanStateBase;
148
+ }());
149
+ exports.CleanStateBase = CleanStateBase;
123
150
  ;
124
151
  /** @internal */
125
- export const CleanState = (CleanStateBase);
152
+ exports.CleanState = (CleanStateBase);
@@ -1,4 +1,4 @@
1
- import { CleanStateBase } from './class.js';
1
+ import { CleanStateBase } from './class';
2
2
  /**
3
3
  * Base type for an `initialState` object.
4
4
  * It is a regular object type, with some reserved keys excluded.
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,4 @@
1
- import { TUseCleanState } from './hook-types.js';
1
+ import { TUseCleanState } from './hook-types';
2
2
  /**
3
3
  * Creates a state object, which includes the provided values,
4
4
  * as well as helper methods for updating those values and automatically
@@ -1,5 +1,8 @@
1
- import { useMemo, useRef } from 'react';
2
- import { CleanState } from './class.js';
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");
3
6
  /**
4
7
  * Creates a state object, which includes the provided values,
5
8
  * as well as helper methods for updating those values and automatically
@@ -10,17 +13,22 @@ import { CleanState } from './class.js';
10
13
  *
11
14
  * Discussion: [When to `useCleanState`](https://cleanjsweb.github.io/neat-react/documents/Clean_State.html).
12
15
  */
13
- export const useCleanState = (_initialState, ...props) => {
14
- const initialState = typeof _initialState === 'function'
15
- ? useMemo(() => _initialState(...props), [])
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); }, [])
16
23
  : _initialState;
17
24
  ;
18
- const cleanState = useRef(useMemo(() => {
19
- return new CleanState(initialState);
25
+ var cleanState = (0, react_1.useRef)((0, react_1.useMemo)(function () {
26
+ return new class_1.CleanState(initialState);
20
27
  }, [])).current;
21
- CleanState.update.call(cleanState);
28
+ class_1.CleanState.update.call(cleanState);
22
29
  return cleanState;
23
30
  };
31
+ exports.useCleanState = useCleanState;
24
32
  // Should be valid.
25
33
  // useCleanState((a: number) => ({b: a.toString(), q: 1}), 6);
26
34
  // useCleanState((a: boolean) => ({b: a.toString()}), true);
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * @module CleanState
3
3
  */
4
- export { CleanState } from './class.js';
5
- export { useCleanState } from './hooks.js';
6
- export type { TCleanState, TStateData, ExtractCleanStateData } from './hook-types.js';
7
- export type { SF, StateFragment } from './class-types.js';
8
- export * as MergedState from '../../base/merged-state.js';
4
+ import '../../globals';
5
+ export { CleanState } from './class';
6
+ export { useCleanState } from './hooks';
7
+ export type { TCleanState, TStateData, ExtractCleanStateData } from './hook-types';
8
+ export type { SF, StateFragment } from './class-types';
9
+ export * as MergedState from '../../base/merged-state';
@@ -1,6 +1,35 @@
1
+ "use strict";
1
2
  /**
2
3
  * @module CleanState
3
4
  */
4
- export { CleanState } from './class.js';
5
- export { useCleanState } from './hooks.js';
6
- export * as MergedState from '../../base/merged-state.js';
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"));
@@ -1,7 +1,6 @@
1
- import type React from 'react';
2
- import type { TPropsBase } from '../logic/index.js';
3
- import type { Extractor } from './types/extractor.js';
4
- import { ComponentInstance } from '../instance/index.js';
1
+ import type { TPropsBase } from '../logic';
2
+ import type { Extractor } from './types/extractor';
3
+ import { ComponentInstance } from '../instance';
5
4
  /**
6
5
  * @summary
7
6
  * A modern class component for React that is fully compatible with
@@ -66,14 +65,6 @@ export declare class ClassComponent<TProps extends TPropsBase = null> extends Co
66
65
  * Note that the callback argument is currently not supported.
67
66
  */
68
67
  readonly forceUpdate: VoidFunction;
69
- /**
70
- * A standard React function component that works like any
71
- * other function component and can be rendered as JSX.
72
- * \`<MyComponent.FC />\`
73
- */
74
- static _FC<T extends typeof ClassComponent>(this: T, props: InstanceType<T>['props']): JSX.Element | null;
75
- static _BoundFC: typeof this._FC | undefined;
76
- static get FC(): typeof ClassComponent._FC;
77
68
  /*************************************
78
69
  * Function Component Extractor *
79
70
  **************************************/
@@ -101,12 +92,8 @@ export declare class ClassComponent<TProps extends TPropsBase = null> extends Co
101
92
  * export default Button.RC;
102
93
  */
103
94
  static readonly extract: Extractor;
104
- /**
105
- * A standard React function component that works like any
106
- * other function component and can be rendered as JSX.
107
- * \`<MyComponent.RC />\`
108
- */
109
- static readonly RC: React.VoidFunctionComponent<object | EmptyObject>;
95
+ /** @see {@link ClassComponent.extract} */
96
+ static readonly FC: Extractor;
110
97
  }
111
98
  export { ClassComponent as Component };
112
99
  /** /