NISHIO Hirokazu[Translate]
2020-01-21
Wifiオフで8を投稿
Wifiオン
自動でクラウド保存されてる
そのタイミングで(local save ok)のフラグが消えてる
ts
setGlobal({ items: [...global.items, item] }); local_db.items.add(item).then(() => { const new_item = { ...item, saved_local: true } setGlobal({ items: [...global.items, new_item] }); }) addItemToFirestore(item).then(() => { const new_item = { ...item, saved_cloud: true } setGlobal({ items: [...global.items, new_item] }); })
ts
const updateItem = (index: number, diff: { [key: string]: any }) => { const global = getGlobal(); const new_item = { ...global.items[index], ...diff } const new_items = [...global.items] new_items[index] = new_item; setGlobal({ items: new_items }); } const index = global.items.length; setGlobal({ items: [...global.items, item] }); local_db.items.add(item).then(() => { updateItem(index, { saved_local: true }) }) addItemToFirestore(item).then(() => { updateItem(index, { saved_cloud: true }) local_db.items.update(item.created, { saved_cloud: true }) })

クラウド保存されないままリロードされたものはリトライされない
リロード時にローカルから復元されたものは即座にリトライ
した

"Engineer's way of creating knowledge" the English version of my book is now available on [Engineer's way of creating knowledge]

(C)NISHIO Hirokazu / Converted from [Scrapbox] at [Edit]