Is it possible to register loopback.io hooks only once for each model?

I am trying to perform hooks operations http://docs.strongloop.com/display/public/LB/Operation+hooks

Here is what I did in the application code:

    mymodel.observe('before save', doSomething);

    //after some time elapses or based on an event we want to change the behaviour
    mymodel.observe('before save', doSomethingElse);


    var doSomething = function (ctx, next) {
        //do something
        next();
    };

    var doSomethingElse = function (ctx, next) {
        //do something else
        next();
    };

When I test this code, I find that doSomething always executes, which makes me wonder if the observer function can only register once per model or is this an error?

If this is by design, could you tell us the reason for this?

+4
source share
2 answers

Disclaimer: I am the main LoopBack developer and author of Operation hooks.

,

. observe() , hook.

, , doSomething, , ?

. doSomething . doSomethingElse, , , doSomething next().

+2

clearObservers removeObserver. . ObserverMixin.

changelog ​​ 2.23.0 .

0

All Articles