Updating fragments
Updating Fragments
Much like in ERB, when building pages with PropsTemplate, we use partials to extract shared views. For example:
This results in duplicate JSON nodes across our Redux state:
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:
Fragments used in nodes that are deferred do not show up inside the metadata until the deferred nodes are loaded.
Creating reducers
You can use the metadata created by fragments to update cross-cutting concerns in your reducer:
Last updated
Was this helpful?