Browse Source

Code cleaning

master
Anthony Hinsinger 6 years ago
parent
commit
bb00fd442f
  1. 13
      src/web/bookform.ts

13
src/web/bookform.ts

@ -23,15 +23,18 @@ const BookForm = () => {
<input placeholder="author name" ...=${spread(authorProps)}> <input placeholder="author name" ...=${spread(authorProps)}>
<button @click=${async () => { <button @click=${async () => {
try { try {
const data = await schema.validate({ const newBook = await schema.validate({
author: authorProps[".value"], author: authorProps[".value"],
title: titleProps[".value"] title: titleProps[".value"]
}); });
await addBook({ variables: data, update: (cache, result) => { await addBook({
const list: any = cache.readQuery({ query: GetBooks }); variables: newBook,
cache.writeQuery({ query: GetBooks, data: { books: [...list.books, result.data.addBook] }}); update: (cache, { data }) => {
}}); const { books }: any = cache.readQuery({ query: GetBooks });
cache.writeQuery({ query: GetBooks, data: { books: [...books, data.addBook] }});
}
});
setTitle(""); setTitle("");
setAuthor(""); setAuthor("");

Loading…
Cancel
Save