mutative icon indicating copy to clipboard operation
mutative copied to clipboard

Proposal: Support draft function return value with modified draft

Open unadlib opened this issue 1 year ago • 1 comments

Regarding return values, Mutative has the same behavior as Immer.

An draft function returned a new value and modified its draft. Either return a new value or modify the draft.

For example,

  expect(() => {
    const state = create({ a: 1 }, (draft) => {
      draft.a = 2;
      return {
        ...draft,
      };
    });
  }).toThrowError();

However, there is an irrational aspect to this approach. As long as a modified draft can be finalized, it should be allowed to return any value.

Therefore, we are considering allowing Mutative to support draft functions returning any value.

unadlib avatar Jan 12 '24 15:01 unadlib