Skip to content

@computed.shallow decorator #2437

@Amareis

Description

@Amareis

There is @computed.struct, but there is no shallow decorator. But if computed getter returns array it may be really good to shallow compare it!

import { observable, computed, autorun } from "mobx";

class Some {
  @observable items = [];

  @computed
  get actives() {
    return this.items.filter((i) => i.active);
  }
}

let s = new Some();
autorun(() => console.log(s.actives));
s.items.push({ active: false }); //will recompute actives!

Yep, computed.struct will prevent recomputing, but for big arrays of classes it will be unefficient. As I see in https://github.com/mobxjs/mobx/blob/master/src/v5/api/computed.ts it'll be three strings change.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions