pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21k stars 1.02k forks source link

Feature request: Custom RxDocument decorators #165

Closed natew closed 7 years ago

natew commented 7 years ago

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).

natew commented 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!

pubkey commented 7 years ago

I think adding a preCreate hook is an excellent idea. It would make everything more flexible.

pubkey commented 7 years ago

Done here The hook is called postCreate because it runs after the RxDocument-instance is created.

natew commented 7 years ago

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.

pubkey commented 7 years ago

@natew postCreate was made non-async for implementation-reasons. If it could be async, next to every methode of rxdb would have been async.