ditox-react 2.3.1 → 2.4.1

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.
@@ -50,6 +50,28 @@ type DependencyContainerParams = {
50
50
  *
51
51
  */
52
52
  declare function DependencyContainer(params: DependencyContainerParams): ReactElement;
53
+ /**
54
+ * Provides a custom dependency container to React app
55
+ *
56
+ * @param params.container - a custom container
57
+ *
58
+ * @example
59
+ * ```tsx
60
+ * const container = useMemo(() => {
61
+ * return createContainer();
62
+ * }
63
+ *
64
+ * return (
65
+ * <CustomDependencyContainer container={container}>
66
+ * {children}
67
+ * </CustomDependencyContainer>
68
+ * );
69
+ * ```
70
+ */
71
+ declare function CustomDependencyContainer(params: {
72
+ children: ReactNode;
73
+ container: Container;
74
+ }): ReactElement;
53
75
 
54
76
  /**
55
77
  * @category Hook
@@ -104,4 +126,4 @@ declare function DependencyModule(params: {
104
126
  scope?: 'scoped' | 'singleton';
105
127
  }): ReactElement;
106
128
 
107
- export { DependencyContainer, DependencyContainerBinder, DependencyContainerParams, DependencyModule, useDependency, useDependencyContainer, useOptionalDependency };
129
+ export { CustomDependencyContainer, DependencyContainer, DependencyContainerBinder, DependencyContainerParams, DependencyModule, useDependency, useDependencyContainer, useOptionalDependency };
@@ -1,2 +1,2 @@
1
- import{createContainer as r,bindModule as n}from"ditox";import e,{createContext as t,useContext as o,useMemo as i,useEffect as u,useCallback as c}from"react";var v=t(void 0);function f(n){var t=n.children,c=n.root,f=n.binder,a=o(v),d=i((function(){var n=r(c?void 0:a);return null==f||f(n),n}),[f,a,c]);return u((function(){return function(){return d.removeAll()}}),[d]),e.createElement(v.Provider,{value:d},t)}function a(r){var n=o(v);if(!n&&"strict"===r)throw new Error("Container is not provided by DependencyContainer component");return n}function d(r){var n=a("strict");return i((function(){return n.resolve(r)}),[n,r])}function l(r){var n=a();return i((function(){return null==n?void 0:n.get(r)}),[n,r])}function m(r){var t=r.children,o=r.module,i=r.scope,u=c((function(r){return n(r,o,{scope:i})}),[o,i]);return e.createElement(f,{binder:u},t)}export{f as DependencyContainer,m as DependencyModule,d as useDependency,a as useDependencyContainer,l as useOptionalDependency};
1
+ import{createContainer as r,bindModule as n}from"ditox";import e,{createContext as t,useContext as o,useMemo as i,useEffect as u,useCallback as c}from"react";var v=t(void 0);function a(n){var t=n.children,c=n.root,a=n.binder,l=o(v),d=i((function(){var n=r(c?void 0:l);return null==a||a(n),n}),[a,l,c]);return u((function(){return function(){return d.removeAll()}}),[d]),e.createElement(v.Provider,{value:d},t)}function l(r){var n=r.children,t=r.container;return e.createElement(v.Provider,{value:t},n)}function d(r){var n=o(v);if(!n&&"strict"===r)throw new Error("Container is not provided by DependencyContainer component");return n}function f(r){var n=d("strict");return i((function(){return n.resolve(r)}),[n,r])}function m(r){var n=d();return i((function(){return null==n?void 0:n.get(r)}),[n,r])}function p(r){var t=r.children,o=r.module,i=r.scope,u=c((function(r){return n(r,o,{scope:i})}),[o,i]);return e.createElement(a,{binder:u},t)}export{l as CustomDependencyContainer,a as DependencyContainer,p as DependencyModule,f as useDependency,d as useDependencyContainer,m as useOptionalDependency};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
1
  export type { DependencyContainerBinder, DependencyContainerParams, } from './DependencyContainer';
2
- export { DependencyContainer } from './DependencyContainer';
2
+ export { CustomDependencyContainer, DependencyContainer, } from './DependencyContainer';
3
3
  export { useDependencyContainer, useDependency, useOptionalDependency, } from './hooks';
4
4
  export { DependencyModule } from './DependencyModule';
package/dist/cjs/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DependencyModule = exports.useOptionalDependency = exports.useDependency = exports.useDependencyContainer = exports.DependencyContainer = void 0;
3
+ exports.DependencyModule = exports.useOptionalDependency = exports.useDependency = exports.useDependencyContainer = exports.DependencyContainer = exports.CustomDependencyContainer = void 0;
4
4
  var DependencyContainer_1 = require("./DependencyContainer");
5
+ Object.defineProperty(exports, "CustomDependencyContainer", { enumerable: true, get: function () { return DependencyContainer_1.CustomDependencyContainer; } });
5
6
  Object.defineProperty(exports, "DependencyContainer", { enumerable: true, get: function () { return DependencyContainer_1.DependencyContainer; } });
6
7
  var hooks_1 = require("./hooks");
7
8
  Object.defineProperty(exports, "useDependencyContainer", { enumerable: true, get: function () { return hooks_1.useDependencyContainer; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAIA,6DAA0D;AAAlD,0HAAA,mBAAmB,OAAA;AAE3B,iCAIiB;AAHf,+GAAA,sBAAsB,OAAA;AACtB,sGAAA,aAAa,OAAA;AACb,8GAAA,qBAAqB,OAAA;AAGvB,uDAAoD;AAA5C,oHAAA,gBAAgB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAIA,6DAG+B;AAF7B,gIAAA,yBAAyB,OAAA;AACzB,0HAAA,mBAAmB,OAAA;AAGrB,iCAIiB;AAHf,+GAAA,sBAAsB,OAAA;AACtB,sGAAA,aAAa,OAAA;AACb,8GAAA,qBAAqB,OAAA;AAGvB,uDAAoD;AAA5C,oHAAA,gBAAgB,OAAA"}
@@ -1,4 +1,4 @@
1
1
  export type { DependencyContainerBinder, DependencyContainerParams, } from './DependencyContainer';
2
- export { DependencyContainer } from './DependencyContainer';
2
+ export { CustomDependencyContainer, DependencyContainer, } from './DependencyContainer';
3
3
  export { useDependencyContainer, useDependency, useOptionalDependency, } from './hooks';
4
4
  export { DependencyModule } from './DependencyModule';
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { DependencyContainer } from './DependencyContainer';
1
+ export { CustomDependencyContainer, DependencyContainer, } from './DependencyContainer';
2
2
  export { useDependencyContainer, useDependency, useOptionalDependency, } from './hooks';
3
3
  export { DependencyModule } from './DependencyModule';
4
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC"}
@@ -50,6 +50,28 @@ type DependencyContainerParams = {
50
50
  *
51
51
  */
52
52
  declare function DependencyContainer(params: DependencyContainerParams): ReactElement;
53
+ /**
54
+ * Provides a custom dependency container to React app
55
+ *
56
+ * @param params.container - a custom container
57
+ *
58
+ * @example
59
+ * ```tsx
60
+ * const container = useMemo(() => {
61
+ * return createContainer();
62
+ * }
63
+ *
64
+ * return (
65
+ * <CustomDependencyContainer container={container}>
66
+ * {children}
67
+ * </CustomDependencyContainer>
68
+ * );
69
+ * ```
70
+ */
71
+ declare function CustomDependencyContainer(params: {
72
+ children: ReactNode;
73
+ container: Container;
74
+ }): ReactElement;
53
75
 
54
76
  /**
55
77
  * @category Hook
@@ -104,4 +126,4 @@ declare function DependencyModule(params: {
104
126
  scope?: 'scoped' | 'singleton';
105
127
  }): ReactElement;
106
128
 
107
- export { DependencyContainer, DependencyContainerBinder, DependencyContainerParams, DependencyModule, useDependency, useDependencyContainer, useOptionalDependency };
129
+ export { CustomDependencyContainer, DependencyContainer, DependencyContainerBinder, DependencyContainerParams, DependencyModule, useDependency, useDependencyContainer, useOptionalDependency };
package/dist/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("ditox"),require("react")):"function"==typeof define&&define.amd?define(["exports","ditox","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).DitoxReact={},e.Ditox,e.React)}(this,(function(e,n,t){"use strict";var r=t.createContext(void 0);function o(e){var o=e.children,i=e.root,u=e.binder,c=t.useContext(r),d=t.useMemo((function(){var e=n.createContainer(i?void 0:c);return null==u||u(e),e}),[u,c,i]);return t.useEffect((function(){return function(){return d.removeAll()}}),[d]),t.createElement(r.Provider,{value:d},o)}function i(e){var n=t.useContext(r);if(!n&&"strict"===e)throw new Error("Container is not provided by DependencyContainer component");return n}e.DependencyContainer=o,e.DependencyModule=function(e){var r=e.children,i=e.module,u=e.scope,c=t.useCallback((function(e){return n.bindModule(e,i,{scope:u})}),[i,u]);return t.createElement(o,{binder:c},r)},e.useDependency=function(e){var n=i("strict");return t.useMemo((function(){return n.resolve(e)}),[n,e])},e.useDependencyContainer=i,e.useOptionalDependency=function(e){var n=i();return t.useMemo((function(){return null==n?void 0:n.get(e)}),[n,e])}}));
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("ditox"),require("react")):"function"==typeof define&&define.amd?define(["exports","ditox","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).DitoxReact={},e.Ditox,e.React)}(this,(function(e,n,t){"use strict";var r=t.createContext(void 0);function o(e){var o=e.children,i=e.root,u=e.binder,c=t.useContext(r),d=t.useMemo((function(){var e=n.createContainer(i?void 0:c);return null==u||u(e),e}),[u,c,i]);return t.useEffect((function(){return function(){return d.removeAll()}}),[d]),t.createElement(r.Provider,{value:d},o)}function i(e){var n=t.useContext(r);if(!n&&"strict"===e)throw new Error("Container is not provided by DependencyContainer component");return n}e.CustomDependencyContainer=function(e){var n=e.children,o=e.container;return t.createElement(r.Provider,{value:o},n)},e.DependencyContainer=o,e.DependencyModule=function(e){var r=e.children,i=e.module,u=e.scope,c=t.useCallback((function(e){return n.bindModule(e,i,{scope:u})}),[i,u]);return t.createElement(o,{binder:c},r)},e.useDependency=function(e){var n=i("strict");return t.useMemo((function(){return n.resolve(e)}),[n,e])},e.useDependencyContainer=i,e.useOptionalDependency=function(e){var n=i();return t.useMemo((function(){return null==n?void 0:n.get(e)}),[n,e])}}));
2
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ditox-react",
3
- "version": "2.3.1",
3
+ "version": "2.4.1",
4
4
  "description": "Dependency injection container for React.js",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -57,7 +57,7 @@
57
57
  "typedoc": "typedoc"
58
58
  },
59
59
  "dependencies": {
60
- "ditox": "2.3.1"
60
+ "ditox": "2.4.1"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
@@ -69,5 +69,5 @@
69
69
  "react-dom": "18.2.0",
70
70
  "react-test-renderer": "18.2.0"
71
71
  },
72
- "gitHead": "1e10e32350931dba38acc4d00b2cc1cd6d5cffb5"
72
+ "gitHead": "e9c66f51c861a7598ab73415d7b2041700bc6d69"
73
73
  }
package/src/index.ts CHANGED
@@ -2,7 +2,10 @@ export type {
2
2
  DependencyContainerBinder,
3
3
  DependencyContainerParams,
4
4
  } from './DependencyContainer';
5
- export {DependencyContainer} from './DependencyContainer';
5
+ export {
6
+ CustomDependencyContainer,
7
+ DependencyContainer,
8
+ } from './DependencyContainer';
6
9
 
7
10
  export {
8
11
  useDependencyContainer,