farwayer / mst-decorators

Class based MobX-State-Tree definitions
26 stars 1 forks source link

how connect with native way defined store? #2

Closed thisroot closed 5 years ago

thisroot commented 5 years ago

Sorry for spam, but i have some one question.

I was try to connect models defined with you decorators with root store, but get an error.

@model class BaseUser { @id userId @str login }

@model class UserModel extends BaseUser{ @maybe(str) firstName @maybe(str) secondName @maybe(str) phone @maybe(str) email }

const User = maybe(ref(UserModel))

@model class UsersModel { @map(User) users }

const Users = maybe(ref(UsersModel))

export { User, UserModel, Users, UsersModel }


- Root store

```js
import { types, Instance } from "mobx-state-tree"
import { Settings, SettingsModel, Setting, SettingModel } from "./Settings"
import { User, UserModel, Users, UsersModel } from "./User"

export const RootStore = types.model("RootStore", {
    users: Users,
})

export type RootStoreModel = Instance<typeof RootStore>
export type RootStoreEnv = {
    users: UsersModel
}

Invalid type definition for property 'users', it looks like you passed a function. Did you forget to invoke it, or did you intend to declare a view / action?

Can you help? or extend documentation? Thanks

farwayer commented 5 years ago

You can use getMstType() function to get native mst type.