API Docs for: 0.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.

_simulateResponse

(
  • id
  • details
  • badcookie
)
private

Simulate a server response

Parameters:

  • id Number

    the id of the transaction.

  • details Object

    the details of the response.

  • badcookie Boolean

    Optional. If true simulate cookies turned off.

_wsRequestFormatter

() Object private

Format web service requests using var foo = function() format so that reset is easier.

Returns:

Object: the formatted request.

destroy

()

Called by the bean registry whenever this bean is reinitialized

disable

(
  • queue
)

Disables all Ajax requests for the application.

Parameters:

  • queue Boolean

    (Optional) When set to true, queues all requests while disabled.

dispatch

(
  • command
  • adapter
)
deprecated

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

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.

enable

()

Enables sending of requests.

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.

execute

(
  • url
  • data
  • method
)
private

Executes an io request.

Parameters:

  • url String

    Url to access.

  • data Object

    The data to send.

  • method String

    GET or POST.

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.

setRequestFormatter

(
  • requestType
  • formatter
)

Sets the request formatter function for a given request type.

Parameters:

  • requestType String

    The type of request that the formatter should handle.

  • formatter Function

    The function to call to format the request.

setResponseFormatter

(
  • formatter
)

Sets the response formatter function for all responses.

Parameters:

  • formatter Function

    The function to call to format the response object.