userbase icon indicating copy to clipboard operation
userbase copied to clipboard

`openDatabase` Issues + Nit

Open ghost opened this issue 4 years ago • 1 comments

1. Opening database removes existing handler

I guess this behavior is intentional, but it's not obvious. I'd be happy to document it.

2. changeHandler is called on database open

It's also not obvious that changeHandler would behave this way, and it contradicts the documentation:

A callback that gets invoked when the database gets modified.

A more natural behavior might be to skip the initial call of changeHandler and instead resolve openDatabase with the data:

const initial = await userbase.openDatabase({
  databaseName: '',
  changeHandler() {},
});

3. Unable to unsubscribe from changeHandler or close database

A wee memory leak. And it's a bit cumbersome for the user, who has maintain some state to key off of in changeHandler to determine whether or not to process the change.

4. Nit: Options are unnecessarily verbose

  • databaseName -> name
  • changeHandler -> onChange

ghost avatar Apr 05 '20 19:04 ghost

1: Good catch. We'll document this behavior.

2: Good feedback. We can't change it easily as it would be a breaking change. But we'll consider this for the next major version.

3: A closeDatabase method is coming soon

4: We'll consider those changes.

Thank you. Leaving open until 1 and 3 are live.

dvassallo avatar Apr 09 '20 01:04 dvassallo