< documentation
Plugins
Extension Points
event 1.0.x
usage
jquery-claypool treats the event as a request scope container. This just means that the event object itself is used to store state information whose expected lifetime is the duration of the event. This state information includes application specific data used to render the views, (called the 'model' with a lowercase m), trigger rendering, select additional views to render, forward control, etc.
options
The following methods are all available on the event object
event.m | event.v | event.c | event.params | event.render | event.reset
event.m
overloaded function getters and setters of the event model. chainable setters. overloaded function for easily setting and getting values on a the event model that will be presented to the view class when event.render is called. the event model is array like so it makes sense that it can be both extended and merged. the event model will be passed to the event view automatically with event.render
getter
Returns the current model (event scope state)
// by default this is the object // {flash:[], length:0} event.m();
getter
Returns the value specified or null if it has not been set.
event.m('mylist');
setter
When there is a single argument and it is an Object or Array, the interal model is deeply extended or merged respectively
event. m({a:'A',b:'B',c:'C'}). m(['D','E','F']);
setter
When there are two arguments the first should be a string. this is the name of the models property that will be set on the model. if the second argument is an object or array, the internal model is deeply extended or merged respectively, and when it is a simple value the value is set directly.
event. m('mysimple','This is a pig.'). m('myprops',{a:'A',b:'B',c:'C'}). m('mylist',['D','E','F']);
event.v
overloaded function getters and setters of the event view. chainable setters. relates to which method will be used by event.render the event.v function gives an overloaded function for easily setting and getting the event view and view method. the event view is resolved my jquery-claypool and called when event.render is issued.
getter
when there is no argument the current view will be returned. If the controller has the application id '#helloController', then by default the code below will return '#helloView' and by default the method called on the view is 'update'.
event.v()
setter
Sets the view and/or view method which will be rendered. when there is an argument, it should be a single string of the form '#appId' or '.methodname' or '#appId.methodname'. the '#' portion determines the view instance and the '.' portion determines the view method that will be called. this method is chainable.
event. m({a:'A'}). v('.think'). render()
event.c
getter and setter to introspect the current controller and forward control to other controllers. setter is chainable. event.c method, especially if used in conjunction with the event.render(callback) method, provides a very rich set of patterns for collecting model information and performing multiple view updates from a single event.
getter
when no argument is present, returns the current controller application id as a string. not chainable.
event.c()
setter
Forwards control to another controller. Single argument is a string of the form 'target.action' where 'target' is required , and '.action' is optional. target is the application id of the controller (usually of the form '#helloController'). 'action' is the name of the desired method to call on the controller, by default this is 'handle' when not specified. chainable, and when control is released by the forwarded controller, it is returned to the current controller.
event. m({a:'A'}). c('#userController.session'). render();
event.params
returns all route params as an object or a single route param by name. also always setter via two arguments. route params are set automatically based on the routers capturing expressions
getter
no arguments returns the entire set of params as an object
/** * assuming urls:'/|:type|/|:id|/edit$' * assuming pattern '/user/532/edit' * returns { * type: 'user', * id:'532' * } */ event.params();
setter
a single string argument returns the named param or null
/** * assuming urls:'/|:type|/|:id|/edit$' * assuming pattern '/user/532/edit' * returns 'user' */ event.params('type');
event.render
triggers jquery-claypool to resolve the view instance and call the view method. event.render triggers jquery-claypool to resolve the view instance and call the specified view method, passing the model event.m() as the first argument. an optional callback can be specified, it will be called when the view method has returned. chainable.
example
triggers jquery-claypool to resolve the view instance and call the view method passing it the event scope state aggregated by event.m()
event.render();
callback
triggers jquery-claypool to resolve the view instance and call the view method and then calls the a callback
event. v('.think'). render(function(){ event. v('.update'). render() '});
event.reset
resets the internal m, v, c settings to the initial state. The event.reset function can be used to clear all model data, reset the view target and method, etc.
example
Resets the event scope state.
event.reset();
Project
- app
- app/boot
- app/boot/client.js
- app/boot/server.js
- app/configs
- app/configs/config.js
- app/configs/environments.js
- app/configs/filters.js
- app/configs/logging.js
- app/configs/routes.js
- app/controllers
- app/controllers/example.js
- app/models
- app/models/example.js
- app/services
- app/services/example.js
- app/templates
- app/templates/example.js
- app/views
- app/views/example.js
- index.html
Guides
This guide is applicable to both the jquery-claypool client and server application frameworks. Where the two differ functionally the documentation will provide notes and examples of usage in each environment.