@bem-react/di
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -8,39 +8,2 @@ 'use strict'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
/* global Reflect, Promise */ | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || { | ||
__proto__: [] | ||
} instanceof Array && function (d, b) { | ||
d.__proto__ = b; | ||
} || function (d, b) { | ||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | ||
}; | ||
return extendStatics(d, b); | ||
}; | ||
function __extends(d, b) { | ||
extendStatics(d, b); | ||
function __() { | ||
this.constructor = d; | ||
} | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
} | ||
var __assign = function () { | ||
@@ -86,21 +49,23 @@ __assign = _assign || function __assign(t) { | ||
} | ||
var Registry = (function (_super) { | ||
__extends(Registry, _super); | ||
function Registry(options) { | ||
var _this = _super.call(this) || this; | ||
_this.inverted = false; | ||
_this.id = options.id; | ||
_this.inverted = options.inverted; | ||
return _this; | ||
var Registry = (function () { | ||
function Registry(_a) { | ||
var id = _a.id, _b = _a.inverted, inverted = _b === void 0 ? false : _b; | ||
this.components = new Map(); | ||
this.id = id; | ||
this.inverted = inverted; | ||
} | ||
Registry.prototype.set = function (id, component) { | ||
this.components.set(id, component); | ||
return this; | ||
}; | ||
Registry.prototype.get = function (id) { | ||
{ | ||
if (!this.has(id)) { | ||
if (!this.components.has(id)) { | ||
throw new Error("Component with id '" + id + "' not found."); | ||
} | ||
} | ||
return this.get(id); | ||
return this.components.get(id); | ||
}; | ||
return Registry; | ||
}(Map)); | ||
}()); | ||
@@ -107,0 +72,0 @@ exports.RegistryConsumer = RegistryConsumer; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _assign=require("object-assign"),React=require("react"),extendStatics=function(t,e){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function __extends(t,e){function r(){this.constructor=t}extendStatics(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var __assign=function(){return(__assign=_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 Registry=function(r){function t(t){var e=r.call(this)||this;return e.inverted=!1,e.id=t.id,e.inverted=t.inverted,e}return __extends(t,r),t.prototype.get=function(t){return this.get(t)},t}(Map);exports.RegistryConsumer=RegistryConsumer,exports.withRegistry=withRegistry,exports.Registry=Registry; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _assign=require("object-assign"),React=require("react"),__assign=function(){return(__assign=_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={};return i.forEach(function(e){var t=r[e.id];n[e.id]=e.inverted?t||e:e||t}),React.createElement(RegistryProvider,{value:n},React.createElement(t,__assign({},e)))})};return e.displayName="RegistryResolver("+i.map(function(e){return e.id}).join(", ")+")",e}}var Registry=function(){function e(e){var t=e.id,r=e.inverted,n=void 0!==r&&r;this.components=new Map,this.id=t,this.inverted=n}return e.prototype.set=function(e,t){return this.components.set(e,t),this},e.prototype.get=function(e){return this.components.get(e)},e}();exports.RegistryConsumer=RegistryConsumer,exports.withRegistry=withRegistry,exports.Registry=Registry; |
@@ -6,2 +6,14 @@ # Change Log | ||
<a name="1.0.1"></a> | ||
## [1.0.1](https://github.com/bem/bem-react-core/compare/@bem-react/di@0.2.4...@bem-react/di@1.0.1) (2018-10-02) | ||
### Bug Fixes | ||
* **di:** use map as class option for using in es5 ([7fd489f](https://github.com/bem/bem-react-core/commit/7fd489f)) | ||
<a name="1.0.0"></a> | ||
@@ -8,0 +20,0 @@ # [1.0.0](https://github.com/bem/bem-react-core/compare/@bem-react/di@0.2.4...@bem-react/di@1.0.0) (2018-09-20) |
14
di.d.ts
import * as React from 'react'; | ||
export declare const RegistryConsumer: React.ComponentType<React.ConsumerProps<Record<string, Registry>>>; | ||
export declare function withRegistry<P>(...registries: Registry[]): (Component: React.ComponentType<P>) => React.StatelessComponent<P>; | ||
export interface IRegistry { | ||
export interface IRegistryOptions { | ||
id: string; | ||
inverted?: true; | ||
inverted?: boolean; | ||
} | ||
export declare class Registry extends Map<any, any> { | ||
export declare class Registry { | ||
id: string; | ||
inverted?: boolean; | ||
constructor(options: IRegistry); | ||
get<P>(id: any): React.ComponentType<P>; | ||
inverted: boolean; | ||
private components; | ||
constructor({ id, inverted }: IRegistryOptions); | ||
set<T>(id: string, component: React.ComponentType<T>): this; | ||
get<T>(id: string): React.ComponentType<T>; | ||
} |
{ | ||
"name": "@bem-react/di", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "BEM React Dependency Injection", | ||
@@ -28,3 +28,3 @@ "repository": { | ||
"unit": "../../node_modules/.bin/mocha --opts ../../mocha.opts --", | ||
"test": "../../node_modules/.bin/nyc npm run unit test/*.test.ts" | ||
"test": "../../node_modules/.bin/nyc npm run unit test/*.test.tsx" | ||
}, | ||
@@ -50,3 +50,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "9a19c9c3f68d5388839a17ee40e4e185f74b967b" | ||
"gitHead": "b4f5b2b3085d5d6ebae06a03b3ba3e39274001e5" | ||
} |
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
2
7374
90