Skip to content

Remote invocation phases - #279

Merged
bajtos merged 3 commits into
masterfrom
feature/phases
Feb 2, 2016
Merged

Remote invocation phases#279
bajtos merged 3 commits into
masterfrom
feature/phases

Conversation

@bajtos

@bajtos bajtos commented Feb 1, 2016

Copy link
Copy Markdown
Member

0) Simplify invokeMethodInContext

Deprecate invokeMethodInContext(ctx, method, cb) in favour of simpler
invokeMethodInContext(ctx, cb).

1) Add remote invocation phases

Rework "invokeMethodInContext" to use a concept of phases that allows
external components a more fine-grained way for extending built-in
functionality.

The new API is exposed on remotes.phases, which is an instance
of PhaseList from loopback-phase.

There are two built-in phases available: "auth" and "invoke".

Hooks registered via remotes.authorization, remotes.before and
remotes.after are invoked in "auth", "invoke:before" and
"invoke:after" phases.

Here is the complete order in which different hooks/handler are called:

  • hook "authorization"
  • phase handlers "auth"
  • hook "remotes.before"
  • phase handlers "invoke:before"
  • invoke method
  • phase handlers "invoke:use"
  • hook "remotes.after"
  • phase handlers "invoke:after"

2) Add remotes.registerPhaseHandler
Implement a method for registering phase handlers with a method-name
based filter.

Example usage:

// match static methods
remotes.registerPhaseHandler('invoke', 'User.*', fn)

// match prototype methods
remotes.registerPhaseHandler('invoke', 'User.prototype.*', fn)

// match all model methods
remotes.registerPhaseHandler('invoke', 'User.**', fn)

Connect to strongloop-internal/scrum-loopback#729

/to @raymondfeng @ritch please review
/cc @chayab

Deprecate `invokeMethodInContext(ctx, method, cb)` in favour of simpler
`invokeMethodInContext(ctx, cb)`.
@bajtos bajtos added this to the #Epic: MobileFirst milestone Feb 1, 2016
@bajtos

bajtos commented Feb 1, 2016

Copy link
Copy Markdown
Member Author

@slnode test please

Rework "invokeMethodInContext" to use a concept of phases that allows
external components a more fine-grained way for extending built-in
functionality.

The new API is exposed on `remotes.phases`, which is an instance
of PhaseList from loopback-phase.

There are two built-in phases available: "auth" and "invoke".

Hooks registered via `remotes.authorization`, `remotes.before` and
`remotes.after` are invoked in "auth", "invoke:before" and
"invoke:after" phases.

Here is the complete order in which different hooks/handler are called:

 - hook "authorization"
 - phase handlers "auth"
 - hook "remotes.before"
 - phase handlers "invoke:before"
 - invoke method
 - phase handlers "invoke:use"
 - hook "remotes.after"
 - phase handlers "invoke:after"
Implement a method for registering phase handlers with a method-name
based filter.

Example usage:

    // match static methods
    remotes.registerPhaseHandler('invoke', 'User.*', fn)

    // match prototype methods
    remotes.registerPhaseHandler('invoke', 'User.prototype.*', fn)

    // match all model methods
    remotes.registerPhaseHandler('invoke', 'User.**', fn)
@ritch

ritch commented Feb 1, 2016

Copy link
Copy Markdown
Member

Deprecate invokeMethodInContext(ctx, method, cb) in favour of simpler
invokeMethodInContext(ctx, cb).

👍

@ritch

ritch commented Feb 1, 2016

Copy link
Copy Markdown
Member

LGTM

@ritch ritch assigned bajtos and unassigned ritch Feb 1, 2016
bajtos added a commit that referenced this pull request Feb 2, 2016
@bajtos
bajtos merged commit 29e5efb into master Feb 2, 2016
@bajtos
bajtos deleted the feature/phases branch February 2, 2016 09:40
@bajtos bajtos removed the #review label Feb 2, 2016
@bajtos
bajtos restored the feature/phases branch February 2, 2016 09:41
@bajtos
bajtos deleted the feature/phases branch February 2, 2016 09:41
bajtos added a commit that referenced this pull request Feb 2, 2016
@bajtos

bajtos commented Feb 2, 2016

Copy link
Copy Markdown
Member Author

Backported to 2.x via 0ab0647.

bajtos added a commit that referenced this pull request Feb 2, 2016
 * Backport pull request #279 from strongloop/feature/phases (Miroslav Bajtoš)
 * Add remotes.registerPhaseHandler (Miroslav Bajtoš)
 * Add remote invocation phases (Miroslav Bajtoš)
 * Simplify invokeMethodInContext (Miroslav Bajtoš)
 * Extract ContextBase and ctx.getScope() (Miroslav Bajtoš)
 * Customize XML root element in remoteMethod (David Cheung)
bajtos added a commit that referenced this pull request Feb 6, 2016
Fix RemoteObjects.prototype.invokeMethodInContext to trigger afterError
hooks only when there was an invocation error.

This bug was introduced recently by #279.
bajtos added a commit that referenced this pull request Feb 6, 2016
Fix RemoteObjects.prototype.invokeMethodInContext to trigger afterError
hooks only when there was an invocation error.

This bug was introduced recently by #279.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants