Skip to content

Calling "replace" on an ObservableSet always changes events #3761

Description

@Nokel81

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"]);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions