https://github.com/wizardpisces/immutable-obj
https://github.com/wizardpisces/immutable-obj
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/wizardpisces/immutable-obj
- Owner: wizardpisces
- Created: 2016-01-11T07:23:40.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-23T03:48:54.000Z (about 9 years ago)
- Last Synced: 2025-02-12T02:34:18.119Z (2 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Regarding Issues
tool to access an obj and return a new one which share the common part
## Installation
[Use npm.](https://docs.npmjs.com/cli/install)
```
npm install --save-dev immutable-obj
```## API
```javascript
var update = require('immutable-obj');
/*
obj // {}
path //array which define a scope for the changing part,the rest will be shared
value //if path exist alter the path value else create the path then define the value
*/
var newObj = update(obj,path,value);update.isEqual(obj,newObj);//check if value is equal not reference,meant for react rerender check
```#usage
```javascriptvar a = {
province: {
address: {
zone: 'A',
info : {
lastName : 'ze'
}
}
},
c: {
x: [1,2,3],
y: [1,{name'liu'},3,4]
}
};var b = update(a, ['province','address','zone'], 'B');
console.log('a',a,'\n' ,'b',b,'\n', b.province.address.info === a.province.address.info);
var c = update(a, 'province.address.zone', 'C');
console.log('a',a,'\n' ,'c',c,'\n');
var d = update(a, ['c','y',1], {name:'liu'});
console.log(a,d,a==d,isEqual(a,d));//false true
```