-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
@goatslacker I like what you have here with connect
. But I miss the decorator version we used to have.
I suggest something like this:
function connectToStores(component) {
if (component.contextTypes == null) component.contextTypes = {}
if (component.contextTypes.flux == null) {
component.contextTypes.flux = React.PropTypes.object.isRequired
}
let storeNames = []
if (component.getStores != null) storeNames = component.getStores()
if (component.stores != null) storeNames = component.stores
if (component.store) storeNames = [component.store]
return connect(component, (stores, flux) => {
return {
listenTo() {
return storeNames.map((name) => flux.stores[name])
},
getProps() {
if (component.getPropsFromStores != null) {
return component.getPropsFromStores.apply(this, arguments)
}
const props = {}
for (const storeName of storeNames) {
props[storeName] = flux.stores[storeName].getState()
}
return props
},
}
})
}
However I'm unsure how you'd want to introduce this into the library. Let me know your thoughts.
jayalfredprufrock
Metadata
Metadata
Assignees
Labels
No labels