Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

外部からの強制データ上書き・一定期間有効なパッチ上書き #84

Open
tompng opened this issue Nov 25, 2019 · 2 comments

Comments

@tompng
Copy link
Owner

tompng commented Nov 25, 2019

ar_syncの通知・自動反映を待っていると、ラグが気になることがある
(ボタンを押したらすぐ何か変化があって欲しい、など)
appoloとかでやっているらしい、postしたら(そのレスポンスを元に)データいい感じに更新してくれるやつ

const newtitle = 'あたらしいタイトル' 
await response = post('/post/3', { title: newtitle })
ArSync.foobarUpdateAllData('Post', 3, { title: response.title })
const newtitle = 'あたらしいタイトル' 
const patch = ArSync.foobarAddPatch('Post', 3, { title: newtitle }, { time: 10000 })
try {
  await response = post('/post/3', { title: 'あたらしいタイトル' })
  patch.invalidate()
  ArSync.foobarUpdateAllData('Post', 3, { title: response.title })
} catch(e) {
  patch.invalidate()
}

こんな感じのAPI用意しとけばいいかな?

@tompng
Copy link
Owner Author

tompng commented Nov 25, 2019

ArSyncで提供しなくてもこれでできるから別に良さそう...

const [post, status] = useArSyncModel(...)
const [patchedPost, createPatch] = useFoobarPatch(post)

const submit = (title: string, body: string) => {
  const patch = createPatch({ title, body })
  try {
    await myApi.updatePost(post.id, { title, body })
    patch.invalidate(n * 1000) // n秒後に無効にする(無効になる前にarsyncで更新されればよし)
  } catch(e) {
    patch.invalidate()
  }
}

もっとまとめると

const [post, status] = useArSyncModel(...)
const [patchedPost, updatePost] = useFoobarPatch(post, myApi.updatePost)
const submit = (title: string, body: string) => updatePost({ title, body }))

@tompng
Copy link
Owner Author

tompng commented Nov 25, 2019

このusePatchを含めてしまえば良い?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant