mobx icon indicating copy to clipboard operation
mobx copied to clipboard

Calling "replace" on an `ObservableSet` always changes events

Open Nokel81 opened this issue 9 months ago • 1 comments

Current Behaviour:

ObservableSet.replace(...) necessarily emits a single DELETE event for every entry in the set and then a single ADD event for all the entries in the provided source.

Expected Behaviour: ObservableSet.replace(...) only emits DELETE events for those items in the set that are not in the provided source and then only emits ADD events for those new entries from the source.

versions:

mobx -> 6.10.9
import { observable, configure } from "mobx";

configure({
  enforceActions: "never"
});

const mySet = observable.set<string>(["some-initial-state"]);

mySet.observe(console.log);

// This should trigger an ADD event
mySet.add("some-second-element");

// This should trigger an ADD event
mySet.add("some-thrid-element");

// This should trigger a DELETE event
mySet.delete("some-initial-state");

// This should trigger no events, since it is in the same order and the same elements
mySet.replace(["some-second-element", "some-third-element"]);

Nokel81 avatar Sep 22 '23 13:09 Nokel81