You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes a user might need to rename or remove a property provided to a component. For example, remaining description to subtitle.
The user currently has two options:
Manually migrate their saved data before updating their Puck configuration
(Preferred) Retain the old prop and map it to the new prop inside the render function.
These solutions either require repetitive work, or require the user to republish each page manually.
Proposal
Add a first-party mechanism for transforming data on a per-component basis.
This would probably live under a separate package (/packages/transform or /packages/migrate) and provide a user with a mechanism to 1) patch their data on the fly in a standardised manor and 2) batch transform their puck data consistently to adhere to the new props.
// Pull from backendconstdata={type: "HeadingBlock",props: {subtitle: "Hello, world",},};exportdefault()=><Puckdata={transform(data)}config={config}/>;
Patch all existing data
// Example dataconstallData=[{path: "/",data: {root: {},content: [{type: "HeadingBlock",props: {subtitle: "Hello, world",},},],},},];// Run the transformerconstpatchedData=allData.map((page)=>({
...page,data: transform(page.data),}));// Write to your dbconstsave=()=>{};save(patchedData);
Considerations
TypeScript - How to tightly manage the types?
The text was updated successfully, but these errors were encountered:
Problem
Source: https://news.ycombinator.com/item?id=37392861
Sometimes a user might need to rename or remove a property provided to a component. For example, remaining
description
tosubtitle
.The user currently has two options:
render
function.These solutions either require repetitive work, or require the user to republish each page manually.
Proposal
Add a first-party mechanism for transforming data on a per-component basis.
This would probably live under a separate package (
/packages/transform
or/packages/migrate
) and provide a user with a mechanism to 1) patch their data on the fly in a standardised manor and 2) batch transform their puck data consistently to adhere to the new props.Create transformer
Patch data inline
Patch all existing data
Considerations
The text was updated successfully, but these errors were encountered: