react-magnetic-di
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -18,3 +18,3 @@ "use strict"; | ||
messages: { | ||
unsortedInjectable: 'Expected dependencie names to be sorted. ' + "'{{name}}' should be before '{{prevName}}'." | ||
unsortedInjectable: 'Expected dependencies to be ordered by name. ' + "'{{name}}' should be before '{{prevName}}'." | ||
} | ||
@@ -21,0 +21,0 @@ }, |
@@ -16,3 +16,3 @@ var _require = require('../utils'), | ||
messages: { | ||
unsortedInjectable: 'Expected dependencie names to be sorted. ' + "'{{name}}' should be before '{{prevName}}'." | ||
unsortedInjectable: 'Expected dependencies to be ordered by name. ' + "'{{name}}' should be before '{{prevName}}'." | ||
} | ||
@@ -19,0 +19,0 @@ }, |
{ | ||
"name": "react-magnetic-di", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "Context driven dependency injection", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -192,3 +192,23 @@ <p align="center"> | ||
- Does not support dynamic `use` and `target` props (changes are ignored) | ||
- Officially supports injecting only functions/classes. If you need to inject some other data types, create a simple getter and use that as dependency. | ||
- Does not replace default props (or default parameters in general): so dependencies provided as default parameters (eg `function MyComponent ({ modal = Modal }) { ... }`) will be ignored. If you accept the dependency as prop/argument you should inject it via prop/argument, as having a double injection strategy is just confusing. | ||
## Can it be used without Babel plugin? | ||
Yes, but you will have to handle variable assignment yourself, which is a bit verbose. In this mode `di` needs an array of dependencies as first argument and the component, or `null`, as second (to make `target` behaviour work). Moreover, `di` won't be removed on prod builds and ESLint rules are not currently compatible with this mode. | ||
```js | ||
import React, { Component } from 'react'; | ||
import { di } from 'react-magnetic-di'; | ||
import { Modal as ModalInj } from 'material-ui'; | ||
import { useQuery as useQueryInj } from 'react-apollo'; | ||
function MyComponent() { | ||
const [Modal, useQuery] = di([ModalInj, useQueryInj], MyComponent); | ||
const { data } = useQuery(); | ||
return <Modal>{data && 'Done!'}</Modal>; | ||
} | ||
``` | ||
## Contributing | ||
@@ -195,0 +215,0 @@ |
@@ -27,2 +27,8 @@ declare module 'react-magnetic-di' { | ||
function di(...dependencies: Dependency[]): void; | ||
/** allow using di without Babel */ | ||
function di<T extends Dependency>( | ||
dependencies: T[], | ||
self: ComponentType<any> | null | ||
): T[]; | ||
class di { | ||
@@ -29,0 +35,0 @@ /** @deprecated use injectable instead */ |
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
85962
1681
217