2020-01-21
pKakidashi
Wifiオフで8を投稿
https://gyazo.com/f5cfee5cbf5ba5f1df286690462e009d
Wifiオン
https://gyazo.com/b3b1633e4edab4d48542c9746ccab3df
自動でクラウド保存されてる
そのタイミングで(local save ok)のフラグが消えてる
code: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 });
})
code:ts
const updateItem = (index: number, diff: { key: string: any }) => {
const global = getGlobal();
const new_item = { ...global.itemsindex, ...diff }
const new_items = ...global.items
new_itemsindex = 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 })
})
クラウド保存されないままリロードされたものはリトライされない
リロード時にローカルから復元されたものは即座にリトライ
した