5. Merge: CRUD
Lesson 5: Merge: CRUD
Until now, every stream used merge: 'set' which replaces the entire value on each update. For lists of items, merge: 'crud' is better.
How CRUD merge works
The store holds an array. Three event names modify it:
'created'- appends the item to the array'updated'- replaces the item with the matchingid'deleted'- removes the item with the matchingid
The key option (default 'id') tells the merge which field to match on.
Try it
The stream is already set up with merge: 'crud'. Add three RPCs:
addTodo(text)- creates a todo withid(usecrypto.randomUUID()),text, anddone: false. Push it to the array and publish with event'created'.toggleTodo(id)- finds the todo, flipsdone, and publishes with event'updated'.deleteTodo(id)- removes the todo from the array and publishes with event'deleted'.
Then update the component: add an input + form to create todos, checkboxes to toggle, and a delete button for each.
WebSocket
0
No messages yet