-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve docs for Operation hooks #1173
Comments
I'd rather that Rand sit with you and get the info to update and improve docs, rather than you write this. |
Miroslav, I will go through the above issues and try to extract the pertinent info. I will likely have questions as a result.... Then let's meet and you can give me a brain dump, as Chanda suggests. You could also jot down some notes if you have some specific things you know you'd like to add to or change in the docs. |
This may not be completed this sprint, since the feature is being significantly reworked. Miroslav said:
|
@crandmck first few things that are ready to be documented. Document "hookState" - see loopbackio/loopback-datasource-juggler#485 and loopbackio/loopback-datasource-juggler#484 Capture the information from loopbackio/loopback-datasource-juggler#483 (comment). The first part explains why there is "instance" object instead of providing always a "data" object. The second part explains different use cases of hooks. Explain why the "before delete" and "after delete" hooks don't receive a list of deleted ids, see the discussion in loopbackio/loopback-datasource-juggler#474. Explain that a naive implementation of hooks creates a race condition (loopbackio/loopback-datasource-juggler#474 (comment)) and describe how it can be avoided (loopbackio/loopback-datasource-juggler#474 (comment)). NOTE: loopbackio/loopback-datasource-juggler#488 is adding loopbackio/loopback-datasource-juggler#481 contains useful information too, e.g. the first part of loopbackio/loopback-datasource-juggler#481 (comment) explains why "updateAttributes" does not have NOTE: loopbackio/loopback-datasource-juggler#488 is adding |
Some material for starting a FAQ section: loopbackio/loopback-datasource-juggler#482 (comment) |
Re-estimating to 1 story point. I'll only gather more pointers to relevant comments and pull requests, so that @crandmck can write the content himself. |
@bajtos Added a note about |
Here is a code snippet based on loopbackio/loopback-datasource-juggler#549 (comment). var FILTERED_PROPERTIES = ['immutable', 'birthday'];
MyModel.observe('before save', function filterProperties(ctx, next) {
if (ctx.options && ctx.options.skipPropertyFilter) return next();
if (ctx.instance) {
FILTERED_PROPERTIES.forEach(function(p) { ctx.instance.unsetAttribute(p); });
} else {
FILTERED_PROPERTIES.forEach(function(p) { delete ctx.data[p]; });
}
next();
});
// immutable is not updated
MyModel.updateOrCreate({ id: 1, immutable: 'new value' }, cb);
// immutable is changed
MyModel.updateOrCreate({ id: 2, immutable: 'new value' }, { skipPropertyFilter: true }, cb); |
Added the example code..thanks. We still need to add all the items noted in the comment above. @bajtos Were you planning to do this, or did you want me to do it? |
Please do it yourself. My plan was only to collect a list of pointers for you. |
Actually there are no more features to add to the list in the comment above, I am reassigning this issue to you, @crandmck. |
OK, here is what I have for this:
I'm going to need a bit more time to sort all this out, because it's fairly complex and there are an abundance of PRs and discussions to sort through. |
Sounds good! FYI, there were two more hooks added recently, see loopbackio/loopback-datasource-juggler#599 and loopbackio/loopback-datasource-juggler#586. I am afraid the task of (fully) documenting operation hooks will be a long one. |
@bajtos It was difficult for me to sort out from the very lengthy discussions across multiple PRs what was actually done and needs to be documented. I gave it my best shot, but apologies if I missed something. I admit to still being somewhat confused. Please review the updates referenced in the comment above and let me know what more needs to be added or changed. Some illustrative examples would help. Re the two new hooks, see http://docs.strongloop.com/display/LB/Operation+hooks#Operationhooks-newhooks. Note this information is "hidden" until the new features are released to production. |
@crandmck thank you for updating the doc page. I am afraid I don't have enough time to review the changes now, I have created a new sprint story so that we can plan this task: https://github.com/strongloop-internal/scrum-loopback/issues/376 Sorry for the delay :( |
OK, np. It took me quite a while to get around to working on this myself. |
Closed in favor of https://github.com/strongloop-internal/scrum-loopback/issues/376. |
Is it possible to terminate the invocation from Operation hooks? |
You can terminate the invocation by raising an error via In the future, please post questions to our mailing list and/or community forums, see https://github.com/strongloop/loopback/wiki/Questions. |
Judging by the recent discussions in GitHub issues, the current minimal documentation does not make it clear how to correctly use the hooks and why they are designed in a seemingly unintuitive way.
The goal of this task is to write down all knowledge that's in Miroslav's head at the moment, add information from comments in the issues linked below, and beef up the doc page Operation hooks.
A list of pain-points can be found here:
Related issues:
The text was updated successfully, but these errors were encountered: