@cleanweb/react 2.1.0 → 2.1.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.
- package/build/classy/class/index.d.ts +2 -1
- package/build/classy/instance/index.d.ts +2 -2
- package/build/classy/instance/types/hook.d.ts +3 -2
- package/build/classy/logic/index.d.ts +10 -6
- package/build/classy/logic/index.js +5 -0
- package/build/classy/logic/types/hook.d.ts +3 -4
- package/build/globals.d.ts +1 -0
- package/package.json +3 -1
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { Extractor } from './types/extractor';
|
2
2
|
import { ComponentInstance } from '../instance';
|
3
|
+
import { TPropsBase } from '../logic';
|
3
4
|
/**
|
4
5
|
* A superset of {@link ComponentInstance} that allows defining your
|
5
6
|
* component's JSX template directly inside the class.
|
@@ -8,7 +9,7 @@ import { ComponentInstance } from '../instance';
|
|
8
9
|
* making it easier to migrate older class components to the newer hooks-based system
|
9
10
|
* with little to no changes to their existing semantics/implementation.
|
10
11
|
*/
|
11
|
-
export declare class ClassComponent<TProps extends
|
12
|
+
export declare class ClassComponent<TProps extends TPropsBase = null> extends ComponentInstance<TProps> {
|
12
13
|
/**
|
13
14
|
* Analogous to {@link React.Component.render}. A function that returns
|
14
15
|
* your component's JSX template.
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { UseInstance } from './types/hook';
|
2
|
-
import { ComponentLogic } from '../../classy/logic';
|
2
|
+
import { ComponentLogic, type TPropsBase } from '../../classy/logic';
|
3
3
|
type AsyncAllowedEffectCallback = () => Awaitable<IVoidFunction>;
|
4
4
|
/** An empty function. It returns (void) without performing any operations. */
|
5
5
|
export declare const noOp: () => void;
|
@@ -10,7 +10,7 @@ export declare const noOp: () => void;
|
|
10
10
|
*
|
11
11
|
* @see https://github.com/cleanjsweb/neat-react#lifecycle-useinstance
|
12
12
|
*/
|
13
|
-
export declare class ComponentInstance<TProps extends
|
13
|
+
export declare class ComponentInstance<TProps extends TPropsBase = null> extends ComponentLogic<TProps> {
|
14
14
|
/**
|
15
15
|
* Runs only _before_ first render,
|
16
16
|
* i.e before the component instance is mounted.
|
@@ -1,6 +1,7 @@
|
|
1
|
+
import { TPropsBase } from '../../../classy/logic';
|
1
2
|
import { ComponentInstance } from '..';
|
2
|
-
type UIClassParam = typeof ComponentInstance<
|
3
|
-
type UIProplessClassParam = typeof ComponentInstance<
|
3
|
+
type UIClassParam = typeof ComponentInstance<NonNullable<TPropsBase>>;
|
4
|
+
type UIProplessClassParam = typeof ComponentInstance<null>;
|
4
5
|
export type UseInstance = {
|
5
6
|
<Class extends UIProplessClassParam>(Methods: Class): InstanceType<Class>;
|
6
7
|
<Class extends UIClassParam>(Methods: Class, props: InstanceType<Class>['props']): InstanceType<Class>;
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import type { TCleanState } from '../../base/state';
|
2
2
|
import type { UseLogic } from './types/hook';
|
3
|
-
export type
|
4
|
-
export type WeakEmpty = WeakEmptyObject;
|
3
|
+
export type TPropsBase = NonPrimitive | null;
|
5
4
|
/**
|
6
5
|
* Base class for a class that holds methods intended for use in a function component,
|
7
6
|
* as well as a static method for initializing state.
|
@@ -14,15 +13,16 @@ export type WeakEmpty = WeakEmptyObject;
|
|
14
13
|
*
|
15
14
|
* Call the {@link useLogic} hook inside your function component to instantiate the class.
|
16
15
|
*/
|
17
|
-
export declare class ComponentLogic<TProps extends
|
16
|
+
export declare class ComponentLogic<TProps extends TPropsBase = null> {
|
18
17
|
/**
|
19
18
|
* A {@link TCleanState | `CleanState`} object.
|
20
19
|
* Holds all of your component's state,
|
21
20
|
* and methods for conveniently manipulating those values.
|
21
|
+
* Initialiazed with the object returned from your `getInitialState` method.
|
22
22
|
*/
|
23
23
|
readonly state: TCleanState<ReturnType<this['getInitialState']>>;
|
24
|
-
/** The props
|
25
|
-
readonly props: TProps;
|
24
|
+
/** The props passed into your component at the time of rendering. */
|
25
|
+
readonly props: TProps extends null ? EmptyObject : TProps;
|
26
26
|
/**
|
27
27
|
* Values received from the hooks your component consumes.
|
28
28
|
* This holds the latest copy of the object returned by
|
@@ -34,7 +34,7 @@ export declare class ComponentLogic<TProps extends object = NonPrimitive> {
|
|
34
34
|
* It receives the initial `props` object and should return
|
35
35
|
* an object with the initial values for your component's state.
|
36
36
|
*/
|
37
|
-
getInitialState: (props?:
|
37
|
+
getInitialState: (props?: this["props"]) => object;
|
38
38
|
/**
|
39
39
|
* Call React hooks from here. If your component needs
|
40
40
|
* access to values return from the hooks you call,
|
@@ -45,6 +45,10 @@ export declare class ComponentLogic<TProps extends object = NonPrimitive> {
|
|
45
45
|
*/
|
46
46
|
useHooks: () => object | void;
|
47
47
|
}
|
48
|
+
/**
|
49
|
+
* @group Component Logic
|
50
|
+
* @category Classy
|
51
|
+
*/
|
48
52
|
export declare const useLogic: UseLogic;
|
49
53
|
/** /
|
50
54
|
testing: {
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useLogic = exports.ComponentLogic = void 0;
|
4
4
|
var react_1 = require("react");
|
5
5
|
var state_1 = require("../../base/state");
|
6
|
+
//////////////////////////////////
|
6
7
|
/**
|
7
8
|
* Base class for a class that holds methods intended for use in a function component,
|
8
9
|
* as well as a static method for initializing state.
|
@@ -37,6 +38,10 @@ var ComponentLogic = /** @class */ (function () {
|
|
37
38
|
}());
|
38
39
|
exports.ComponentLogic = ComponentLogic;
|
39
40
|
;
|
41
|
+
/**
|
42
|
+
* @group Component Logic
|
43
|
+
* @category Classy
|
44
|
+
*/
|
40
45
|
var useLogic = function () {
|
41
46
|
var _a;
|
42
47
|
var args = [];
|
@@ -1,10 +1,9 @@
|
|
1
|
-
import type { ComponentLogic } from '..';
|
1
|
+
import type { ComponentLogic, TPropsBase } from '..';
|
2
2
|
/*************************************
|
3
3
|
* # Hooks *
|
4
4
|
**************************************/
|
5
|
-
|
6
|
-
type
|
7
|
-
type ULProplessClassParam = typeof ComponentLogic<HardEmptyObject>;
|
5
|
+
type ULClassParam = typeof ComponentLogic<NonNullable<TPropsBase>>;
|
6
|
+
type ULProplessClassParam = typeof ComponentLogic<null>;
|
8
7
|
export type UseLogic = {
|
9
8
|
<Class extends ULProplessClassParam>(Methods: Class): InstanceType<Class>;
|
10
9
|
<Class extends ULClassParam>(Methods: Class, props: InstanceType<Class>['props']): InstanceType<Class>;
|
package/build/globals.d.ts
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cleanweb/react",
|
3
|
-
"version": "2.1.0",
|
3
|
+
"version": "2.1.1-beta.0",
|
4
4
|
"description": "A suite of helpers for writing cleaner React function components.",
|
5
5
|
"engines": {
|
6
6
|
"node": ">=18"
|
@@ -23,6 +23,7 @@
|
|
23
23
|
"scripts": {
|
24
24
|
"prebuild": "rimraf ./build",
|
25
25
|
"build": "tsc && tsc-alias",
|
26
|
+
"build:docs": "npx typedoc",
|
26
27
|
"postbuild": "copyfiles tsconfig.json build",
|
27
28
|
"_": "",
|
28
29
|
"prepublishOnly": "npm run build",
|
@@ -69,6 +70,7 @@
|
|
69
70
|
"globals": "^15.12.0",
|
70
71
|
"rimraf": "^6.0.1",
|
71
72
|
"tsc-alias": "1.8.10",
|
73
|
+
"typedoc-plugin-markdown": "^4.4.1",
|
72
74
|
"typescript": "^5.6.2"
|
73
75
|
},
|
74
76
|
"peerDependencies": {
|