Update functions

PHOTO EMBED

Wed Jun 21 2023 12:44:24 GMT+0000 (Coordinated Universal Time)

Saved by @AndraAbly #javascript

// update a post by replacing the old value with the new
model.on('post', 'update', (state: Post, event: PostEvent) => event);

// the like event increments the like counter on the post
model.on('post', 'like', (state: Post) => {
	state.likes++;
	return state;
});

// the add comment event adds a new comment to the post
model.on('comments', 'add', (state: Post, event: CommentEvent) => {
	state.comments.push(event);
	return state;
});
content_copyCOPY

You can define the logic to modify the local state as update functions, that will be applied via the model.