| 1 | dojo.provide("dojox.lang.oo.Filter"); |
| 2 | |
| 3 | (function(){ |
| 4 | var oo = dojox.lang.oo, |
| 5 | |
| 6 | F = oo.Filter = function(bag, filter){ |
| 7 | // summary: |
| 8 | // Filter to control mixing in objects by skipping |
| 9 | // properties and renaming them. |
| 10 | // description: |
| 11 | // This object is used as a holder of an original object |
| 12 | // (whose properties are to be copied), and a filter |
| 13 | // function used while copying by dojox.lang.oo.mixin. |
| 14 | // bag: Object |
| 15 | // object to be filtered |
| 16 | // filter: Function|Object |
| 17 | // a function to handle the name filtering, |
| 18 | // or an object with exec() method |
| 19 | this.bag = bag; |
| 20 | this.filter = typeof filter == "object" ? |
| 21 | function(){ return filter.exec.apply(filter, arguments); } : filter; |
| 22 | }, |
| 23 | |
| 24 | // the default map-based filter object |
| 25 | MapFilter = function(map){ |
| 26 | this.map = map; |
| 27 | }; |
| 28 | |
| 29 | MapFilter.prototype.exec = function(name){ |
| 30 | return this.map.hasOwnProperty(name) ? this.map[name] : name; |
| 31 | }; |
| 32 | |
| 33 | oo.filter = function(bag, map){ |
| 34 | // summary: |
| 35 | // creates a simple filter object |
| 36 | // bag: Object |
| 37 | // object to be filtered |
| 38 | // map: Object |
| 39 | // the dictionary for renaming/removing while copying |
| 40 | // returns: |
| 41 | // new dojox.lang.oo.Filter object |
| 42 | return new F(bag, new MapFilter(map)); |
| 43 | }; |
| 44 | })(); |