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:

https://github.com/strongloop/loopback-datasource-juggler/blob/master/3.0-release-notes.md#remove-deprecated-model-hooks-and-model-events

there's a number of differences. here's couple worth noting:

  1. operation hooks can invoke callback before or after events. example beforesave/aftersave operation hooks vs changed event invokes callback after change in model

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


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo