Closed natew closed 7 years ago
Actually, instead of having a methods object you give, would be nice to just give a class. This could then be extended by the RxDocument. This would also solve the getter issue we had before!
I think adding a preCreate hook is an excellent idea. It would make everything more flexible.
Done here
The hook is called postCreate
because it runs after the RxDocument-instance is created.
Just curious: postCreate was made non-async, was there a reason? I have a use case that would be nice to have async, but if its technically a lot harder it's not a problem.
@natew postCreate was made non-async for implementation-reasons. If it could be async, next to every methode of rxdb would have been async.
Case
When you write a query and exec(), you get a list back of RxDocuments. Typically you can define methods() to add methods to them, but this isn't very flexible. This may be a more advanced use case, but for example I want to extend documents in a variety of ways. One would be adding observable values onto them. Another would be adding specific getters. Etc, etc.
Issue
Can't really hook into the internals to do this. Idea would be to be able to hook into preCreate for an RxDocument and decorate the instance or the class (or both).