@cleanweb/react 1.1.1-beta.10 → 1.1.1-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/base/merged-state.d.ts +1 -0
- package/build/base/merged-state.js +1 -0
- package/build/base/state.d.ts +1 -0
- package/build/base/state.js +1 -0
- package/build/classy/class.d.ts +1 -0
- package/build/classy/class.js +10 -5
- package/build/classy/instance.d.ts +2 -2
- package/build/classy/logic.js +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +2 -1
- package/build/tsconfig.json +2 -0
- package/package.json +2 -2
@@ -12,6 +12,7 @@ var __assign = (this && this.__assign) || function () {
|
|
12
12
|
};
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
14
14
|
exports.useMergedState = void 0;
|
15
|
+
require("../globals");
|
15
16
|
var react_1 = require("react");
|
16
17
|
var MergedState = /** @class */ (function () {
|
17
18
|
function MergedState(initialState) {
|
package/build/base/state.d.ts
CHANGED
package/build/base/state.js
CHANGED
@@ -12,6 +12,7 @@ var __assign = (this && this.__assign) || function () {
|
|
12
12
|
};
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
14
14
|
exports.useCleanState = exports.useMountState = void 0;
|
15
|
+
require("../globals");
|
15
16
|
var react_1 = require("react");
|
16
17
|
/**
|
17
18
|
* Returns a value that is false before the component has been mounted,
|
package/build/classy/class.d.ts
CHANGED
@@ -2,6 +2,7 @@ import type { VoidFunctionComponent } from 'react';
|
|
2
2
|
import type { IComponentInstanceClass } from './instance';
|
3
3
|
import type { TStateData } from '../base';
|
4
4
|
import { ComponentInstance } from './instance';
|
5
|
+
export declare const useRerender: () => () => void;
|
5
6
|
type ComponentClassParams = ConstructorParameters<typeof ClassComponent>;
|
6
7
|
type o = object;
|
7
8
|
export interface IComponentClass<Instance extends ClassComponent<o, o, o> = ClassComponent, Params extends ComponentClassParams = ComponentClassParams> extends IComponentInstanceClass<Instance, Params> {
|
package/build/classy/class.js
CHANGED
@@ -15,7 +15,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
15
15
|
};
|
16
16
|
})();
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
18
|
-
exports.Use = exports.ClassComponent = void 0;
|
18
|
+
exports.Use = exports.ClassComponent = exports.useRerender = void 0;
|
19
19
|
var jsx_runtime_1 = require("react/jsx-runtime");
|
20
20
|
var react_1 = require("react");
|
21
21
|
var instance_1 = require("./instance");
|
@@ -41,6 +41,7 @@ var useRerender = function () {
|
|
41
41
|
var rerender = function () { return _forceRerender(Date.now()); };
|
42
42
|
return rerender;
|
43
43
|
};
|
44
|
+
exports.useRerender = useRerender;
|
44
45
|
;
|
45
46
|
var ClassComponent = /** @class */ (function (_super) {
|
46
47
|
__extends(ClassComponent, _super);
|
@@ -57,7 +58,7 @@ var ClassComponent = /** @class */ (function (_super) {
|
|
57
58
|
var Render = instance.Render, template = instance.template;
|
58
59
|
var _forceUpdate;
|
59
60
|
// @ts-expect-error (Cannot assign to 'forceUpdate' because it is a read-only property.ts(2540))
|
60
|
-
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.
|
61
|
+
instance.forceUpdate = (_forceUpdate = (0, exports.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`.
|
61
62
|
);
|
62
63
|
// Add calling component name to Render function name in stack traces.
|
63
64
|
(0, react_1.useMemo)(function () {
|
@@ -76,13 +77,17 @@ var ClassComponent = /** @class */ (function (_super) {
|
|
76
77
|
* state in the "before-render" stage of `Render`, since it will be attempting to update it's parent's
|
77
78
|
* state (i.e `Wrapper` component) rather than it's own state.
|
78
79
|
*
|
79
|
-
*
|
80
|
+
* Users should favor using the `template()` method instead. This way, we avoid
|
80
81
|
* establishing a component boundary between `Wrapper` and `Render`.
|
81
82
|
*
|
82
83
|
* Although, since beforeRender() is called earlier from a hook, this is probably
|
83
84
|
* a non-issue. It will only force users to move their logic into `beforeRender` instead
|
84
|
-
* of doing it directly in `Render`.
|
85
|
-
*
|
85
|
+
* of doing it directly in `Render`. Even if `template` is being used, the `beforeRender` method
|
86
|
+
* is the preferred location for such logic to maintain a high level of separation of concerns,
|
87
|
+
* which is what this library exists to provide.
|
88
|
+
*
|
89
|
+
* So there's probably no real value lost with the component boundary. Users should just use
|
90
|
+
* `beforeRender` + `template`.
|
86
91
|
**/
|
87
92
|
switch (typeof template) {
|
88
93
|
case 'undefined':
|
@@ -54,8 +54,8 @@ type InstanceClassParams = ConstructorParameters<typeof ComponentInstance<o, o,
|
|
54
54
|
export interface IComponentInstanceClass<Instance extends ComponentInstance<o, o, o> = ComponentInstance, Params extends InstanceClassParams = InstanceClassParams> extends IComponentLogicClass<Instance, Params> {
|
55
55
|
}
|
56
56
|
type UseInstance = {
|
57
|
-
<Class extends typeof ComponentInstance<HardEmptyObject, o, o>>(Methods: Class & IComponentInstanceClass<InstanceType<Class>>,
|
58
|
-
<Class extends typeof ComponentInstance<o, o, o>>(Methods: Class & IComponentInstanceClass<InstanceType<Class>>,
|
57
|
+
<Class extends typeof ComponentInstance<HardEmptyObject, o, o>>(Methods: Class & IComponentInstanceClass<InstanceType<Class>>, props?: HardEmptyObject): InstanceType<Class>;
|
58
|
+
<Class extends typeof ComponentInstance<o, o, o>>(Methods: Class & IComponentInstanceClass<InstanceType<Class>>, props: InstanceType<Class>['props']): InstanceType<Class>;
|
59
59
|
};
|
60
60
|
export declare const useInstance: UseInstance;
|
61
61
|
export {};
|
package/build/classy/logic.js
CHANGED
package/build/index.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from
|
1
|
+
export * from './classy';
|
package/build/index.js
CHANGED
@@ -16,7 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./classy"), exports);
|
18
18
|
// PS: Document component inheritance pattern with lifecycle callback arrays and namespaces.
|
19
|
-
// Due to react's remounting behaviour, components must externally track when some logic has run,
|
19
|
+
// Due to react's remounting behaviour, components must externally track when some logic has run,
|
20
|
+
// if it really really must only ever run once per mounted instance. Tricky to get right for components that may have multiple instance rendered simultaneously at different parts of a page.
|
20
21
|
// useCleanState => useState, separate call for each key
|
21
22
|
// useMergedState => useState, same call for all keys
|
22
23
|
// useMethods => useCallback
|
package/build/tsconfig.json
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cleanweb/react",
|
3
|
-
"version": "1.1.1-beta.
|
3
|
+
"version": "1.1.1-beta.12",
|
4
4
|
"description": "A suite of helpers for writing cleaner React function components.",
|
5
5
|
"engines": {
|
6
6
|
"node": ">=18"
|
@@ -30,7 +30,7 @@
|
|
30
30
|
"scripts": {
|
31
31
|
"prebuild": "rimraf ./build",
|
32
32
|
"build": "tsc && tsc-alias",
|
33
|
-
"postbuild": "copyfiles
|
33
|
+
"postbuild": "copyfiles tsconfig.json build",
|
34
34
|
"_": "",
|
35
35
|
"prepublishOnly": "npm run build",
|
36
36
|
"publish:patch": "npm version patch && npm publish",
|