@@ -37,11 +37,19 @@ export class Immer implements ProducersFns {
37
37
38
38
autoFreeze_ : boolean = true
39
39
40
- constructor ( config ?: { useProxies ?: boolean ; autoFreeze ?: boolean } ) {
40
+ strictModeEnabled_ : boolean = false
41
+
42
+ constructor ( config ?: {
43
+ useProxies ?: boolean
44
+ autoFreeze ?: boolean
45
+ strictMode ?: boolean
46
+ } ) {
41
47
if ( typeof config ?. useProxies === "boolean" )
42
48
this . setUseProxies ( config ! . useProxies )
43
49
if ( typeof config ?. autoFreeze === "boolean" )
44
50
this . setAutoFreeze ( config ! . autoFreeze )
51
+ if ( typeof config ?. strictMode === "boolean" )
52
+ this . setStrictMode ( config ! . strictMode )
45
53
this . produce = this . produce . bind ( this )
46
54
this . produceWithPatches = this . produceWithPatches . bind ( this )
47
55
}
@@ -183,6 +191,23 @@ export class Immer implements ProducersFns {
183
191
this . useProxies_ = value
184
192
}
185
193
194
+ /**
195
+ * Pass true to throw errors when attempting to access a non-draftable reference.
196
+ *
197
+ * By default, strict mode is disabled.
198
+ */
199
+ setStrictMode ( value : boolean ) {
200
+ this . strictModeEnabled_ = value
201
+ }
202
+
203
+ unsafe ( callback : ( ) => void ) {
204
+ const scope = getCurrentScope ( )
205
+
206
+ scope . unsafeNonDraftabledAllowed_ = true
207
+ callback ( )
208
+ scope . unsafeNonDraftabledAllowed_ = false
209
+ }
210
+
186
211
applyPatches ( base : Objectish , patches : Patch [ ] ) {
187
212
// If a patch replaces the entire state, take that replacement as base
188
213
// before applying patches
0 commit comments