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

How to extract from a model one prop to be an independent model so it can be used in other places #1583

Closed
2 tasks done
b-asaf opened this issue Sep 24, 2020 · 2 comments
Closed
2 tasks done
Labels
needs reproduction/info Needs more info or reproduction in order to fix it

Comments

@b-asaf
Copy link

b-asaf commented Sep 24, 2020

Question

  • I've checked documentation and searched for existing issues
  • I tried the spectrum channel

Hi,
I am trying to extract from a model one prop to be an independent model so it can be used in other places, What I have now is:

const ModelA = types
  .model('ModelA', {
    propA: XXXX,
    propB: type.enumaration('EnumName', Object.values(Enum)),
    propC: XXX,
})
....views()
....actions()
;
export default ModelA;

The above code is working fine. when I try to extract propB to a different model like this:

import ModelB from './PropBModel';
const ModelA = types
  .model('ModelA', {
    propA: XXXX,
    propB: ModelB,
    propC: XXX,
})
....views()
....actions()
;
export default ModelA;
-------------------
**PropBModel.js:** 

const ModelB = types
  .model('ModelB', {
    propB: type.enumaration('EnumName', Object.values(Enum)),
})
....views()
....actions()
;
export default ModelB;

I am getting: value [XXX] is not assignable to type: 'ModelB' (value is not plain object) I keep getting:value [one of the Object.values] is not assignable to type: 'EnumName' (Value is not a plain object)`

I think it similar to issue #1403 but I don't use type script at the moment.

I prefer NOT to use types.compose for readability.

@coolsoftwaretyler
Copy link
Collaborator

Hey @b-asaf - sorry that it took so long for anyone to get back to you here. I just wanted to check in and see if you're still having this issue or if it was ever resolved.

It's been almost three years now, so if this is no longer relevant to you, let me know and I can close it out.

If you'd like a better answer, it would be really helpful for me if you could fork this CodeSandbox and give me a reproduction of the issue you're having more specifically: https://codesandbox.io/s/awesome-shannon-uoriy0

If I don't hear back in about two weeks, I'll probably close it out.

@coolsoftwaretyler coolsoftwaretyler added the needs reproduction/info Needs more info or reproduction in order to fix it label Jun 28, 2023
@coolsoftwaretyler
Copy link
Collaborator

Been about two weeks here. Sorry we couldn't help more! Closin' out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reproduction/info Needs more info or reproduction in order to fix it
Projects
None yet
Development

No branches or pull requests

2 participants