let model = new models.Model<Post>({ name: 'posts', sync: getPost(123), streams: [postEvents, commentEvents], }); // define mutation functions function updatePost(post: Post) { return async function() { await fetch(`/posts/${post.id}`, { method: "PUT", body: JSON.stringify(post), }); } } // register the mutations on the model model.NewMutation(updatePost, { name: 'updatePost', stream: 'post', optimistic: function(post) { return post; } });
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter