-
Notifications
You must be signed in to change notification settings - Fork 114
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
Flux / dispatcher usage #70
Comments
Hi! Thanks for the kind words.
Hope that helps! |
To clarify, the main purpose of Flux's non-singleton, everything-is-an-instance approach is to enable server-side rendering. It just also happens to have other benefits, like the ability for local Flux. But the recommended approach is still for a single, "global" Flux class. |
|
JavaScript passes objects by reference, so the fatness of the object makes no difference. Unless I misunderstood your question, which is possible :) |
Yeah, just wondering if it's ok to pass those "complex" objects as |
Using props is more explicit but it doesn't scale well. I suggest using FluxComponent: // entry point
// this adds flux to context
React.render(
<FluxComponent flux={flux}>
<App />
</Flux>
, el)
// elsewhere, use FluxComponent to access flux
<FluxComponent>
<Something /> // has flux prop
</FluxComponent> |
Yes, I meant this as The other option I saw somewhere was by using But yeah, I guess I can just wrap my 👍 |
|
Perfect, thanks for the help 👍 |
@acdlite hey sorry to bother you again. I've adjusted my example by wrapping a import Dispatcher from './Dispatcher'
let dispatcher = new Dispatcher()
let Application = React.createClass({
render() {
return (
<FluxComponent flux={dispatcher}>
<div>
<FluxComponent connectToStores="user">
<TopNav />
</FluxComponent>
<div>
<div>Left nav</div>
<div>Main content</div>
</div>
</div>
</FluxComponent>
)
}
})
export default Application
---
import Application from './Application'
React.render(<Application />, document.getElementById('app'))
# doesn't work!
# Uncaught Error: fluxMixin: Could not find Flux instance. Ensure that your component has either `this.context.flux` or `this.props.flux`. let Application = React.createClass({
render() {
return (
<div>
<FluxComponent connectToStores="user">
<TopNav />
</FluxComponent>
<div>
<div>Left nav</div>
<div>Main content</div>
</div>
</div>
)
}
})
export default Application
---
import Application from './Application'
import Dispatcher from './Dispatcher'
let dispatcher = new Dispatcher()
React.render(<FluxComponent flux={dispatcher}><Application /></FluxComponent>, document.getElementById('app'))
# it works! Any idea why? |
Ah, there is a very subtle difference. In React 0.12 and below, context is owner-based, not parent-based. (A component's owner is the one that renders it, whereas the parent is the one directly above it in the component tree.) So the first example will not work because the inner FluxComponent it does not have an owner who provides In React 0.13, context will be parent-based instead facebook/react#2112 |
Hmm ok I think I get it. Thanks for the explanation! :) |
No problem! Yes, I believe the first example should work in React 0.13. |
👍 |
This is incorrect. In 0.13, context is still owner-based, and a warning has been added in 0.13 to notify people of the upcoming switch to parent-based context. See facebook/react#3392 (comment) |
Yes you're right. |
Hi @acdlite,
first of all thx for making this library, it has really nice concepts and looks really promising.
I've been playing around a little with it and there are couple of things I'm not 100% sure, so I'd like to ask you ;)
Flux
container? Should I create one for the entire application with all actions / stores declared in it or should I create many of them and instantiate them only where needed (e.g.: one for general application usage, one for a specific page, ...)?Thanks :)
The text was updated successfully, but these errors were encountered: