[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 /** 2 * @provides javelin-view-visitor 3 * @requires javelin-install 4 * javelin-util 5 * 6 * Add new behaviors to views without changing the view classes themselves. 7 * 8 * Allows you to register specific visitor functions for certain view classes. 9 * If no visitor is registered for a view class, the default_visitor is used. 10 * If no default_visitor is invoked, a no-op visitor is used. 11 * 12 * Registered visitors should be functions with signature 13 * function(view, results_of_visiting_children) {} 14 * Children are visited before their containing parents, and the return values 15 * of the visitor on the children are passed to the parent. 16 * 17 */ 18 19 JX.install('ViewVisitor', { 20 construct: function(default_visitor) { 21 this._visitors = {}; 22 this._default = default_visitor || JX.bag; 23 }, 24 members: { 25 _visitors: null, 26 _default: null, 27 register: function(cls, visitor) { 28 this._visitors[cls] = visitor; 29 }, 30 visit: function(view, children) { 31 var visitor = this._visitors[cls] || this._default; 32 return visitor(view, children); 33 } 34 } 35 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |