@bem-react/di
Advanced tools
Comparing version 1.3.1-dev.8 to 1.4.0-dev.1
@@ -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.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) | ||
### Features | ||
* **di:** the way to add typings for registry result ([b76e4e1](https://github.com/bem/bem-react/tree/master/packages/di/commit/b76e4e1)) | ||
# 1.3.0 (2018-12-21) | ||
@@ -8,0 +19,0 @@ |
11
di.d.ts
@@ -8,3 +8,3 @@ import React, { ComponentType } from 'react'; | ||
id: string; | ||
children: (registry: object) => React.ReactNode; | ||
children: (registry: any) => React.ReactNode; | ||
} | ||
@@ -34,3 +34,12 @@ export declare const ComponentRegistryConsumer: React.SFC<IComponentRegistryConsumer>; | ||
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.3.1-dev.8", | ||
"version": "1.4.0-dev.1", | ||
"description": "BEM React Dependency Injection", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/bem/bem-react/tree/master/packages/di", |
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
17771
159