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

Hook or event when local database is created #116

Open
bmihelac opened this issue May 12, 2017 · 7 comments
Open

Hook or event when local database is created #116

bmihelac opened this issue May 12, 2017 · 7 comments

Comments

@bmihelac
Copy link

bmihelac commented May 12, 2017

Local database is created on first page load, on sign in, and on sign out. It would be nice to have hook or event that would allow custom code to be performed when local database is created.

For example database indexes could be created at that time or some data could be bootstrapped.

Currently database is cleared in after 'signout' hook (of hoodie-client/init).

 hoodie.account.hook.after('signout', function (options) {
   return hoodie.store.reset()
 })

This make impossible to use clear event or signout hook to bootstrap new database. I have made an non working signout hook example on hoodie-app-tracker app.

Currently to achieve running code is only possible when resolvinghoodie.account.signOut as demonstrated in this commit: bmihelac/hoodie-app-tracker@d0974b3

What do you think about emitting event store.created or adding hook hoodie.store.hook.after('database:create')?

@janl
Copy link
Member

janl commented May 12, 2017

Great idea!

I can’t comment on whether to use an event or a hook, but either sounds fine to me.

@gr2m
Copy link
Member

gr2m commented May 12, 2017

I wonder if there are other use cases than indexes for which we would want the hook. If it would only be for indexes, I could imagine a declarative way. Indeces would be relevant for both, client and server

@bmihelac
Copy link
Author

Maybe bootstraping some data?

@gr2m
Copy link
Member

gr2m commented Jun 17, 2017

I’m currently thinking about a bootstrap event and hook. bootstrap would be emitted each time the database is "ready". On page reload, this will be nearly immediate. After sign in, we will emit the event after all user data has been synchronised to the client. This would also address the problem there is currently no way to tell when this data bootstrapping is done.

So to add custom data or views, you could then do

hoodie.account.hook.before('bootstrap', function (options) {
   return hoodie.store.add(myAppViews)
 })

Would that work for you?

@bmihelac
Copy link
Author

bootstrap would be emitted after db is recreated after destroyed, ie. when user signs out?

@gr2m
Copy link
Member

gr2m commented Jun 20, 2017

Yes, that’s my thinking. Here the list of cases

  1. Page load: emits once database is ready
  2. Sign in: emits once all data is loaded from remote
  3. Sign out: emits once new database is ready

@bmihelac
Copy link
Author

This looks good. Thanks

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