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 pass this to link stores? #881

Closed
DanMossa opened this issue Nov 11, 2022 · 2 comments
Closed

How to pass this to link stores? #881

DanMossa opened this issue Nov 11, 2022 · 2 comments

Comments

@DanMossa
Copy link

DanMossa commented Nov 11, 2022

I see that in the js documentation this is how you link stores

class RootStore {
    constructor() {
        this.userStore = new UserStore(this)
        this.todoStore = new TodoStore(this)
    }
}

class UserStore {
    constructor(rootStore) {
        this.rootStore = rootStore
    }

    getTodos(user) {
        // Access todoStore through the root store.
        return this.rootStore.todoStore.todos.filter(todo => todo.author === user)
    }
}

class TodoStore {
    todos = []
    rootStore

    constructor(rootStore) {
        makeAutoObservable(this, { rootStore: false })
        this.rootStore = rootStore
    }
}

I'm confused as to how I can do this with mobx.

I have a RootStore

class RootStore = RootStoreBase with _$RootStore;

abstract class RootStoreBase with Store {
  // Not sure if this is correct either.
  late LikesStore likesStore;
  RootStoreBase() {
    likesStore = LikesStore(this);
  }
}

How can I set this up in my LikesStore?

@fzyzcjy
Copy link
Collaborator

fzyzcjy commented Nov 11, 2022

this as RootStore

@DanMossa
Copy link
Author

@fzyzcjy
So it's okay that inside RootStore it's late and not final?

And then I should pass this as RootStore even though it's RootStoreBase. Isn't that wrong though because it actually is the RootStoreBase? Or am I not understanding something?

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

No branches or pull requests

2 participants