@bem-react/di
Advanced tools
Comparing version 1.5.2 to 1.5.3
@@ -59,3 +59,10 @@ 'use strict'; | ||
} | ||
var ComponentRegistryConsumer = function (props) { return (React.createElement(RegistryConsumer, null, function (registries) { return props.children(registries[props.id].snapshot()); })); }; | ||
var ComponentRegistryConsumer = function (props) { return (React.createElement(RegistryConsumer, null, function (registries) { | ||
{ | ||
if (!registries[props.id]) { | ||
throw new Error("Registry with id '" + props.id + "' not found."); | ||
} | ||
} | ||
return props.children(registries[props.id].snapshot()); | ||
})); }; | ||
var Registry = /** @class */ (function () { | ||
@@ -103,4 +110,5 @@ function Registry(_a) { | ||
Registry.prototype.merge = function (registry) { | ||
this.components = __assign({}, this.components, (registry ? registry.snapshot() : {})); | ||
return this; | ||
var clone = new Registry({ id: this.id, inverted: this.inverted }); | ||
clone.components = __assign({}, this.components, (registry ? registry.snapshot() : {})); | ||
return clone; | ||
}; | ||
@@ -107,0 +115,0 @@ return Registry; |
@@ -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 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=__assign({},r);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; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),__assign=function(){return(__assign=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},registryContext=React.createContext({}),RegistryProvider=registryContext.Provider,RegistryConsumer=registryContext.Consumer;function withRegistry(){for(var i=[],e=0;e<arguments.length;e++)i[e]=arguments[e];return function(t){var e=function(e){return React.createElement(RegistryConsumer,null,function(r){var n=__assign({},r);return i.forEach(function(e){var t=r[e.id];n[e.id]=e.inverted?t?e.merge(t):e:e&&t?t.merge(e):e}),React.createElement(RegistryProvider,{value:n},React.createElement(t,__assign({},e)))})};return e.displayName="RegistryResolver("+i.map(function(e){return e.id}).join(", ")+")",e}}var ComponentRegistryConsumer=function(t){return React.createElement(RegistryConsumer,null,function(e){return t.children(e[t.id].snapshot())})},Registry=function(){function r(e){var t=e.id,r=e.inverted,n=void 0!==r&&r;this.components={},this.id=t,this.inverted=n}return r.prototype.set=function(e,t){return this.components[e]=t,this},r.prototype.get=function(e){return this.components[e]},r.prototype.snapshot=function(){return this.components},r.prototype.merge=function(e){var t=new r({id:this.id,inverted:this.inverted});return t.components=__assign({},this.components,e?e.snapshot():{}),t},r}();exports.RegistryConsumer=RegistryConsumer,exports.withRegistry=withRegistry,exports.ComponentRegistryConsumer=ComponentRegistryConsumer,exports.Registry=Registry; |
@@ -6,2 +6,13 @@ # Change Log | ||
## [1.5.3](https://github.com/bem/bem-react/tree/master/packages/di/compare/@bem-react/di@1.5.2...@bem-react/di@1.5.3) (2019-03-01) | ||
### Bug Fixes | ||
* **di:** registers are overwritten in context ([a7b6377](https://github.com/bem/bem-react/tree/master/packages/di/commit/a7b6377)) | ||
## [1.5.2](https://github.com/bem/bem-react/tree/master/packages/di/compare/@bem-react/di@1.5.1...@bem-react/di@1.5.2) (2019-01-29) | ||
@@ -8,0 +19,0 @@ |
@@ -42,3 +42,3 @@ import React, { ComponentType } from 'react'; | ||
*/ | ||
merge(registry: Registry): this; | ||
merge(registry: Registry): Registry; | ||
} |
{ | ||
"name": "@bem-react/di", | ||
"version": "1.5.2", | ||
"version": "1.5.3", | ||
"description": "BEM React Dependency Injection", | ||
@@ -50,3 +50,3 @@ "repository": "https://github.com/bem/bem-react/tree/master/packages/di", | ||
}, | ||
"gitHead": "82551bf6017ad12325089616dfe85ab7be175d84" | ||
"gitHead": "44234ca2470324bfecb9ef393e0bc4718ab24780" | ||
} |
19272
167