javascript - What's the difference between Loopback's operation hooks vs events? -
loopback seems have overlapping concepts when handling points of time in model's lifecycle:
https://docs.strongloop.com/display/public/lb/operation+hooks
applied through model.observe
vs
https://docs.strongloop.com/display/public/lb/events#events-modelevents
applied through model.on
both seem have similar ways of handling crud events.
what's difference between these 2 types of event systems? , when should use 1 on another?
update:
apparently overlapping model events have been deprecated in loopback v3, operation hooks should used:
there's a number of differences. here's couple worth noting:
operation hooks can invoke callback before or after events. example beforesave/aftersave operation hooks vs changed event invokes callback after change in model
there events in model's lifecycle operation hooks invoke, e.g. loaded operation hooks invoked whenever instance of model loaded via find(), findone(), count(), etc. there's events only covered model events, e.g. datasourceattached, invoked when model attached datasource.
so there's overlap, there's difference in lifecycle events can watch.