Skip to content

Bulk computed / Observing proxy / Observing result of Object.create ? #3276

Answered by urugator
IanBellomy asked this question in Q&A
Discussion options

You must be logged in to vote

Object.create

There is a quirk in impl https://mobx.js.org/observable-state.html#limitations (point 14), can't be changed until next major.

proxy

I think it should be possible to do something like (did not test):

const defaults = observable({}); // if immutable, observable is redundant
const userData = observable({});
const data = new Proxy(userData,{
    get(t,prop,r) {
       return Reflect.get(userData, prop, r) ?? Reflect.get(defaults, prop, r)
    }
    set(t,prop,val,r) {
       return Reflect.set(userData, prop, val, r);
    }
})

Other approaches to consider:
Change the API so you don't need the setting keys to be represented as fields, but eg get(Settings.EMAIL)/set(Settings.E…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by IanBellomy
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