API Docs for: 0.8.3
Show:

ActionContext Class

The main point of entry for all mojits into Mojito. The Action Context is passed to every mojit action during execution, either on the client or server. This object is the API into Mojito, can can have many plugins attached the provide extra functionality.

Methods

_dispatch

(
  • command
  • adapter
)

This _dispatch function is called one time per Mojito execution. It creates a contextualized Y instance for all further internal dispatches to use. It also creates the ActionContext for the mojit.

The command has three main parts: the "instance", the "context", and the "params".

 command: {
     instance: ...see below...
     context: ...see below...
     params: ...see below...
 }

The "instance" is a partial instance with details of the mojit instance. See ServerStore.expandInstance() for details of the structure and which fields are required.

The "context" is the request context. It is built by the "contextualizer" middleware.

The "params" is a structured set of parameters to pass to the mojit.

 params: {
     route: {},
     url: {},
     body: {},
     file: {},
     ...
 }
adapter: {
     flush: function(data, meta){},
     done: function(data, meta){},
     error: function(err){}
}

Parameters:

  • command Map

    the "command" describing how to dispatch the mojit. See above.

  • adapter Object

    the output adapter to pass to the mojit. See above.

attachActionContextAddons

(
  • addons
  • command
  • adapter
  • ac
  • store
)
private

Mixes all the Action Context addons into the Action Context

Parameters:

  • addons Array

    The action context addons.

  • command Object

    The command object.

  • adapter Object

    The output adapter.

  • ac Y.mojito.ActionContext

    The action context.

  • store ResourceStore

    the resource store

dispatch

(
  • command
  • adapter
)
deprecated

Defined in node_modules/mojito/lib/app/autoload/action-context.common.js:23

Deprecated: Use 'ac._dispatch()' instead. See https://github.com/yahoo/mojito/blob/develop/DEPRECATIONS.md for details.

This dispatch function is called one time per Mojito execution. It creates a contextualized Y instance for all further internal dispatches to use. It also creates the ActionContext for the mojit.

The command has three main parts: the "instance", the "context", and the "params".

 command: {
     instance: ...see below...
     context: ...see below...
     params: ...see below...
 }

The "instance" is a partial instance with details of the mojit instance. See ServerStore.expandInstance() for details of the structure and which fields are required.

The "context" is the request context. It is built by the "contextualizer" middleware.

The "params" is a structured set of parameters to pass to the mojit.

 params: {
     route: {},
     url: {},
     body: {},
     file: {},
     ...
 }
adapter: {
     flush: function(data, meta){},
     done: function(data, meta){},
     error: function(err){}
}

Parameters:

  • command Map

    the "command" describing how to dispatch the mojit. See above.

  • adapter Object

    the output adapter to pass to the mojit. See above.

done

(
  • data
  • meta
)

Returns data and closes the request.

Parameters:

  • data Object | String

    The data you want return by the request.

  • meta Object

    Any meta-data required to service the request.

error

(
  • err
)

Programatically report an error to Mojito, which will handle it gracefully.

Parameters:

  • err Error

    A normal JavaScript Error object is expected, but you may add a "code" property to the error if you want the framework to report a certain HTTP status code for the error. For example, if the status code is 404, Mojito will generate a 404 page. Additionally you might provide a reasonPhrase property, to override the default human readable description for this status code with one specific to your application. For example for the status code 404 you could provide "This does not exist in my app".

flush

(
  • data
  • meta
)

Returns data in the request and allows you to carry on execution.

Parameters:

  • data Object | String

    The data you want return by the request.

  • meta Object

    Any meta-data required to service the request.