@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.
@@ -1,3 +1,4 @@
1
+ import '../globals';
1
2
  declare class MergedState<TState extends object> {
2
3
  static useRefresh<TState extends object>(this: MergedState<TState>): void;
3
4
  reservedKeys: string[];
@@ -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) {
@@ -1,3 +1,4 @@
1
+ import '../globals';
1
2
  /**
2
3
  * Returns a value that is false before the component has been mounted,
3
4
  * then true during all subsequent rerenders.
@@ -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,
@@ -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> {
@@ -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
- * Consider using this as a function call instead of JSX to avoid that. This way, we avoid
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`. This might mean cleaner Render functions,
85
- * so there's probably no real value lost if we keep the component boundary.
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>>, ...props: ([] | [HardEmptyObject])): InstanceType<Class>;
58
- <Class extends typeof ComponentInstance<o, o, o>>(Methods: Class & IComponentInstanceClass<InstanceType<Class>>, ...props: [InstanceType<Class>['props']]): 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 {};
@@ -56,7 +56,7 @@ testing: {
56
56
  }(ComponentLogic));
57
57
  ;
58
58
  MyComponentLogic.getInitialState;
59
- var self_1 = useLogic(MyComponentLogic, {});
59
+ // const self = useLogic(MyComponentLogic);
60
60
  }
61
61
  testing: {
62
62
  var A = /** @class */ (function (_super) {
package/build/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from "./classy";
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, 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.
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
@@ -35,10 +35,12 @@
35
35
  "exactOptionalPropertyTypes": true,
36
36
  },
37
37
  "include": [
38
+ // "**/[!globals].ts",
38
39
  "**/*.ts",
39
40
  "**/*.tsx"
40
41
  ],
41
42
  "exclude": [
43
+ "**/globals.ts",
42
44
  "node_modules/**/**.*",
43
45
  "build/**/**.*",
44
46
  "mirror-pkg/**/**.*"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cleanweb/react",
3
- "version": "1.1.1-beta.10",
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 globals.d.ts tsconfig.json build",
33
+ "postbuild": "copyfiles tsconfig.json build",
34
34
  "_": "",
35
35
  "prepublishOnly": "npm run build",
36
36
  "publish:patch": "npm version patch && npm publish",