Page MenuHomePhorge

ViewVisitor.js
No OneTemporary

ViewVisitor.js

/**
* @provides javelin-view-visitor
* @requires javelin-install
* javelin-util
*
* Add new behaviors to views without changing the view classes themselves.
*
* Allows you to register specific visitor functions for certain view classes.
* If no visitor is registered for a view class, the default_visitor is used.
* If no default_visitor is invoked, a no-op visitor is used.
*
* Registered visitors should be functions with signature
* function(view, results_of_visiting_children) {}
* Children are visited before their containing parents, and the return values
* of the visitor on the children are passed to the parent.
*
*/
JX.install('ViewVisitor', {
construct: function(default_visitor) {
this._visitors = {};
this._default = default_visitor || JX.bag;
},
members: {
_visitors: null,
_default: null,
register: function(cls, visitor) {
this._visitors[cls] = visitor;
},
visit: function(view, children) {
var visitor = this._visitors[cls] || this._default;
return visitor(view, children);
}
}
});

File Metadata

Mime Type
text/plain
Expires
Thu, Feb 20, 23:34 (3 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1129470
Default Alt Text
ViewVisitor.js (1 KB)

Event Timeline