Skip to content

Instantly share code, notes, and snippets.

@ritch
Created May 12, 2014 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritch/e281fa45d0b8d5303908 to your computer and use it in GitHub Desktop.
Save ritch/e281fa45d0b8d5303908 to your computer and use it in GitHub Desktop.
How might we zonify loopback?

Here is a basic (truncated) callstack for a REST request to loopback.

  • GET /users
  • loopback.rest()
    • loopback.token()
    • Model.checkAccess()
    • sharedMethod.invoke(argsFromHttpCtx)
      • User.find()
        • connector.find()
          • driver.find()
    • sharedMethod.toResult(callbackArgs)
    • res.send(result)

Below is the important async calls during a loopback http request:

// LoopBack Zones
loopback.rest() // async (middleware)
loopback.token() // async (middleware)
Model.checkAccess() // async 
sharedMethod.invoke(argsFromHttpCtx) // async
// Juggler (Connector) Zones
driver.find(..., callback); // async

Proposed Zones

Request // done-ish (should set data.req and data.res)
  Access Control // loopback/lib/middleware/token.js 
    Remote Method Invocation // strong-remoting/lib/shared-method.js
      [Driver Invocation] // juggler/lib/dao.js ***

Proposed Invocation Context

zone.data.ctx = new Context(req, res, app, method);

Model.currentContext = function() {
  return zone.data.ctx;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment