@cleanweb/react 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +30 -0
- package/build/base/index.d.ts +2 -0
- package/build/base/index.js +2 -0
- package/build/{class.d.ts → classy/class.d.ts} +2 -2
- package/build/{class.jsx → classy/class.jsx} +1 -1
- package/build/classy/index.d.ts +3 -0
- package/build/classy/index.js +3 -0
- package/build/{instance.js → classy/instance.js} +1 -1
- package/build/{logic.d.ts → classy/logic.d.ts} +1 -1
- package/build/{logic.js → classy/logic.js} +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/package.json +26 -7
- package/build/README.md +0 -0
- package/build/package.json +0 -43
- /package/build/{methods.d.ts → base/methods.d.ts} +0 -0
- /package/build/{methods.js → base/methods.js} +0 -0
- /package/build/{state.d.ts → base/state.d.ts} +0 -0
- /package/build/{state.js → base/state.js} +0 -0
- /package/build/{instance.d.ts → classy/instance.d.ts} +0 -0
package/README.md
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Structured React Function Components
|
2
|
+
This package provides a suite of tools for writing cleaner React function components. It is particularly useful for larger components with lots of state variables and multiple closure functions that need to access those variables. Below is a brief summary of the exported members. A more robust documentation is in the works.
|
3
|
+
|
4
|
+
## useCleanState
|
5
|
+
Example:
|
6
|
+
```jsx
|
7
|
+
const state1 = useCleanState(initialStateObject); // { myValue: 'initial-value' }
|
8
|
+
const state2 = useCleanState(initialStateGetter); // () => ({ myValue: 'initial-value' })
|
9
|
+
|
10
|
+
return (
|
11
|
+
{/* or state2.put.clicked(true) or state2.putMany({ clicked: true }) */}
|
12
|
+
<button onClick={() => state2.clicked = true }>
|
13
|
+
{state1.label}
|
14
|
+
</button>
|
15
|
+
)
|
16
|
+
```
|
17
|
+
|
18
|
+
## useMethods
|
19
|
+
To be finished
|
20
|
+
|
21
|
+
## useLogic
|
22
|
+
To be finished
|
23
|
+
|
24
|
+
## useInstance
|
25
|
+
To be finished
|
26
|
+
Define all of your component's logic and lifecycle effects in a seperate class. Allow your function component to remain neat as just a JSX template. Access the instance of your class within the template with the useInstance hook.
|
27
|
+
|
28
|
+
## ClassComponent
|
29
|
+
To be finished.
|
30
|
+
Wrap your function component in a class, allowing you to organize logic into discreet methods and work with a persistent instance throughout the component's lifecycle that's much easier to reason about. At it's core, your component remains a function component and maintains all features of function components.
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import type { ComponentInstanceConstructor } from '
|
1
|
+
import type { ComponentInstanceConstructor } from './instance';
|
2
2
|
import { FunctionComponent } from "react";
|
3
|
-
import { ComponentInstance } from '
|
3
|
+
import { ComponentInstance } from './instance';
|
4
4
|
type Obj = Record<string, any>;
|
5
5
|
type IComponentConstructor = ComponentInstanceConstructor<any, any, any> & typeof ClassComponent<any, any, any>;
|
6
6
|
export declare class ClassComponent<TState extends Obj, TProps extends Obj, THooks extends Obj> extends ComponentInstance<TState, TProps, THooks> {
|
@@ -14,7 +14,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
14
14
|
};
|
15
15
|
})();
|
16
16
|
import { useMemo } from "react";
|
17
|
-
import { ComponentInstance, useInstance } from '
|
17
|
+
import { ComponentInstance, useInstance } from './instance';
|
18
18
|
/** Provide more useful stack traces for otherwise non-specific function names. */
|
19
19
|
var setFunctionName = function (func, newName) {
|
20
20
|
try {
|
@@ -14,7 +14,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
14
14
|
};
|
15
15
|
})();
|
16
16
|
import { useEffect } from "react";
|
17
|
-
import { useMountState } from "
|
17
|
+
import { useMountState } from "../base/state";
|
18
18
|
import { ComponentLogic, useLogic } from "./logic";
|
19
19
|
export var noOp = function () { };
|
20
20
|
var ComponentInstance = /** @class */ (function (_super) {
|
package/build/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./classy";
|
package/build/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./classy";
|
package/package.json
CHANGED
@@ -1,29 +1,47 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cleanweb/react",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.2",
|
4
4
|
"description": "A suite of helpers for writing cleaner React function components.",
|
5
5
|
"engines": {
|
6
6
|
"node": ">=18"
|
7
7
|
},
|
8
8
|
"files": [
|
9
|
-
"build"
|
9
|
+
"build",
|
10
|
+
".npmrc"
|
10
11
|
],
|
12
|
+
"main": "build/index.js",
|
13
|
+
"exports": {
|
14
|
+
".": "./build/index.js",
|
15
|
+
"./base": "./build/base/index.js",
|
16
|
+
"./classy": "./build/classy/index.js",
|
17
|
+
"./state": "./build/base/state.js",
|
18
|
+
"./methods": "./build/base/methods.js",
|
19
|
+
"./logic": "./build/classy/logic",
|
20
|
+
"./instance": "./build/classy/instance",
|
21
|
+
"./class-component": "./build/classy/class",
|
22
|
+
"./full-class": "./build/classy/class"
|
23
|
+
},
|
11
24
|
"scripts": {
|
12
|
-
"
|
25
|
+
"prebuild": "rimraf ./build",
|
26
|
+
"build": "tsc && tsc-alias",
|
27
|
+
"postbuild": "copyfiles globals.d.ts tsconfig.json build",
|
28
|
+
"_": "",
|
13
29
|
"prepublishOnly": "npm run build",
|
14
|
-
"
|
30
|
+
"publish:patch": "npm version patch && npm publish",
|
31
|
+
"//postpublish": "cd ./mirror-pkg && npm publish && cd ..",
|
32
|
+
"__": "",
|
15
33
|
"test": "echo \"No tests ATM\""
|
16
34
|
},
|
17
35
|
"keywords": [
|
18
36
|
"react",
|
19
|
-
"clean-react",
|
20
|
-
"clean react",
|
21
37
|
"function components",
|
22
38
|
"hooks",
|
23
39
|
"react hooks",
|
40
|
+
"react state",
|
24
41
|
"state",
|
25
42
|
"clean state",
|
26
|
-
"group state"
|
43
|
+
"group state",
|
44
|
+
"grouped state"
|
27
45
|
],
|
28
46
|
"author": {
|
29
47
|
"name": "Feranmi Akinlade",
|
@@ -35,6 +53,7 @@
|
|
35
53
|
"@types/react": "^16",
|
36
54
|
"copyfiles": "^2.4.1",
|
37
55
|
"rimraf": "^6.0.1",
|
56
|
+
"tsc-alias": "1.8.10",
|
38
57
|
"typescript": "^5.6.2"
|
39
58
|
},
|
40
59
|
"peerDependencies": {
|
package/build/README.md
DELETED
File without changes
|
package/build/package.json
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "@cleanweb/react",
|
3
|
-
"version": "1.0.0",
|
4
|
-
"description": "A suite of helpers for writing cleaner React function components.",
|
5
|
-
"engines": {
|
6
|
-
"node": ">=18"
|
7
|
-
},
|
8
|
-
"files": [
|
9
|
-
"build"
|
10
|
-
],
|
11
|
-
"scripts": {
|
12
|
-
"build": "rimraf ./build && tsc && copyfiles README.md package.json .npmrc globals.d.ts tsconfig.json build",
|
13
|
-
"prepublishOnly": "npm run build",
|
14
|
-
"postpublish": "cd ./mirror-pkg && npm publish && cd ..",
|
15
|
-
"test": "echo \"No tests ATM\""
|
16
|
-
},
|
17
|
-
"keywords": [
|
18
|
-
"react",
|
19
|
-
"clean-react",
|
20
|
-
"clean react",
|
21
|
-
"function components",
|
22
|
-
"hooks",
|
23
|
-
"react hooks",
|
24
|
-
"state",
|
25
|
-
"clean state",
|
26
|
-
"group state"
|
27
|
-
],
|
28
|
-
"author": {
|
29
|
-
"name": "Feranmi Akinlade",
|
30
|
-
"url": "https://feranmi.dev"
|
31
|
-
},
|
32
|
-
"license": "MIT",
|
33
|
-
"devDependencies": {
|
34
|
-
"@types/node": "20.14.10",
|
35
|
-
"@types/react": "^16",
|
36
|
-
"copyfiles": "^2.4.1",
|
37
|
-
"rimraf": "^6.0.1",
|
38
|
-
"typescript": "^5.6.2"
|
39
|
-
},
|
40
|
-
"peerDependencies": {
|
41
|
-
"react": ">=16"
|
42
|
-
}
|
43
|
-
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|