6. Merge: Set
Lesson 6: Merge: Set
You used merge: 'set' with numbers before. It works exactly the same with objects - each publish replaces the entire value.
Set vs CRUD
merge: 'crud'- the store is an array, events add/update/remove itemsmerge: 'set'- the store is a single value, each event replaces it completely
Use 'set' when you have one shared object (settings, profile, game state) rather than a list of items.
Try it
The profile stream is already set up. Add two RPCs:
updateProfile(changes)- merges the changes into the current profile using the spread operator (profile = { ...profile, ...changes }) and publishes the full updated profileresetProfile()- resets the profile to defaults and publishes
Then update the component with inputs for name, a color picker, a status dropdown, and a reset button. When User A types a name, User B sees it update live.
WebSocket
0
No messages yet