@cleanweb/react 1.0.0 → 1.0.3
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/{methods.d.ts → base/methods.d.ts} +1 -1
- package/build/{methods.js → base/methods.js} +1 -1
- package/build/{state.js → base/state.js} +2 -2
- package/build/{class.d.ts → classy/class.d.ts} +4 -4
- package/build/{class.jsx → classy/class.js} +4 -3
- package/build/classy/index.d.ts +3 -0
- package/build/classy/index.js +3 -0
- package/build/{instance.d.ts → classy/instance.d.ts} +2 -1
- package/build/{instance.js → classy/instance.js} +3 -3
- package/build/{logic.d.ts → classy/logic.d.ts} +1 -1
- package/build/{logic.js → classy/logic.js} +2 -2
- package/build/globals.d.ts +0 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/tsconfig.json +1 -1
- package/package.json +26 -7
- package/build/README.md +0 -0
- package/build/package.json +0 -43
- /package/build/{state.d.ts → base/state.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.
|
@@ -9,7 +9,7 @@ var __assign = (this && this.__assign) || function () {
|
|
9
9
|
};
|
10
10
|
return __assign.apply(this, arguments);
|
11
11
|
};
|
12
|
-
import { useMemo } from
|
12
|
+
import { useMemo } from 'react';
|
13
13
|
var ComponentMethods = /** @class */ (function () {
|
14
14
|
function ComponentMethods() {
|
15
15
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { useEffect, useRef, useState } from
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
2
2
|
var _CleanState_ = /** @class */ (function () {
|
3
3
|
function _CleanState_(stateAndSetters) {
|
4
4
|
var _this = this;
|
@@ -18,7 +18,7 @@ var _CleanState_ = /** @class */ (function () {
|
|
18
18
|
if (reservedKeys.includes(key))
|
19
19
|
throw new Error("The name \"".concat(key, "\" is reserved by CleanState and cannot be used to index state variables. Please use a different key."));
|
20
20
|
_this._values_[key] = responseFromUseState[0], _this._setters_[key] = responseFromUseState[1];
|
21
|
-
|
21
|
+
// this.put[key] = this._setters_[key];
|
22
22
|
var self = _this;
|
23
23
|
Object.defineProperty(_this, key, {
|
24
24
|
get: function () {
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import type {
|
2
|
-
import {
|
3
|
-
import { ComponentInstance } from '
|
1
|
+
import type { FunctionComponent } from 'react';
|
2
|
+
import type { ComponentInstanceConstructor } from './instance';
|
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> {
|
7
7
|
Render: FunctionComponent<TProps>;
|
8
|
-
static FC: <IComponentType extends IComponentConstructor>(this: IComponentType, _Component?: IComponentType) => (props: InstanceType<IComponentType>["props"]) =>
|
8
|
+
static FC: <IComponentType extends IComponentConstructor>(this: IComponentType, _Component?: IComponentType) => (props: InstanceType<IComponentType>["props"]) => JSX.Element;
|
9
9
|
}
|
10
10
|
export {};
|
@@ -13,8 +13,9 @@ var __extends = (this && this.__extends) || (function () {
|
|
13
13
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14
14
|
};
|
15
15
|
})();
|
16
|
-
import {
|
17
|
-
import {
|
16
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
17
|
+
import { useMemo } from 'react';
|
18
|
+
import { ComponentInstance, useInstance } from './instance';
|
18
19
|
/** Provide more useful stack traces for otherwise non-specific function names. */
|
19
20
|
var setFunctionName = function (func, newName) {
|
20
21
|
try {
|
@@ -42,7 +43,7 @@ var ClassComponent = /** @class */ (function (_super) {
|
|
42
43
|
var Render = useInstance(Component, props).Render;
|
43
44
|
// Add calling component name to Render function name in stack traces.
|
44
45
|
useMemo(function () { return setFunctionName(Render, "".concat(Component.name, ".Render")); }, []);
|
45
|
-
return
|
46
|
+
return _jsx(Render, {});
|
46
47
|
};
|
47
48
|
// Include calling component name in wrapper function name on stack traces.
|
48
49
|
var wrapperName = "ClassComponent".concat(Wrapper.name, " > ").concat(Component.name);
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import type { ComponentLogicConstructor } from './logic';
|
2
|
+
import { ComponentLogic } from './logic';
|
2
3
|
type Obj = Record<string, any>;
|
3
4
|
type AsyncAllowedEffectCallback = () => IVoidFunction | Promise<IVoidFunction>;
|
4
5
|
export declare const noOp: () => void;
|
@@ -13,9 +13,9 @@ var __extends = (this && this.__extends) || (function () {
|
|
13
13
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14
14
|
};
|
15
15
|
})();
|
16
|
-
import { useEffect } from
|
17
|
-
import { useMountState } from
|
18
|
-
import { ComponentLogic, useLogic } from
|
16
|
+
import { useEffect } from 'react';
|
17
|
+
import { useMountState } from '../base/state';
|
18
|
+
import { ComponentLogic, useLogic } from './logic';
|
19
19
|
export var noOp = function () { };
|
20
20
|
var ComponentInstance = /** @class */ (function (_super) {
|
21
21
|
__extends(ComponentInstance, _super);
|
package/build/globals.d.ts
CHANGED
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/build/tsconfig.json
CHANGED
package/package.json
CHANGED
@@ -1,29 +1,47 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cleanweb/react",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.3",
|
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
|