@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 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.
@@ -0,0 +1,2 @@
1
+ export * from './state';
2
+ export * from './methods';
@@ -0,0 +1,2 @@
1
+ export * from './state';
2
+ export * from './methods';
@@ -1,4 +1,4 @@
1
- import type { CleanState } from "./state";
1
+ import type { CleanState } from './state';
2
2
  export declare class ComponentMethods<TState extends object, TProps extends object> {
3
3
  state: CleanState<TState>;
4
4
  props: TProps;
@@ -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 "react";
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 "react";
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
- _this.put[key] = _this._setters_[key];
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 { ComponentInstanceConstructor } from '@/instance';
2
- import { FunctionComponent } from "react";
3
- import { ComponentInstance } from '@/instance';
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"]) => import("react").JSX.Element;
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 { useMemo } from "react";
17
- import { ComponentInstance, useInstance } from '@/instance';
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 <Render />;
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);
@@ -0,0 +1,3 @@
1
+ export * from './logic';
2
+ export * from './instance';
3
+ export * from './class';
@@ -0,0 +1,3 @@
1
+ export * from './logic';
2
+ export * from './instance';
3
+ export * from './class';
@@ -1,4 +1,5 @@
1
- import { ComponentLogic, ComponentLogicConstructor } from "./logic";
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 "react";
17
- import { useMountState } from "./state";
18
- import { ComponentLogic, useLogic } from "./logic";
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);
@@ -1,4 +1,4 @@
1
- import type { CleanState } from "./state";
1
+ import type { CleanState } from '../base/state';
2
2
  export declare class ComponentLogic<TState extends object, TProps extends object, THooks extends object> {
3
3
  state: CleanState<TState>;
4
4
  props: TProps;
@@ -1,5 +1,5 @@
1
- import { useMemo } from "react";
2
- import { useCleanState } from "./state";
1
+ import { useMemo } from 'react';
2
+ import { useCleanState } from '../base/state';
3
3
  var ComponentLogic = /** @class */ (function () {
4
4
  function ComponentLogic() {
5
5
  }
@@ -18,7 +18,6 @@ type Constructor<
18
18
  * @example
19
19
  * ```js
20
20
  * const getNumber: AsyncFunction<number> = async () => {
21
- * await oneTickDelay();
22
21
  * return 5;
23
22
  * }
24
23
  * ```
@@ -0,0 +1 @@
1
+ export * from "./classy";
package/build/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./classy";
@@ -27,7 +27,7 @@
27
27
  "moduleResolution": "node",
28
28
  "resolveJsonModule": true,
29
29
  "isolatedModules": true,
30
- "jsx": "preserve",
30
+ "jsx": "react-jsx",
31
31
  "strictNullChecks": true
32
32
  },
33
33
  "include": [
package/package.json CHANGED
@@ -1,29 +1,47 @@
1
1
  {
2
2
  "name": "@cleanweb/react",
3
- "version": "1.0.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
- "build": "rimraf ./build && tsc && copyfiles README.md package.json .npmrc globals.d.ts tsconfig.json build",
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
- "postpublish": "cd ./mirror-pkg && npm publish && cd ..",
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
@@ -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