Path: blob/master/webroot/rsrc/externals/javelin/ext/view/ViewVisitor.js
12242 views
/**1* @provides javelin-view-visitor2* @requires javelin-install3* javelin-util4*5* Add new behaviors to views without changing the view classes themselves.6*7* Allows you to register specific visitor functions for certain view classes.8* If no visitor is registered for a view class, the default_visitor is used.9* If no default_visitor is invoked, a no-op visitor is used.10*11* Registered visitors should be functions with signature12* function(view, results_of_visiting_children) {}13* Children are visited before their containing parents, and the return values14* of the visitor on the children are passed to the parent.15*16*/1718JX.install('ViewVisitor', {19construct: function(default_visitor) {20this._visitors = {};21this._default = default_visitor || JX.bag;22},23members: {24_visitors: null,25_default: null,26register: function(cls, visitor) {27this._visitors[cls] = visitor;28},29visit: function(view, children) {30var visitor = this._visitors[cls] || this._default;31return visitor(view, children);32}33}34});353637