react-services-injector
Advanced tools
Comparing version 1.0.0-rc.1 to 1.0.0-rc.2
@@ -170,13 +170,10 @@ 'use strict'; | ||
var services = injector.get(true); | ||
var toRender = Array.isArray(options && options.toRender) ? options.toRender.map(this.byName) : []; | ||
var toRender = Array.isArray(options && options.toRender) ? options.toRender.map(this.byName) : options ? [] : services; | ||
var toUse = Array.isArray(options && options.toUse) ? options.toUse.map(this.byName) : options ? [] : services; | ||
instance.services = this.toObject(services); | ||
instance.services = _extends(this.toObject(toRender), this.toObject(toUse)); | ||
this.components.push({ | ||
key: ++this.key, | ||
instance: instance, | ||
toRender: toRender, | ||
toUse: toUse | ||
toRender: toRender | ||
}); | ||
@@ -183,0 +180,0 @@ |
@@ -114,13 +114,10 @@ let Service = function () { | ||
const services = injector.get(true); | ||
const toRender = Array.isArray(options && options.toRender) ? options.toRender.map(this.byName) : []; | ||
const toRender = Array.isArray(options && options.toRender) ? options.toRender.map(this.byName) : options ? [] : services; | ||
const toUse = Array.isArray(options && options.toUse) ? options.toUse.map(this.byName) : options ? [] : services; | ||
instance.services = this.toObject(services); | ||
instance.services = Object.assign(this.toObject(toRender), this.toObject(toUse)); | ||
this.components.push({ | ||
key: ++this.key, | ||
instance, | ||
toRender, | ||
toUse | ||
toRender | ||
}); | ||
@@ -127,0 +124,0 @@ |
{ | ||
"name": "react-services-injector", | ||
"version": "1.0.0-rc.1", | ||
"version": "1.0.0-rc.2", | ||
"description": "A library to create and use sigleton-services in your React application.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -39,3 +39,3 @@ React Services Injector | ||
> **Important!** You should use getters for any methods, that are 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 `toUse` or `toRender` options. | ||
> **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. | ||
@@ -58,3 +58,3 @@ Then, let's create a service that will automatically update the random number (`services/intervalService.js`): | ||
serviceDidConnect() { | ||
const {Storage} = this.services; | ||
const {Storage} = this.services; //any service has access to all other services | ||
@@ -120,3 +120,3 @@ setInterval(() => this.enabled && Storage.changeNumber(), 1000); | ||
``` | ||
> **Important!** Second argument of `injector.connect` is object containing two arrays: `toRender` and `toUse`. `toRender` should contain names of services that render result of component depends on. Other services that you use in the component should be in the `toUse` array. | ||
> **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. | ||
@@ -150,4 +150,3 @@ > **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. | ||
export default injector.connect(Test, { | ||
toRender: ['IntervalService'], //render result depends only on IntervalService | ||
toUse: ['Storage'] //but we also need to use Storage | ||
toRender: ['IntervalService'] //render result depends only on IntervalService | ||
}); | ||
@@ -165,4 +164,7 @@ ``` | ||
#### Data modifying | ||
Never modify service fields from outside! Make a method for that. Don't use setters. | ||
Never modify service fields from outside! Make a method for that. Don't use setters. | ||
#### Helpers | ||
#### Data storing | ||
@@ -189,6 +191,6 @@ It's better (not always) to store pure data in the service class and format it in getters. | ||
#### `toRender` and `toUse` | ||
It's not important, but strongly recommended to pass options object to the `connect()` method. | ||
If you don't pass it, the component will be connected to all services. | ||
If you do pass, but don't specify one of `toRender` or `toUse` arrays, component will be connected only to specified services. | ||
#### `toRender` property | ||
It is important to pass options object to the `connect()` method. | ||
If you don't pass it, the component's render method won't be connected to any services. | ||
So it will be never updated. | ||
@@ -195,0 +197,0 @@ #### Dependencies |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
198
0
23810
340