userbase
userbase copied to clipboard
Feature request: changeHandler should receive information on which items changed
Right now the changeHandler receives just one argument, which is the entire list of items in a database. I would like to receive information on exactly which items were changed so I don't have to iterate over them myself to figure it out. This could be a second argument passed to the changeHandler.
I am playing around with it at the moment and I think I can provide a PR. I have a couple of questions about this:
- What should the argument be, if an entry was deleted? An empty array or the deleted item?
- Should an object for the argument be used to be able to seemlessly integrate additional arguments in the future?
Regarding (1), I usually see change handler callbacks implemented as cb: <T>(previous: T | null, current: T | null). So a new item is (null, T), a changed item is (T, T), and a deleted item is (T, null). Sometimes the callback is (current, previous) to make it easy to capture just the new value.
From #227:
This could be done on the application side, rather than inside userbase-js. This is our preference for now because we'd rather keep the SDK extremely simple
For anyone looking to solve this, you can use a tool like deep-diff to compare old/new copies of the database values.