File tree Expand file tree Collapse file tree 4 files changed +19
-4
lines changed
Expand file tree Collapse file tree 4 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 88 Immutable ,
99 Immer ,
1010 enableMapSet ,
11- enablePatches
11+ enablePatches ,
12+ produceWithPatches
1213} from "../src/immer"
1314
1415enableMapSet ( )
@@ -162,6 +163,20 @@ it("can apply patches", () => {
162163 expect ( applyPatches ( { } , patches ) ) . toEqual ( { x : 4 } )
163164} )
164165
166+ it ( "can apply readonly patches" , ( ) => {
167+ const [ , patches ] : readonly [
168+ {
169+ x : number
170+ } ,
171+ readonly Patch [ ] ,
172+ readonly Patch [ ]
173+ ] = produceWithPatches ( { x : 3 } , d => {
174+ d . x ++
175+ } )
176+
177+ expect ( applyPatches ( { } , patches ) ) . toEqual ( { x : 4 } )
178+ } )
179+
165180describe ( "curried producer" , ( ) => {
166181 it ( "supports rest parameters" , ( ) => {
167182 type State = { readonly a : 1 }
Original file line number Diff line number Diff line change @@ -172,7 +172,7 @@ export class Immer implements ProducersFns {
172172 this . useStrictShallowCopy_ = value
173173 }
174174
175- applyPatches < T extends Objectish > ( base : T , patches : Patch [ ] ) : T {
175+ applyPatches < T extends Objectish > ( base : T , patches : readonly Patch [ ] ) : T {
176176 // If a patch replaces the entire state, take that replacement as base
177177 // before applying patches
178178 let i : number
Original file line number Diff line number Diff line change @@ -211,7 +211,7 @@ export function enablePatches() {
211211 } )
212212 }
213213
214- function applyPatches_ < T > ( draft : T , patches : Patch [ ] ) : T {
214+ function applyPatches_ < T > ( draft : T , patches : readonly Patch [ ] ) : T {
215215 patches . forEach ( patch => {
216216 const { path, op} = patch
217217
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ const plugins: {
2424 patches : Patch [ ] ,
2525 inversePatches : Patch [ ]
2626 ) : void
27- applyPatches_ < T > ( draft : T , patches : Patch [ ] ) : T
27+ applyPatches_ < T > ( draft : T , patches : readonly Patch [ ] ) : T
2828 }
2929 MapSet ?: {
3030 proxyMap_ < T extends AnyMap > ( target : T , parent ?: ImmerState ) : T
You can’t perform that action at this time.
0 commit comments