- Notifications
You must be signed in to change notification settings - Fork0
A JavaScript library for transactional mutable updates
License
mutativejs/mutability
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A JavaScript library for transactional mutable updates based onMutative.
When we want to perform transactional updates on a mutable object, if an error is caught during the update process, the mutable update will not be applied at all. Otherwise, the mutable update will be applied to the mutable object. Therefore, we need a tool to implement this functionality.
yarn add mutative mutability
or with npm
npm install mutative mutability
import{mutate}from'mutability';test('base - mutate',()=>{constbaseState={a:{c:1,},};const{ patches, inversePatches}=mutate(baseState,(draft)=>{draft.a.c=2;});expect(baseState).toEqual({a:{c:2}});expect({ patches, inversePatches}).toEqual({patches:[{op:'replace',path:['a','c'],value:2,},],inversePatches:[{op:'replace',path:['a','c'],value:1,},],});apply(baseState,inversePatches);expect(baseState).toEqual({a:{c:1}});});test('base - mutate with error',()=>{constbaseState={a:{c:1,},b:{c:1,},};try{mutate(baseState,(draft)=>{draft.a.c=2;thrownewError('error');draft.b.c=2;});}catch(e){//}expect(baseState).toEqual({a:{c:1,},b:{c:1,},});});
Mutate the mutable object, and return the patches and inverse patches.
Apply the mutable update with patches.
Mutability isMIT licensed.
About
A JavaScript library for transactional mutable updates
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.