react-services-injector
Advanced tools
Comparing version 1.0.0-rc.5 to 1.0.0-rc.6
@@ -102,3 +102,4 @@ 'use strict'; | ||
methods.forEach(function (method) { | ||
var descriptor = method.descriptor; | ||
var name = method.name, | ||
descriptor = method.descriptor; | ||
@@ -110,2 +111,4 @@ | ||
if (Helpers.isFunction(descriptor) && (name.indexOf('get') === 0 || name.indexOf('find') === 0)) return; | ||
var fn = instance[method.name]; | ||
@@ -227,12 +230,14 @@ | ||
value: function connect(component, options) { | ||
var ConnectedComponent = function (_component) { | ||
_inherits(ConnectedComponent, _component); | ||
var classes = {}; | ||
function ConnectedComponent(props) { | ||
_classCallCheck(this, ConnectedComponent); | ||
classes[component.name] = function (_component) { | ||
_inherits(_class, _component); | ||
return _possibleConstructorReturn(this, (ConnectedComponent.__proto__ || Object.getPrototypeOf(ConnectedComponent)).call(this, props)); | ||
function _class(props) { | ||
_classCallCheck(this, _class); | ||
return _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).call(this, props)); | ||
} | ||
_createClass(ConnectedComponent, [{ | ||
_createClass(_class, [{ | ||
key: 'componentWillMount', | ||
@@ -242,3 +247,3 @@ value: function componentWillMount() { | ||
if (_get(ConnectedComponent.prototype.__proto__ || Object.getPrototypeOf(ConnectedComponent.prototype), 'componentWillMount', this)) _get(ConnectedComponent.prototype.__proto__ || Object.getPrototypeOf(ConnectedComponent.prototype), 'componentWillMount', this).call(this); | ||
if (_get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'componentWillMount', this)) _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'componentWillMount', this).call(this); | ||
} | ||
@@ -250,11 +255,11 @@ }, { | ||
if (_get(ConnectedComponent.prototype.__proto__ || Object.getPrototypeOf(ConnectedComponent.prototype), 'componentWillUnmount', this)) _get(ConnectedComponent.prototype.__proto__ || Object.getPrototypeOf(ConnectedComponent.prototype), 'componentWillUnmount', this).call(this); | ||
if (_get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'componentWillUnmount', this)) _get(_class.prototype.__proto__ || Object.getPrototypeOf(_class.prototype), 'componentWillUnmount', this).call(this); | ||
} | ||
}]); | ||
return ConnectedComponent; | ||
return _class; | ||
}(component); | ||
try { | ||
Object.defineProperty(ConnectedComponent, 'name', { | ||
Object.defineProperty(classes[component.name], 'name', { | ||
get: function get() { | ||
@@ -266,3 +271,3 @@ return component.name; | ||
return ConnectedComponent; | ||
return classes[component.name]; | ||
} | ||
@@ -269,0 +274,0 @@ }]); |
17
index.js
@@ -60,3 +60,3 @@ let Service = function () { | ||
methods.forEach(method => { | ||
const {descriptor} = method; | ||
const {name, descriptor} = method; | ||
@@ -69,2 +69,5 @@ if (!Helpers.isFunction(descriptor) || descriptor.value === service) | ||
if (Helpers.isFunction(descriptor) && (name.indexOf('get') === 0 || name.indexOf('find') === 0)) | ||
return; | ||
const fn = instance[method.name]; | ||
@@ -147,3 +150,3 @@ | ||
instance, | ||
toRender | ||
toRender, | ||
}); | ||
@@ -164,3 +167,5 @@ | ||
connect(component, options) { | ||
class ConnectedComponent extends component { | ||
const classes = {}; | ||
classes[component.name] = class extends component { | ||
constructor(props) { | ||
@@ -183,6 +188,6 @@ super(props); | ||
} | ||
} | ||
}; | ||
try { | ||
Object.defineProperty(ConnectedComponent, 'name', { | ||
Object.defineProperty(classes[component.name], 'name', { | ||
get: () => component.name | ||
@@ -192,3 +197,3 @@ }); | ||
return ConnectedComponent; | ||
return classes[component.name]; | ||
} | ||
@@ -195,0 +200,0 @@ } |
{ | ||
"name": "react-services-injector", | ||
"version": "1.0.0-rc.5", | ||
"version": "1.0.0-rc.6", | ||
"description": "A library to create and use sigleton-services in your React application.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -45,3 +45,3 @@ React Services Injector | ||
> **Important!** You should use getters for any method that is not modifying any data in the service. If you use common function for that purpose, it may result into an infinite loop. Any non-getter methods of service will update components that specified the service in their `toRender` property. | ||
> **Important!** You should use getters for any method that is not modifying any data in the service. If you use common function for that purpose, it may result into an infinite loop. Any non-getter methods of service will update components that specified the service in their `toRender` property. Exceptions are methods that are starting with "get" or "find", for example `findSomethingById` — they will also not trigger rendering. | ||
@@ -127,3 +127,3 @@ Then, let's create a service that will automatically update the random number (`services/intervalService.js`): | ||
``` | ||
> **Important!** Second argument of `injector.connect` is object containing `toRender` array. `toRender` should contain names of services that render result of component depends on. You will be still able to use any service you want in the component. | ||
> **Important!** Second argument of `injector.connect` is object containing `toRender` array. `toRender` should contain names of services that render result of component depends on. You will be still able to use any service you want in the component. If you don't pass `toRender` property, injector will consider that the components rendering depends on every service, so please, don't forget to pass it. | ||
@@ -264,2 +264,2 @@ > **Note:** you shouldn't use services in the class constructor. You can't to, actually. Use it, for example, in the `componentWillMount` lifecycle method if you need something to be done once component is created. | ||
Please, feel free to create an issue any time if you find a bug or unexpected behavior. | ||
Feature requests are pretty much acceptable too. | ||
Feature requests are pretty much acceptable too. |
Sorry, the diff of this file is not supported yet
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
442
263
31444
6