@bem-react/di
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -48,4 +48,4 @@ 'use strict'; | ||
providedRegistries[registry.id] = registry.inverted | ||
? (overrides || registry) | ||
: (registry || overrides); | ||
? overrides ? registry.merge(overrides) : registry | ||
: (registry && overrides) ? overrides.merge(registry) : registry; | ||
}); | ||
@@ -91,5 +91,17 @@ return (React.createElement(RegistryProvider, { value: providedRegistries }, | ||
}; | ||
/** | ||
* Returns list of components from registry. | ||
*/ | ||
Registry.prototype.snapshot = function () { | ||
return this.components; | ||
}; | ||
/** | ||
* Override components by external registry. | ||
* | ||
* @param registry external registry | ||
*/ | ||
Registry.prototype.merge = function (registry) { | ||
this.components = __assign({}, this.components, (registry ? registry.snapshot() : {})); | ||
return this; | ||
}; | ||
return Registry; | ||
@@ -96,0 +108,0 @@ }()); |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),__assign=function(){return(__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)},registryContext=React.createContext({}),RegistryProvider=registryContext.Provider,RegistryConsumer=registryContext.Consumer;function withRegistry(){for(var i=[],t=0;t<arguments.length;t++)i[t]=arguments[t];return function(e){var t=function(t){return React.createElement(RegistryConsumer,null,function(r){var n={};return i.forEach(function(t){var e=r[t.id];n[t.id]=t.inverted?e||t:t||e}),React.createElement(RegistryProvider,{value:n},React.createElement(e,__assign({},t)))})};return t.displayName="RegistryResolver("+i.map(function(t){return t.id}).join(", ")+")",t}}var ComponentRegistryConsumer=function(e){return React.createElement(RegistryConsumer,null,function(t){return e.children(t[e.id].snapshot())})},Registry=function(){function t(t){var e=t.id,r=t.inverted,n=void 0!==r&&r;this.components={},this.id=e,this.inverted=n}return t.prototype.set=function(t,e){return this.components[t]=e,this},t.prototype.get=function(t){return this.components[t]},t.prototype.snapshot=function(){return this.components},t}();exports.RegistryConsumer=RegistryConsumer,exports.withRegistry=withRegistry,exports.ComponentRegistryConsumer=ComponentRegistryConsumer,exports.Registry=Registry; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),__assign=function(){return(__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var o in e=arguments[r])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},registryContext=React.createContext({}),RegistryProvider=registryContext.Provider,RegistryConsumer=registryContext.Consumer;function withRegistry(){for(var o=[],t=0;t<arguments.length;t++)o[t]=arguments[t];return function(e){var t=function(t){return React.createElement(RegistryConsumer,null,function(r){var n={};return o.forEach(function(t){var e=r[t.id];n[t.id]=t.inverted?e?t.merge(e):t:t&&e?e.merge(t):t}),React.createElement(RegistryProvider,{value:n},React.createElement(e,__assign({},t)))})};return t.displayName="RegistryResolver("+o.map(function(t){return t.id}).join(", ")+")",t}}var ComponentRegistryConsumer=function(e){return React.createElement(RegistryConsumer,null,function(t){return e.children(t[e.id].snapshot())})},Registry=function(){function t(t){var e=t.id,r=t.inverted,n=void 0!==r&&r;this.components={},this.id=e,this.inverted=n}return t.prototype.set=function(t,e){return this.components[t]=e,this},t.prototype.get=function(t){return this.components[t]},t.prototype.snapshot=function(){return this.components},t.prototype.merge=function(t){return this.components=__assign({},this.components,t?t.snapshot():{}),this},t}();exports.RegistryConsumer=RegistryConsumer,exports.withRegistry=withRegistry,exports.ComponentRegistryConsumer=ComponentRegistryConsumer,exports.Registry=Registry; |
@@ -6,2 +6,13 @@ # Change Log | ||
# [1.5.0](https://github.com/bem/bem-react/tree/master/packages/di/compare/@bem-react/di@1.4.0...@bem-react/di@1.5.0) (2019-01-10) | ||
### Features | ||
* **di:** partially registries merge ([7890e03](https://github.com/bem/bem-react/tree/master/packages/di/commit/7890e03)) | ||
# [1.4.0](https://github.com/bem/bem-react/tree/master/packages/di/compare/@bem-react/di@1.3.0...@bem-react/di@1.4.0) (2018-12-28) | ||
@@ -8,0 +19,0 @@ |
@@ -33,3 +33,12 @@ import React, { ComponentType } from 'react'; | ||
get<T>(id: string): ComponentType<T>; | ||
/** | ||
* Returns list of components from registry. | ||
*/ | ||
snapshot<RT>(): RT; | ||
/** | ||
* Override components by external registry. | ||
* | ||
* @param registry external registry | ||
*/ | ||
merge(registry: Registry): this; | ||
} |
{ | ||
"name": "@bem-react/di", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "BEM React Dependency Injection", | ||
@@ -50,3 +50,3 @@ "repository": "https://github.com/bem/bem-react/tree/master/packages/di", | ||
}, | ||
"gitHead": "c836d59cf9e8d3f9deb6305b8322426d22c95eca" | ||
"gitHead": "5b6f6188fdae8273ea9e966d2e7f74bee9cfe1bf" | ||
} |
18095
159