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:
-
commandMapthe "command" describing how to dispatch the mojit. See above.
-
adapterObjectthe output adapter to pass to the mojit. See above.
attachActionContextAddons
-
addons -
command -
adapter -
ac -
store
Mixes all the Action Context addons into the Action Context
Parameters:
-
addonsArrayThe action context addons.
-
commandObjectThe command object.
-
adapterObjectThe output adapter.
-
acY.mojito.ActionContextThe action context.
-
storeResourceStorethe resource store
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:
-
commandMapthe "command" describing how to dispatch the mojit. See above.
-
adapterObjectthe output adapter to pass to the mojit. See above.
done
-
data -
meta
Returns data and closes the request.
Parameters:
-
dataObject | StringThe data you want return by the request.
-
metaObjectAny meta-data required to service the request.
error
-
err
Programatically report an error to Mojito, which will handle it gracefully.
Parameters:
-
errErrorA 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:
-
dataObject | StringThe data you want return by the request.
-
metaObjectAny meta-data required to service the request.
