-
Notifications
You must be signed in to change notification settings - Fork 184
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
Add Redux Support #839
Add Redux Support #839
Conversation
@@ -0,0 +1,60 @@ | |||
const Q = require('q'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer native promises -- no need to take a dep
const state = this.store.getState(); | ||
const stateKeys = Object.keys(this.stateWaitMap); | ||
|
||
for (let i = 0; i < stateKeys.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be easier to read if you used a forEach
?
Object.keys(this.stateWaitMap).forEach(stateKey => {
if (stateKey.promise.isPending()) {
when(stateProps) { | ||
const promises = stateProps.map((stateProp) => { | ||
if (!this.stateWaitMap.hasOwnProperty(stateProp)) { | ||
this.stateWaitMap[stateProp] = Q.defer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new Promise()...
this.checkStateStatus(); | ||
const unsub = this.store.subscribe(this.checkStateStatus.bind(this)); | ||
|
||
return Q.all(promises).then(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promise.all()...
|
||
class RootProvider extends React.Component { | ||
render() { | ||
if (!this.props.store) throw("Error Root Provider expects a store passed in as a prop"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: include the braces here
} | ||
|
||
RootProvider.isRootProvider = function(element) { | ||
return element && element.props && element.props._isRootProvider; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer a symbol for this, e.g.
const rootProviderSymbol = Symbol();
class RootProvider extends React.Component {
[rootProviderSymbol]: true,
static isRootProvider(elem) {
return elem[rootProviderSymbol];
}
}
"description": "Package to support Redux in React-Server", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -0,0 +1,76 @@ | |||
import {createStore, applyMiddleware} from "redux"; // eslint-disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why disable the linter for all these?
"url": "https://github.com/redfin/react-server" | ||
}, | ||
"keywords": [ | ||
"redux" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe toss a react server mention in there?
{ | ||
"name": "react-server-redux", | ||
"version": "0.5.1", | ||
"description": "Package to support Redux in React-Server", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be self-evident its a package, so maybe just "Redux support for React Server"?
Could you also update the redux example? The test-pages are a great start, but I'd like a "minimal example" so I can think about the api. |
cb0257b
to
12cee72
Compare
This pr relates to #788... adding support for redux.
The package provides a RootProvider which can be used to wrap your RootElement components with a single RootProvider rather then a provider for each RootElement. Additionally a ReduxAdapter(Can this be a better name?) class which provides developers the ability to wait for specific values to be available in the state tree. I have also included two test pages to showcase each usage.
Let me know what you think and how I can improve it!