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

types.snapshotProcessor and types.reference #1297

Open
3 tasks done
kornacki opened this issue May 23, 2019 · 2 comments
Open
3 tasks done

types.snapshotProcessor and types.reference #1297

kornacki opened this issue May 23, 2019 · 2 comments
Labels
bug Confirmed bug

Comments

@kornacki
Copy link

Bug report

  • I've checked documentation and searched for existing issues
  • I've made sure my project is based on the latest MST version
  • Fork this code sandbox or another minimal reproduction.

Sandbox link or minimal reproduction code
https://codesandbox.io/s/mobxstatetree-todolist-gj3fx?fontsize=14

Describe the expected behavior
in models/LogsStore.js when I use SimpleLog without snapshotProcessor everything is OK,

but

when i try use SingleLog with snapshotProcessor in console log throw error:

Uncaught Error: [mobx-state-tree] Failed to resolve reference '2' to type 'SimpleLog' (from node: /highlighted)

Why used references not working with types.snapshotProcessor?

Thanks:)

@xaviergonz
Copy link
Contributor

Minimum code

export const SimpleLog = types.model("SimpleLog", {
  id: types.identifier
});

export const SingleLog = types.snapshotProcessor(SimpleLog, {
  preProcessor(sn) {
    return {
      id: `${sn.time}`
    };
  }
});

export const LogsStore = types.model("Logs", {
  ref: types.maybe(types.reference(SimpleLog)),
  obj: SingleLog
});

const Logs = LogsStore.create({
  ref: "2",
  obj: {
    time: "2"
  }
});

const r = Logs.ref;

TODO: add exception when types.reference is not passed a model type? (probably the same for safe ref)

@xaviergonz xaviergonz added the bug Confirmed bug label May 23, 2019
@kresli
Copy link

kresli commented Nov 3, 2020

is there any workaround for this issue?

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

No branches or pull requests

3 participants