unfold / fetch-data Goto Github PK
View Code? Open in Web Editor NEWDeclarative data fetching for Redux and React
Declarative data fetching for Redux and React
Instead of a Provider type class that exposes registerDependency we could use the new staticContext
:
static contextTypes = {
router: PropTypes.shape({
staticContext: PropTypes.object,
}).isRequired,
}
componentWillMount() {
const { staticContext } = this.context.router
if (staticContext) {
staticContext.registerDependency(this.dispatchIfNeeded(this.props))
}
}
import { resolveRequestPromises } from '@unfold/fetch-data'
const renderApplication = () => renderToString(<Application />)
try {
const markup = await resolveFetchRequests(renderApplication, { maxIterations: 2 })
res.send(markup)
} catch (error) {
next(error)
}
As of now the following doesn't work:
// Fetch both a product and a page
connectFetchData({
mapPropsToAction: ({ productId, parentPath }) => (
Promise.all([
actions.getProductById(productId),
actions.getPageByPath(parentPath)
])
),
mapStateToProps: (state, { productId, parentPath }) => ({
product: state.products.byId[productId],
page: state.pages.byPath[parentPath],
}),
})
It's easy to work around this by chaining multiple connectFetchData
, but this prevents the actions from being fired in parallel. Ideally one would be allowed to return a Promise, but since we're using mapPropsToRequest
to determine loading state this isn't trivial.
I suggest being able to return an array from mapPropsToAction
that is dispatched in parallel in the middleware. To compute loading and error state something like this would probably be sufficient:
const loading = requests.some(request => request.loading)
const error = requests.find(request => request.error)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.