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

oncontentadded event #25

Open
rektide opened this issue Mar 27, 2020 · 2 comments
Open

oncontentadded event #25

rektide opened this issue Mar 27, 2020 · 2 comments

Comments

@rektide
Copy link

rektide commented Mar 27, 2020

Hello. At the moment, if I have a complex service worker that wants to take notice of content being added, I can either

  1. do that additional work everytime I call index.add()
  2. use setInterval() or some such & call index.getAll() & diff, checking for new content

Since we have this index, & this index already can tell us when content goes away, it would also be nice to know when content is added. This would be a more normalized path than (1) or (2).

@rayankans
Copy link
Collaborator

Currently, the contentdelete event only fires if the deletion was originated by the user.

But like the idea of have generic contentadd and contentdelete events. Even though there are workarounds like you mentioned, it could simplify some of the synchronization logic.

@jeffposnick Any thoughts on the matter considering you've been looking into the best way to synchronize content index entries in a web app?

@jeffposnick
Copy link
Contributor

(Summarizing some thoughts from https://twitter.com/jeffposnick/status/1207784110732795910)

The "source of truth" that made the most sense to me was the Cache Storage API (or IDB, if you use that for your offline data). I'm not sure what the right interval for syncing the Cache Storage API state with the Content Indexing API is, but it's been cheap enough that doing it each time my web app starts up hasn't seemed to be a problem.

Listening to contentdelete and then removing the related Responses from Cache Storage is the "right" thing to do, in that it would prevent items from reappearing in the UX—in my model, where Cache Storage is the source of truth, the items would get added to the index again once my web app starts up.

I don't actually see a need for a contentadd event, though, since I'm not aware of a mechanism for a user to specify a URL that they would like to be available offline outside of a web app's normal user interface. If we get to the point where there is some browser end-user interface that supports entering an arbitrary URL and we want a way to signal to the web app that the URL should be cached for offline use, then maybe contentadd would make sense.

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

3 participants