@bem-react/di
Advanced tools
Comparing version 2.2.3 to 2.2.4
@@ -28,17 +28,21 @@ 'use strict'; | ||
var RegistryResolver = function (props) { | ||
var providedRegistriesRef = React.useRef(null); | ||
return (React.createElement(RegistryConsumer, null, function (contextRegistries) { | ||
var providedRegistries = __assign({}, contextRegistries); | ||
for (var i = 0; i < registries.length; i++) { | ||
var registry = registries[i]; | ||
var overrides = contextRegistries[registry.id]; | ||
// eslint-disable-next-line no-nested-ternary | ||
providedRegistries[registry.id] = registry.overridable | ||
? overrides | ||
? registry.merge(overrides) | ||
: registry | ||
: registry && overrides | ||
? overrides.merge(registry) | ||
: registry; | ||
if (providedRegistriesRef.current === null) { | ||
var providedRegistries = __assign({}, contextRegistries); | ||
for (var i = 0; i < registries.length; i++) { | ||
var registry = registries[i]; | ||
var overrides = contextRegistries[registry.id]; | ||
// eslint-disable-next-line no-nested-ternary | ||
providedRegistries[registry.id] = registry.overridable | ||
? overrides | ||
? registry.merge(overrides) | ||
: registry | ||
: registry && overrides | ||
? overrides.merge(registry) | ||
: registry; | ||
} | ||
providedRegistriesRef.current = providedRegistries; | ||
} | ||
return (React.createElement(RegistryProvider, { value: providedRegistries }, React.createElement(Component, props))); | ||
return (React.createElement(RegistryProvider, { value: providedRegistriesRef.current }, React.createElement(Component, props))); | ||
})); | ||
@@ -45,0 +49,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
"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 o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},registryContext=React.createContext({}),RegistryProvider=registryContext.Provider,RegistryConsumer=registryContext.Consumer;function withRegistry(){var e=[].slice.call(arguments);return function(t){return function(r){return React.createElement(RegistryConsumer,null,function(n){for(var o=__assign({},n),s=0;s<e.length;s++){var i=e[s],u=n[i.id];o[i.id]=i.overridable?u?i.merge(u):i:i&&u?u.merge(i):i}return React.createElement(RegistryProvider,{value:o},React.createElement(t,r))})}}}var ComponentRegistryConsumer=function(e){return React.createElement(RegistryConsumer,null,function(t){return e.children(t[e.id].snapshot())})},useRegistries=function(){return React.useContext(registryContext)},useComponentRegistry=function(e){return useRegistries()[e].snapshot()},registryHocMark="RegistryHoc";function withBase(e){var t=function(){throw new Error("Not found base component for enhance HOC: "+e.toString())};return t.$symbol=registryHocMark,t.hoc=e,t}function isHoc(e){return e.$symbol===registryHocMark}var Registry=function(){function e(e){var t=e.id,r=e.overridable,n=void 0===r||r;this.components={},this.id=t,this.overridable=n}return e.prototype.set=function(e,t){return this.components[e]=t,this},e.prototype.extends=function(e,t){return this.components[e]=withBase(t),this},e.prototype.fill=function(e){for(var t in e)this.components[t]=e[t];return this},e.prototype.get=function(e){return this.components[e]},e.prototype.snapshot=function(){return this.components},e.prototype.merge=function(t){var r=new e({id:this.id,overridable:this.overridable});if(r.fill(this.components),!t)return r;var n=t.snapshot();for(var o in n)n.hasOwnProperty(o)&&(r.components[o]=this.mergeComponents(r.components[o],n[o]));return r},e.prototype.mergeComponents=function(e,t){return isHoc(t)&&e?isHoc(e)?withBase(function(r){return t.hoc(e.hoc(r))}):t.hoc(e):t},e}();exports.ComponentRegistryConsumer=ComponentRegistryConsumer,exports.Registry=Registry,exports.RegistryConsumer=RegistryConsumer,exports.registryContext=registryContext,exports.useComponentRegistry=useComponentRegistry,exports.useRegistries=useRegistries,exports.withRegistry=withRegistry; | ||
'use strict';function t(t){var e=function(){throw new Error("Not found base component for enhance HOC: "+t.toString())};return e.$symbol=c,e.hoc=t,e}function e(t){return t.$symbol===c}Object.defineProperty(exports,'__esModule',{value:1});var n=require('react'),r=function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])({}).hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},o=n.createContext({}),i=o.Provider,s=o.Consumer,u=function(){return n.useContext(o)},c='RegistryHoc',p=function(){function n(t){var e=t.id,n=t.overridable,r=void 0===n?1:n;this.components={},this.id=e,this.overridable=r}return n.prototype.set=function(t,e){return this.components[t]=e,this},n.prototype.extends=function(e,n){return this.components[e]=t(n),this},n.prototype.fill=function(t){for(var e in t)this.components[e]=t[e];return this},n.prototype.get=function(t){return this.components[t]},n.prototype.snapshot=function(){return this.components},n.prototype.merge=function(t){var e=new n({id:this.id,overridable:this.overridable});if(e.fill(this.components),!t)return e;var r=t.snapshot();for(var o in r)r.hasOwnProperty(o)&&(e.components[o]=this.mergeComponents(e.components[o],r[o]));return e},n.prototype.mergeComponents=function(n,r){return e(r)&&n?e(n)?t(function(t){return r.hoc(n.hoc(t))}):r.hoc(n):r},n}();exports.ComponentRegistryConsumer=function(t){return n.createElement(s,null,function(e){return t.children(e[t.id].snapshot())})},exports.Registry=p,exports.RegistryConsumer=s,exports.registryContext=o,exports.useComponentRegistry=function(t){return u()[t].snapshot()},exports.useRegistries=u,exports.withRegistry=function(){var t=[].slice.call(arguments);return function(e){return function(o){var u=n.useRef(null);return n.createElement(s,null,function(s){if(null===u.current){for(var c=r({},s),p=0;p<t.length;p++){var a=t[p],f=s[a.id];c[a.id]=a.overridable?f?a.merge(f):a:a&&f?f.merge(a):a}u.current=c}return n.createElement(i,{value:u.current},n.createElement(e,o))})}}}; |
@@ -6,2 +6,8 @@ # Change Log | ||
## [2.2.4](https://github.com/bem/bem-react/compare/@bem-react/di@2.2.3...@bem-react/di@2.2.4) (2020-04-02) | ||
### Bug Fixes | ||
- **di:** resolve [#551](https://github.com/bem/bem-react/issues/551) issue ([c4491a4](https://github.com/bem/bem-react/commit/c4491a44268bd61ec77316208b918c03abea65c8)) | ||
## [2.2.3](https://github.com/bem/bem-react/compare/@bem-react/di@2.2.2...@bem-react/di@2.2.3) (2020-03-12) | ||
@@ -8,0 +14,0 @@ |
{ | ||
"name": "@bem-react/di", | ||
"version": "2.2.3", | ||
"version": "2.2.4", | ||
"description": "BEM React Dependency Injection", | ||
@@ -49,3 +49,3 @@ "homepage": "https://github.com/bem/bem-react/tree/master/packages/di", | ||
}, | ||
"gitHead": "2d0812109bdb4f8d8d4d507e3585e51ddb556ed5" | ||
"gitHead": "05800170cddaa0f6bef4808c6de3adbf0982c16c" | ||
} |
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
43637
270