https://github.com/leops/babel-plugin-immutability-helper
Like immutability-helper, at compile time
https://github.com/leops/babel-plugin-immutability-helper
Last synced: about 1 month ago
JSON representation
Like immutability-helper, at compile time
- Host: GitHub
- URL: https://github.com/leops/babel-plugin-immutability-helper
- Owner: leops
- Created: 2017-10-01T13:29:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-01T13:31:52.000Z (over 8 years ago)
- Last Synced: 2025-08-09T02:02:08.568Z (10 months ago)
- Language: JavaScript
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
babel-plugin-immutability-helper
==================================
A babel plugin providing an API similar to
[immutability-helper](https://github.com/kolodny/immutability-helper), with the
"update spec" resolved at compile time.
# Example
```javascript
import update from 'immutability-helper';
const state2 = update(state1, {
someObject: {
anArray: { $push: [4, 5, 6] },
anotherArray: { $unshift: [4, 5, 6] },
},
[dynamicKey]: {
prop: { $set: 'nextValue' },
$toggle: ['a'],
$unset: ['b'],
$merge: {
merged: 'value',
},
$apply: t => t,
},
});
```
```javascript
import update from 'immutability-helper';
const state2 = {
...state1,
someObject: {
...state1.someObject,
anArray: [...state1.someObject.anArray, 4, 5, 6],
anotherArray: [4, 5, 6, ...state1.someObject.anotherArray]
},
[dynamicKey]: (t => t)({
...state1[dynamicKey],
prop: 'nextValue',
a: !state1[dynamicKey].a,
b: undefined,
merged: 'value'
})
};
```
# Notable differences
- The `$splice` operation is not supported
- The `$unset` operation does not use the `delete` operator, but replaces the
value with the `undefined` constant
- No equality check is performed, most operations will **ALWAYS** return a new
object.
- Runtime extensions are of course unsupported
- This plugin cannot deoptimize to dynamic calls in unsupported cases