Skip to content

Compressing patches #1976

Closed Answered by EmilTholin
BrianHung asked this question in Q&A
Oct 25, 2022 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Hi @BrianHung!

I just ported that Immer example to MST, and I don't think that is supported. I can't say for certain that it's unachievable, but I don't think it is right now.

import { applyPatch, applySnapshot, onPatch, types } from "mobx-state-tree";

const Model = types
  .model({
    a: 1,
    b: types.maybe(types.number)
  })
  .actions((self) => ({
    setA(a: number) {
      self.a = a;
    },
    setB(b: number) {
      self.b = b;
    },
    reset() {
      applySnapshot(self, {});
    }
  }));

const patches: any = [];
const compiledPatches: any = [];

const model = Model.create();
const dispose = onPatch(model, (patch) => patches.push(patch));

model.setB(9);
model.setA(3);
model.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@BrianHung
Comment options

Answer selected by EmilTholin
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants