Skip to content

Better object creation performance by defining getters/setters in the class prototype? #3268

Answered by urugator
hjkcai asked this question in General
Discussion options

You must be logged in to vote

If you don't need to support utilities like: isObservable, isObservableProp, observe*, intercept* just use the observable primitives for the individual fields, no need to "simulate" the administration object behind [$mobx] symbol.

constructor() {
  this._num = observable.box()
  this._computed = computed(() => this.num + 1)
}

get num() {
  return this._num.get();
}

set num(value) {
  this._num.set(value);
}

get computed() {
  this._computed.get();
}

* observe, intercept is supportable on the level of individual atoms, eg observe(obj._num, listener).

MobxHacked.prototype.method = action(MobxHacked.prototype.method)

That's correct

If you don't mind a bit worse UX (dunno if these object…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by hjkcai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants