Updating fragments
Updating Fragments
Much like in ERB, when building pages with PropsTemplate, we use partials to extract shared views. For example:
views/
application/
_header.json.props
posts/
index.json.props
comments/
index.json.propsThis results in duplicate JSON nodes across our Redux state:
{
pages: {
"/posts": {
data: {
header: {
email: "foo@foo.com"
}
}
},
"/comments": {
data: {
header: {
email: "foo@foo.com"
}
}
},
}
}As we mentioned in the state shape guide this is by design. To update these cross-cutting cocerns, you will have to create a reducer to iterate through each pages node and immutably update them. This can be error-prone, but Breezy provides tooling to make this easy.
Fragments
To help with creating reducers, Breezy has a featured called fragments. A fragment in Breezy is a rendered partial with a given name:
Using the fragment functionality will create metadata about the node. This has been set up for you in application.json.props:
The resulting JSON looks like this:
Creating reducers
You can use the metadata created by fragments to update cross-cutting concerns in your reducer:
Last updated
Was this helpful?