Callback props
A component cannot reach into its parent, and it should not change data it was handed. When the card's Add button is clicked, the card asks, and the shop decides.
That question is a callback prop. On a component tag, @add={ add(album) } is not a DOM event: it hands the card a function. When the card calls it, the shop's own add handler runs with that album.
<!-- Shop.pzl -->
<AlbumCard album={ album } @add={ add(album) }/>
// AlbumCard.pzl
events = {
add: () => this.props.add?.(),
};
this.props.add is the function the shop passed. The ?. keeps the card working where a parent passes nothing. There is no $emit and no event bubbling between components: data flows down as props, intent flows up through callbacks, and the parent owns every change.
Your turn
- In
Shop.pzl, pass the callback:<AlbumCard album={ album } @add={ add(album) }/>. - In
AlbumCard.pzl, replace the stand-in handler withadd: () => this.props.add?.().
Click Add. The header count goes up and the card swaps its button for the "In playlist" badge, because the album record changed and every view that read it re-rendered.