@bem-react/di
Advanced tools
Comparing version 1.6.0 to 2.0.0
@@ -6,2 +6,18 @@ # Change Log | ||
# [2.0.0](https://github.com/bem/bem-react/tree/master/packages/di/compare/@bem-react/di@1.6.0...@bem-react/di@2.0.0) (2019-05-24) | ||
### Features | ||
* **di:** replace inverted by overridable ([957a0fe](https://github.com/bem/bem-react/tree/master/packages/di/commit/957a0fe)) | ||
### BREAKING CHANGES | ||
* **di:** Set inverted flag by default and rename it to "overridable". | ||
# [1.6.0](https://github.com/bem/bem-react/tree/master/packages/di/compare/@bem-react/di@1.5.3...@bem-react/di@1.6.0) (2019-04-22) | ||
@@ -8,0 +24,0 @@ |
@@ -15,9 +15,9 @@ import React, { ReactNode, FunctionComponent, ComponentType } from 'react'; | ||
id: string; | ||
inverted?: boolean; | ||
overridable?: boolean; | ||
} | ||
export declare class Registry { | ||
id: string; | ||
inverted: boolean; | ||
overridable: boolean; | ||
private components; | ||
constructor({ id, inverted }: IRegistryOptions); | ||
constructor({ id, overridable }: IRegistryOptions); | ||
/** | ||
@@ -24,0 +24,0 @@ * Set react component in registry by id. |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./build/cjs/di.production.min.js'); | ||
module.exports = require('./build/di.production.min.js'); | ||
} else { | ||
module.exports = require('./build/cjs/di.development.js'); | ||
module.exports = require('./build/di.development.js'); | ||
} |
{ | ||
"name": "@bem-react/di", | ||
"version": "1.6.0", | ||
"version": "2.0.0", | ||
"description": "BEM React Dependency Injection", | ||
@@ -27,3 +27,3 @@ "homepage": "https://github.com/bem/bem-react", | ||
"prepublishOnly": "npm run build", | ||
"build": "PKG=di node ../../scripts/rollup/build.js", | ||
"build": "node ../../scripts/rollup/build.js", | ||
"lint": "__DEV__=1 tsc -p . --noEmit && tslint -p . -t stylish", | ||
@@ -52,3 +52,3 @@ "unit": "../../node_modules/.bin/mocha --opts ../../mocha.opts --", | ||
}, | ||
"gitHead": "f542664df66df1874065280f8ff52f74cb2663a4" | ||
"gitHead": "b2939f6e269850d7147889f2632fa6ed3fc1f7b4" | ||
} |
@@ -1,2 +0,2 @@ | ||
# Dependency Injection (DI) | ||
# @bem-react/di · [![npm (scoped)](https://img.shields.io/npm/v/@bem-react/di.svg)](https://www.npmjs.com/package/@bem-react/di) [![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/@bem-react/di.svg)](https://bundlephobia.com/result?p=@bem-react/di) | ||
@@ -12,3 +12,3 @@ **Dependency Injection (DI)** allows you to split React components into separate versions and comfortably switch them in the project whenever needed, e.g., to make a specific bundle. | ||
``` | ||
npm i @bem-react/di -S | ||
npm i -S @bem-react/di | ||
``` | ||
@@ -170,1 +170,28 @@ | ||
``` | ||
## Replacing components | ||
Components inside registry can be replaced (e.g. for experiments) by wrapping `withRegistry(...)(App)` with another registry. | ||
```ts | ||
import { Registry, withRegistry } from '@bem-react/di'; | ||
import { AppDesktop } from './App@desktop'; | ||
import { HeaderExperimental } from './experiments/Components/Header/Header'; | ||
const expRegistry = new Registry({ id: cnApp() }); | ||
// replacing original Header with HeaderExperimental | ||
registry.set('Header', HeaderExperimental); | ||
// AppDesktopExperimental will call App with HeaderExperimental as 'Header' | ||
export const AppDesktopExperimental = withRegistry(expRegistry)(AppDesktop); | ||
``` | ||
When `App` extracts components from registry *DI* actually takes all registries defined above and merges. By default higher defined registry overrides lower defined one. | ||
If at some point you want to create registry that wan't be overrided just call the constructor with `overridable: false`. | ||
```ts | ||
const boldRegistry = new Registry({ id: cnApp(), overridable: false }); | ||
``` |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
20994
2
196
168
1