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

Question Sir. #2

Closed
aap82 opened this issue Nov 23, 2016 · 1 comment
Closed

Question Sir. #2

aap82 opened this issue Nov 23, 2016 · 1 comment

Comments

@aap82
Copy link

aap82 commented Nov 23, 2016

Hey, so I was going through your code and stumbled upon this comment in store-utils.js w/r/t to linkStores fn().

// This function takes care of helping stores communicate with
// each other. If there is an array defined on any store named
// "linkedStores", the array elements (containing exact names of other stores)
// are used here to "inject" the actual store objects into that store
// so it can be access directly

Not being having a programming background whatsoever, this is exactly the thing I've been struggling with when working with mobx: how to access actions in two or more stores in the same code block. My question:

Is linking in this way performant?

I've never truly seen anything like this. It makes sense somewhat if the stores are quite small, which is in fact how I have mine structured. But it doesnt seem quite right at the same time. Again, i apologize if this is common knowledge is programming, but I had to ask this question.

cheers,
ap

@lostpebble
Copy link
Owner

lostpebble commented Dec 9, 2016

Hi, sorry for the late reply, I completely missed the notification on this.

Logically, I feel like there shouldn't be any affect on performance compared to any other solution that might connect stores together (if you know of one, please let me know), since the stores are still singletons- we're just referencing them and calling functions on them as we might in any other part of the code.

The only thing we have to be careful of is causing a loop between two stores calling the same functions on each other. But for my use case I mostly use it in a one way direction, that being mostly towards a UIStore to open up loading modals and other interface interactions.

To me as well, it doesn't seem quite right. But it works, and that's what counts I guess 😅 I'm always open to finding better ways to do it though!

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