New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-magnetic-di

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-magnetic-di - npm Package Compare versions

Comparing version 2.2.3 to 2.2.4

10

lib/cjs/babel/processor-di.js

@@ -25,6 +25,4 @@ "use strict";

ref.scope.push({
id: t.arrayPattern(dependencyIdentifiers),
init: t.callExpression(ref.node, [t.arrayExpression(args), getComponentDeclaration(t, ref.scope) || t.nullLiteral()])
});
statement.replaceWith(t.variableDeclaration('const', [t.variableDeclarator(t.arrayPattern(dependencyIdentifiers), t.callExpression(ref.node, [t.arrayExpression(args), getComponentDeclaration(t, ref.scope) || t.nullLiteral()]))]));
ref.scope.registerDeclaration(statement);
args.forEach(function (argIdentifier) {

@@ -38,7 +36,5 @@ // for each argument we get the dependency variable name

argIdentifier.name = name;
}); // remove the original statement
statement.remove();
});
}
module.exports = processReference;

@@ -23,6 +23,4 @@ var _require = require('./utils'),

ref.scope.push({
id: t.arrayPattern(dependencyIdentifiers),
init: t.callExpression(ref.node, [t.arrayExpression(args), getComponentDeclaration(t, ref.scope) || t.nullLiteral()])
});
statement.replaceWith(t.variableDeclaration('const', [t.variableDeclarator(t.arrayPattern(dependencyIdentifiers), t.callExpression(ref.node, [t.arrayExpression(args), getComponentDeclaration(t, ref.scope) || t.nullLiteral()]))]));
ref.scope.registerDeclaration(statement);
args.forEach(function (argIdentifier) {

@@ -36,7 +34,5 @@ // for each argument we get the dependency variable name

argIdentifier.name = name;
}); // remove the original statement
statement.remove();
});
}
module.exports = processReference;
{
"name": "react-magnetic-di",
"version": "2.2.3",
"version": "2.2.4",
"description": "Context driven dependency injection",

@@ -5,0 +5,0 @@ "keywords": [

@@ -128,3 +128,4 @@ <p align="center">

In the example above we replace all `Modal` and `useQuery` dependencies across all components in the tree with the custom versions. If you want to replace dependencies **only** for a specific component (or set of components) you can use the `target` prop:
In the example above we replace all `Modal` and `useQuery` dependencies across all components in the tree with the custom versions.
If you want to replace dependencies **only** for a specific component (or set of components) you can use the `target` prop:

@@ -145,3 +146,3 @@ ```jsx

The library also provides a `withDi` HOC in case you want to export components with dependencies alredy injected:
The library also provides a `withDi` HOC in case you want to export components with dependencies already injected:

@@ -159,4 +160,8 @@ ```jsx

`withDi` supports the same API as `DiProvider`, where `target` is the third argument of the HOC `withDi(MyComponent, [Modal], MyComponent)` in case you want to limit injection to a specific component only.
`withDi` supports the same API and capabilities as `DiProvider`, where `target` is the third argument of the HOC `withDi(MyComponent, [Modal], MyComponent)` in case you want to limit injection to a specific component only.
When you have the same dependency replaced multiple times, there are two behaviours that determine which injectable will "win":
- the one defined on the closest `DiProvider` wins. So you can declare more specific replacements by wrapping components with `DiProvider` or `withDi` and those will win over same type injectables on other top level `DiProvider`s
- the injectable defined last in the `use` array wins. So you can define common injectables but still override each type case by case (eg: `<DiProvider use={[...commonDeps, specificInjectable]}>`
### Configuration Options

@@ -177,5 +182,5 @@

## Eslint plugin and rules
## ESLint plugin and rules
In order to enforce better practices, this package exports some eslint rules:
In order to enforce better practices, this package exports some ESLint rules:

@@ -190,3 +195,3 @@ | rule | description | options |

The rules are exported from `react-magnetic-di/eslint-plugin`. Unfortunately Eslint does not allow plugins that are not npm packages, so rules needs to be imported via other means for now.
The rules are exported from `react-magnetic-di/eslint-plugin`. Unfortunately ESLint does not allow plugins that are not npm packages, so rules needs to be imported via other means for now.

@@ -200,4 +205,6 @@ ## Current limitations

## Can it be used without Babel plugin?
## FAQ
#### 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.

@@ -219,2 +226,3 @@

## Contributing

@@ -221,0 +229,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc