Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MobX erases Native Objects #3412

Closed
jbis9051 opened this issue May 22, 2022 · 2 comments
Closed

MobX erases Native Objects #3412

jbis9051 opened this issue May 22, 2022 · 2 comments
Labels

Comments

@jbis9051
Copy link

jbis9051 commented May 22, 2022

MobX seems to be erasing my native pointers. (To clarify, I am using MobX without React.)

  // `state` is a mobx store created with `makeAutoObservable(this)`
  const instance = rust.new_instance(); // returns a pointer
  console.log(instance); // [External: 600000d44240]
  state.directHostInstance = instance; // Copy to a MobxStore
  console.log(state.directHostInstance); // {}
  console.log(toJS(state).directHostInstance); // {}

How can I get my [External: 600000d44240] back?

@urugator
Copy link
Collaborator

If instance is a plain object, mobx creates an observable copy during an assigment.
If instance should not become observable, you can mark the field as reference makeAutoObservable(this, { directHostInstance: observable.ref })
If it should become observale, you can make it observable manually prior assigment state.directHostInstance = makeAutoObservable(instance), but it's not possible to observe addition/removal of keys of such object.
https://mobx.js.org/observable-state.html#avoid-proxies

@urugator
Copy link
Collaborator

Closing for inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants