react-magnetic-di
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -8,4 +8,4 @@ "use strict"; | ||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } | ||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } | ||
var _require = require('./constants'), | ||
@@ -12,0 +12,0 @@ PACKAGE_NAME = _require.PACKAGE_NAME, |
@@ -10,4 +10,4 @@ "use strict"; | ||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } | ||
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } | ||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } | ||
@@ -14,0 +14,0 @@ function injectable(from, implementation) { |
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } | ||
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } | ||
const { | ||
@@ -5,0 +5,0 @@ PACKAGE_NAME, |
{ | ||
"name": "react-magnetic-di", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "Context driven dependency injection", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -75,3 +75,6 @@ <p align="center"> | ||
// and the replacement implementation as second | ||
const fetchApiDi = injectable(fetchApi, jest.fn().mockResolvedValue('mock')); | ||
const fetchApiDi = injectable( | ||
fetchApi, | ||
jest.fn().mockResolvedValue({ data: 'mock' }) | ||
); | ||
@@ -275,4 +278,2 @@ const result = await runWithDi(() => myApiFetcher(), [fetchApiDi]); | ||
```` | ||
## ESLint plugin and rules | ||
@@ -298,2 +299,3 @@ | ||
- Targeting only works on named functions/classes, so it won't work on anonymous scopes (eg `export default () => { ... }` or `memo(() => { ... })`) | ||
- If you define an injectable as `global` then you lose the ability to "scope" that injectable to a section of the tree, so the override will apply "globally". As a result, when defining multiple global replacements for the same dependency, only the last one evaluated will apply. So be mindful when using it in a multi DiProvider setting. | ||
@@ -311,3 +313,3 @@ ## FAQ | ||
// It will print ['fetchApi'] | ||
```` | ||
``` | ||
@@ -314,0 +316,0 @@ One possible reason for it to happen is that the context has been lost. Typical occurrences are async or deeply nested functions (especially in React). |
@@ -13,10 +13,10 @@ declare module 'react-magnetic-di' { | ||
: Type extends ReadonlyArray<infer InferredArrayMember> | ||
? InferredArrayMember[] extends Type | ||
? readonly InferredArrayMember[] extends Type | ||
? ReadonlyArray<DeepPartial<InferredArrayMember>> // readonly list | ||
: Array<DeepPartial<InferredArrayMember>> // mutable list | ||
: DeepPartialObject<Type> // tuple | ||
: Type extends object | ||
? DeepPartialObject<Type> | ||
: Type | undefined; | ||
? InferredArrayMember[] extends Type | ||
? readonly InferredArrayMember[] extends Type | ||
? ReadonlyArray<DeepPartial<InferredArrayMember>> // readonly list | ||
: Array<DeepPartial<InferredArrayMember>> // mutable list | ||
: DeepPartialObject<Type> // tuple | ||
: Type extends object | ||
? DeepPartialObject<Type> | ||
: Type | undefined; | ||
@@ -36,4 +36,5 @@ type DeepPartialObject<Type> = { | ||
use: Injectable[]; | ||
children?: ReactNode; | ||
global?: boolean; | ||
target?: Function | Function[]; | ||
children?: ReactNode; | ||
}, | ||
@@ -51,2 +52,3 @@ { getDependencies: (deps: Dependency[]) => Dependency[] } | ||
displayName?: string; | ||
global?: boolean; | ||
target?: Function | Function[]; | ||
@@ -53,0 +55,0 @@ track?: boolean; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
129589
2542
319