unadlib / mutative

Efficient immutable updates, 2-6x faster than naive handcrafted reducer, and more than 10x faster than Immer.
http://mutative.js.org/
MIT License
1.58k stars 18 forks source link

Ability to make Strict Mode the default #43

Open rynti opened 3 months ago

rynti commented 3 months ago

Hey there, I hope this is an okay place to ask this question.

I was wondering if there was any way to by default enable strict mode globally? I'd like to enable strict mode by default in a development build, and turn it off for production, but haven't found an ergonomic way to do that.

In your docs this is also the recommended way:

image

Would love to hear suggestions for users of this library on how they would go about doing that.

Thanks in advance!

unadlib commented 3 months ago

hi @rynti , you can use strict: process.env.NODE_ENV !== 'production' to enable strict mode by default in a development build.

For example,

create(
  { count: 0 },
  (draft) => {
    //
  },
  {
    strict: process.env.NODE_ENV !== "production",
  }
);