react-obsidian 0.0.25 → 0.0.26

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/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  <br>⚠️ <b>Until we hit v1, Obsidian is not semver-compliant and all APIs are subject to change.</b></h5>
12
12
 
13
13
  ## Introduction
14
-
14
+ useButtonClick
15
15
  React Obsidian is a dependency injection framework for React and React Native applications. It allows you to inject dependencies effortlessly into hooks, components or classes. Separating the construction and consumption of dependencies is crucial to maintaining a readable and testable codebase.
16
16
 
17
17
  React Obsidian is guided by the principles of the Dependency Injection pattern, but does not strictly follow them. We allowed ourselves a degree of freedom when designing the library in order to reduce boilerplate code and library footprint.
@@ -115,7 +115,7 @@ const useButtonClick = ({ biLogger }: UseButtonPressProps): UseButtonPress => {
115
115
  };
116
116
 
117
117
  // Dependencies are injected from ApplicationGraph
118
- export default injectHook(usePress, ApplicationGraph);
118
+ export default injectHook(useButtonClick, ApplicationGraph);
119
119
 
120
120
  // Now that we exported the injected hook, we can use it in a component without the needed so provide its dependencies manually
121
121
  const Component = () => (
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentInjector.d.ts","sourceRoot":"","sources":["../../../../src/injectors/components/ComponentInjector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,MAAM,CAAC,CAAC,EACN,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAClC,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,GAChC,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAMtC,OAAO,CAAC,aAAa;CAUtB"}
1
+ {"version":3,"file":"ComponentInjector.d.ts","sourceRoot":"","sources":["../../../../src/injectors/components/ComponentInjector.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAGtD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,MAAM,CAAC,CAAC,EACN,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAClC,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,GAChC,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAMtC,OAAO,CAAC,aAAa;CAgBtB"}
@@ -30,6 +30,7 @@ var react_1 = __importStar(require("react"));
30
30
  var hoist_non_react_statics_1 = __importDefault(require("hoist-non-react-statics"));
31
31
  var PropsInjector_1 = __importDefault(require("./PropsInjector"));
32
32
  var useGraph_1 = __importDefault(require("./useGraph"));
33
+ var React_1 = require("../../utils/React");
33
34
  var ComponentInjector = /** @class */ (function () {
34
35
  function ComponentInjector() {
35
36
  }
@@ -38,10 +39,14 @@ var ComponentInjector = /** @class */ (function () {
38
39
  (0, hoist_non_react_statics_1.default)(Wrapped, Target);
39
40
  return Wrapped;
40
41
  };
41
- ComponentInjector.prototype.wrapComponent = function (Target, Graph) {
42
+ ComponentInjector.prototype.wrapComponent = function (InjectionCandidate, Graph) {
42
43
  return function (passedProps) {
43
44
  var graph = (0, useGraph_1.default)(Graph, passedProps);
44
- var proxiedProps = (0, react_1.useState)(new PropsInjector_1.default(graph).inject(passedProps))[0];
45
+ var _a = (0, react_1.useState)(new PropsInjector_1.default(graph).inject(passedProps)), proxiedProps = _a[0], setProxiedProps = _a[1];
46
+ (0, react_1.useEffect)(function () {
47
+ setProxiedProps(new PropsInjector_1.default(graph).inject(passedProps));
48
+ }, [passedProps]);
49
+ var Target = (0, React_1.isMemoizedComponent)(InjectionCandidate) ? InjectionCandidate.type : InjectionCandidate;
45
50
  return react_1.default.createElement(react_1.default.Fragment, null, Target(proxiedProps));
46
51
  };
47
52
  };
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentInjector.js","sourceRoot":"","sources":["../../../../src/injectors/components/ComponentInjector.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAwC;AACxC,oFAA2D;AAE3D,kEAA4C;AAC5C,wDAAkC;AAGlC;IAAA;IAoBA,CAAC;IAnBC,kCAAM,GAAN,UACE,MAAkC,EAClC,KAAiC;QAEjC,IAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAClD,IAAA,iCAAoB,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,yCAAa,GAArB,UACE,MAAkC,EAClC,KAAiC;QAEjC,OAAO,UAAC,WAAuB;YAC7B,IAAM,KAAK,GAAG,IAAA,kBAAQ,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC;YACpC,IAAA,YAAY,GAAI,IAAA,gBAAQ,EAAC,IAAI,uBAAa,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,GAA1D,CAA2D;YAC9E,OAAO,8DAAG,MAAM,CAAC,YAA4B,CAAC,CAAI,CAAC;QACrD,CAAC,CAAC;IACJ,CAAC;IACH,wBAAC;AAAD,CAAC,AApBD,IAoBC"}
1
+ {"version":3,"file":"ComponentInjector.js","sourceRoot":"","sources":["../../../../src/injectors/components/ComponentInjector.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAmD;AACnD,oFAA2D;AAE3D,kEAA4C;AAC5C,wDAAkC;AAElC,2CAAwD;AAExD;IAAA;IA0BA,CAAC;IAzBC,kCAAM,GAAN,UACE,MAAkC,EAClC,KAAiC;QAEjC,IAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAClD,IAAA,iCAAoB,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QACtC,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,yCAAa,GAArB,UACE,kBAA8C,EAC9C,KAAiC;QAEjC,OAAO,UAAC,WAAuB;YAC7B,IAAM,KAAK,GAAG,IAAA,kBAAQ,EAAC,KAAK,EAAE,WAAW,CAAC,CAAC;YACrC,IAAA,KAAkC,IAAA,gBAAQ,EAAC,IAAI,uBAAa,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAvF,YAAY,QAAA,EAAE,eAAe,QAA0D,CAAC;YAE/F,IAAA,iBAAS,EAAC;gBACR,eAAe,CAAC,IAAI,uBAAa,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;YAChE,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;YAElB,IAAM,MAAM,GAAG,IAAA,2BAAmB,EAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAkB,CAAC;YACtG,OAAO,8DAAG,MAAM,CAAC,YAA4B,CAAC,CAAI,CAAC;QACrD,CAAC,CAAC;IACJ,CAAC;IACH,wBAAC;AAAD,CAAC,AA1BD,IA0BC"}
@@ -0,0 +1,5 @@
1
+ import { FunctionComponent } from 'react';
2
+ declare type MemoizedComponent = React.MemoExoticComponent<FunctionComponent<any>>;
3
+ export declare function isMemoizedComponent(component: FunctionComponent<any>): component is MemoizedComponent;
4
+ export {};
5
+ //# sourceMappingURL=React.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"React.d.ts","sourceRoot":"","sources":["../../../src/utils/React.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAE1C,aAAK,iBAAiB,GAAG,KAAK,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC;AAC3E,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,iBAAiB,CAAC,GAAG,CAAC,GAAG,SAAS,IAAI,iBAAiB,CAErG"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isMemoizedComponent = void 0;
4
+ function isMemoizedComponent(component) {
5
+ return component.type !== undefined;
6
+ }
7
+ exports.isMemoizedComponent = isMemoizedComponent;
8
+ //# sourceMappingURL=React.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"React.js","sourceRoot":"","sources":["../../../src/utils/React.ts"],"names":[],"mappings":";;;AAGA,SAAgB,mBAAmB,CAAC,SAAiC;IACnE,OAAQ,SAA+B,CAAC,IAAI,KAAK,SAAS,CAAC;AAC7D,CAAC;AAFD,kDAEC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-obsidian",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "description": "Dependency injection framework for React and React Native applications",
5
5
  "scripts": {
6
6
  "prepack": "npm run lint && tsc --project tsconfig.prod.json",
@@ -1,9 +1,10 @@
1
- import React, { useState } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import hoistNonReactStatics from 'hoist-non-react-statics';
3
3
  import { ObjectGraph } from '../../graph/ObjectGraph';
4
4
  import PropsInjector from './PropsInjector';
5
5
  import useGraph from './useGraph';
6
6
  import { Constructable } from '../../types';
7
+ import { isMemoizedComponent } from '../../utils/React';
7
8
 
8
9
  export default class ComponentInjector {
9
10
  inject<P>(
@@ -16,12 +17,18 @@ export default class ComponentInjector {
16
17
  }
17
18
 
18
19
  private wrapComponent<P>(
19
- Target: React.FunctionComponent<P>,
20
+ InjectionCandidate: React.FunctionComponent<P>,
20
21
  Graph: Constructable<ObjectGraph>,
21
22
  ): React.FunctionComponent<Partial<P>> {
22
23
  return (passedProps: Partial<P>) => {
23
24
  const graph = useGraph(Graph, passedProps);
24
- const [proxiedProps] = useState(new PropsInjector(graph).inject(passedProps));
25
+ const [proxiedProps, setProxiedProps] = useState(new PropsInjector(graph).inject(passedProps));
26
+
27
+ useEffect(() => {
28
+ setProxiedProps(new PropsInjector(graph).inject(passedProps));
29
+ }, [passedProps]);
30
+
31
+ const Target = isMemoizedComponent(InjectionCandidate) ? InjectionCandidate.type : InjectionCandidate;
25
32
  return <>{Target(proxiedProps as unknown as P)}</>;
26
33
  };
27
34
  }
@@ -0,0 +1,6 @@
1
+ import { FunctionComponent } from 'react';
2
+
3
+ type MemoizedComponent = React.MemoExoticComponent<FunctionComponent<any>>;
4
+ export function isMemoizedComponent(component: FunctionComponent<any>): component is MemoizedComponent {
5
+ return (component as MemoizedComponent).type !== undefined;
6
+ }