| OLD | NEW |
| (Empty) |
| 1 part of angular.core.dom_internal; | |
| 2 | |
| 3 /** | |
| 4 * A View is a fundamental building block of DOM. It is a chunk of DOM which | |
| 5 * can not be structurally changed. A View can have [ViewPort] placeholders | |
| 6 * embedded in its DOM. A [ViewPort] can contain other [View]s and it is the | |
| 7 * only way in which DOM structure can be modified. | |
| 8 * | |
| 9 * A [View] is a collection of DOM nodes | |
| 10 | |
| 11 * A [View] can be created from [ViewFactory]. | |
| 12 * | |
| 13 */ | |
| 14 class View { | |
| 15 final List<dom.Node> nodes; | |
| 16 final EventHandler eventHandler; | |
| 17 | |
| 18 View(this.nodes, this.eventHandler); | |
| 19 | |
| 20 void registerEvent(String eventName) { | |
| 21 eventHandler.register(eventName); | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 /** | |
| 26 * A ViewPort maintains an ordered list of [View]'s. It contains a | |
| 27 * [placeholder] node that is used as the insertion point for view nodes. | |
| 28 */ | |
| 29 class ViewPort { | |
| 30 final dom.Node placeholder; | |
| 31 final Animate _animate; | |
| 32 final _views = <View>[]; | |
| 33 | |
| 34 ViewPort(this.placeholder, this._animate); | |
| 35 | |
| 36 void insert(View view, { View insertAfter }) { | |
| 37 dom.Node previousNode = _lastNode(insertAfter); | |
| 38 _viewsInsertAfter(view, insertAfter); | |
| 39 | |
| 40 _animate.insert(view.nodes, placeholder.parentNode, | |
| 41 insertBefore: previousNode.nextNode); | |
| 42 } | |
| 43 | |
| 44 void remove(View view) { | |
| 45 _views.remove(view); | |
| 46 _animate.remove(view.nodes); | |
| 47 } | |
| 48 | |
| 49 void move(View view, { View moveAfter }) { | |
| 50 dom.Node previousNode = _lastNode(moveAfter); | |
| 51 _views.remove(view); | |
| 52 _viewsInsertAfter(view, moveAfter); | |
| 53 | |
| 54 _animate.move(view.nodes, placeholder.parentNode, | |
| 55 insertBefore: previousNode.nextNode); | |
| 56 } | |
| 57 | |
| 58 void _viewsInsertAfter(View view, View insertAfter) { | |
| 59 int index = insertAfter == null ? 0 : _views.indexOf(insertAfter) + 1; | |
| 60 _views.insert(index, view); | |
| 61 } | |
| 62 | |
| 63 dom.Node _lastNode(View insertAfter) => | |
| 64 insertAfter == null | |
| 65 ? placeholder | |
| 66 : insertAfter.nodes.last; | |
| 67 } | |
| OLD | NEW |