immutable-assign
Advanced tools
Comparing version 1.0.17 to 1.0.18
@@ -10,2 +10,5 @@ // Place your settings in this file to overwrite default and user settings. | ||
} | ||
, | ||
"typescript.check.workspaceVersion": false, | ||
"editor.wordWrap": true | ||
} |
{ | ||
"name": "immutable-assign", | ||
"version": "1.0.17", | ||
"version": "1.0.18", | ||
"description": "", | ||
@@ -9,2 +9,3 @@ "main": "src/iassign.js", | ||
"test-karma": "node_modules\\.bin\\karma start", | ||
"test-karma-mac": "node_modules\\.bin\\karma start --browsers Safari,Chrome", | ||
"cover": "node_modules\\.bin\\istanbul cover node_modules\\jasmine\\bin\\jasmine.js", | ||
@@ -36,2 +37,3 @@ "build": "gulp" | ||
"deep-freeze": "0.0.1", | ||
"edge-launcher": "*", | ||
"gulp": "^3.9.1", | ||
@@ -44,3 +46,2 @@ "gulp-less": "^3.1.0", | ||
"karma-chrome-launcher": "^1.0.1", | ||
"edge-launcher": "*", | ||
"karma-firefox-launcher": "^1.0.0", | ||
@@ -50,2 +51,3 @@ "karma-ie-launcher": "^1.0.0", | ||
"karma-phantomjs-launcher": "^1.0.1", | ||
"karma-safari-launcher": "^1.0.0", | ||
"lodash": "^4.13.1", | ||
@@ -52,0 +54,0 @@ "merge2": "^1.0.2", |
# immutable-assign (iassign.js) | ||
Lightweight immutable helper that supports TypeScript type checking, and allows you to continue working with POJO (Plain Old JavaScript Object). | ||
Lightweight immutable helper that allows you to continue working with POJO (Plain Old JavaScript Object), and supports full TypeScript type checking | ||
@@ -9,12 +9,16 @@ This library is trying to solve following problems: | ||
* Encapsulated data is no more POJO, therefore cannot be easily used with other libraries, e.g., lodash, underscore, etc. | ||
* Most immutable libraries leak themselves throughout your entire application, however, they should have been encapsulated at the place where updates happen. This is also a pain when you need to change to another immutable library that has its own APIs. | ||
* Most immutable libraries leak themselves throughout your entire application (including view components), however, they should have been encapsulated at the place where updates happen (e.g., Redux reducers). This is also a pain when you need to change to another immutable library that has its own APIs. | ||
* [seamless-immutable](https://github.com/rtfeldman/seamless-immutable) address some of above issues when reading the properties, but still use verbose APIs to write properties. | ||
* [Immutability Helpers](https://facebook.github.io/react/docs/update.html) allows us to work with POJO, but it has still introduced some magic keywords, such as $set, $push, etc. | ||
* In addition, we lost TypeScript type checking. E.g., when calling nested2.getIn(['a', 'b', 'd']), TypeScript won't be able to warn me if I changed property 'd' to 'e'. | ||
* In addition, we lost TypeScript type checking. E.g., when calling nested2.getIn(["a", "b", "c"]), TypeScript won't be able to warn me if I changed property "c" to "d". | ||
This library has only one method **iassign()**, which accept a POJO object and return you a new POJO object with specific property updated. I have added some options to freeze input and output using [deep-freeze](https://github.com/substack/deep-freeze), which can be used in development to make sure they don't change unintentionally by us or the 3rd party libraries. | ||
This library will leave your POJO objects completely untouched (except the optional deep-freeze), it does not wrap around nor add methods/properties to your POJO objects. | ||
This library works in JavaScript and it works really well with TypeScript, because of its [generic type argument inference](https://www.typescriptlang.org/docs/handbook/generics.html); and since you are working with POJO (not the wrapper objects), you can utilize the full power of TypeScript: IntelliSense, type checking and refactoring, etc. | ||
## Performance | ||
Performance of this library should be comparable to [Immutable.js](https://facebook.github.io/immutable-js/), because read operations will always occur more than write operations. When using this library, all your react components can read object properties directly. E.g., you can use <TextBox value={this.state.userinfo.fullName} /> in your components, instead of <TextBox value={this.state.getIn(["userinfo", "fullName"])} />. I.e., the more read operations you have, the more it will outperform [Immutable.js](https://facebook.github.io/immutable-js/). | ||
Performance of this library should be comparable to [Immutable.js](https://facebook.github.io/immutable-js/), because read operations will always occur more than write operations. When using this library, all your react components can read object properties directly. E.g., you can use <TextBox value={this.state.userinfo.fullName} /> in your components, instead of <TextBox value={this.state.getIn(["userinfo", "fullName"])} />. In addition, shouldComponentUpdate() can compare POJO objects without knowing about the immutable libraries, e.g., return this.props.userInfo.orders !== nextProps.userInfos.orders. I.e., the more read operations you have, the more it will outperform [Immutable.js](https://facebook.github.io/immutable-js/). | ||
@@ -41,2 +45,7 @@ ##Install with npm | ||
freezeOutput: boolean; // Deep freeze output | ||
// Disable validation for extra statements in the getProp() function, | ||
// which is needed when running the coverage, e.g., istanbul.js does add | ||
// instrument statements in our getProp() function, which can be safely ignored. | ||
disableExtraStatementCheck: boolean; | ||
} | ||
@@ -197,8 +206,9 @@ ``` | ||
* getProp() must be pure function; I.e., it cannot access anything other than the input parameters. e.g., it must not access "this" or "window" objects. In addition, it must not modify the input parameters. It should only return a property that needs to be updated. | ||
* getProp() must be a pure function; I.e., it cannot access anything other than the input parameters. e.g., it must not access "this" or "window" objects. In addition, it must not modify the input parameters. It should only return a property that needs to be updated. | ||
##History | ||
* 1.0.18 - Tested on Mac (Safari 10 and Chrome 54) | ||
* 1.0.16 - Tested in Node.js and major browsers (IE 11, Chrome 52, Firefox 47, Edge 13, PhantomJS 2) | ||
@@ -10,3 +10,6 @@ | ||
disableHasReturnCheck: boolean; | ||
disableExtraStatementCheck: boolean; | ||
// Disable validation for extra statements in the getProp() function, | ||
// which is needed when running the coverage, e.g., istanbul.js does add | ||
// instrument statements in our getProp() function, which can be safely ignored. | ||
disableExtraStatementCheck: boolean; | ||
} | ||
@@ -13,0 +16,0 @@ |
@@ -9,5 +9,8 @@ "use strict"; | ||
freezeOutput: boolean; // Deep freeze output | ||
disableAllCheck: boolean; | ||
disableAllCheck: boolean; | ||
disableHasReturnCheck: boolean; | ||
disableExtraStatementCheck: boolean; | ||
// Disable validation for extra statements in the getProp() function, | ||
// which is needed when running the coverage, e.g., istanbul.js does add | ||
// instrument statements in our getProp() function, which can be safely ignored. | ||
disableExtraStatementCheck: boolean; | ||
} | ||
@@ -14,0 +17,0 @@ |
820129
23704
212
17