| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // TODO(jmesserly): more commentary here. | |
| 6 /** | |
| 7 * Template and node binding for HTML elements. | |
| 8 * | |
| 9 * This library provides access to the Polymer project's | |
| 10 * [Template Binding](http://www.polymer-project.org/platform/template.html) and | |
| 11 * [Node.bind()](http://www.polymer-project.org/platform/node_bind.html) APIs. | |
| 12 * Find more information at the | |
| 13 * [Polymer.dart homepage](https://www.dartlang.org/polymer-dart/). | |
| 14 */ | |
| 15 library mdv; | |
| 16 | |
| 17 import 'dart:async'; | |
| 18 import 'dart:collection'; | |
| 19 import 'dart:html'; | |
| 20 import 'package:observe/observe.dart'; | |
| 21 | |
| 22 import 'src/list_diff.dart' show calculateSplices, ListChangeDelta; | |
| 23 | |
| 24 part 'src/element.dart'; | |
| 25 part 'src/input_bindings.dart'; | |
| 26 part 'src/input_element.dart'; | |
| 27 part 'src/node.dart'; | |
| 28 part 'src/select_element.dart'; | |
| 29 part 'src/template.dart'; | |
| 30 part 'src/template_iterator.dart'; | |
| 31 part 'src/text.dart'; | |
| 32 part 'src/text_area_element.dart'; | |
| 33 | |
| 34 /** Initialize the Model-Driven Views polyfill. */ | |
| 35 void initialize() { | |
| 36 TemplateElement.mdvPackage = _mdv; | |
| 37 } | |
| 38 | |
| 39 | |
| 40 typedef DocumentFragmentCreated(DocumentFragment fragment); | |
| 41 | |
| 42 // TODO(jmesserly): ideally this would be a stream, but they don't allow | |
| 43 // reentrancy. | |
| 44 Set<DocumentFragmentCreated> _instanceCreated; | |
| 45 | |
| 46 /** | |
| 47 * *Warning*: This is an implementation helper for Model-Driven Views and | |
| 48 * should not be used in your code. | |
| 49 * | |
| 50 * This event is fired whenever a template is instantiated via | |
| 51 * [Element.createInstance]. | |
| 52 */ | |
| 53 // TODO(rafaelw): This is a hack, and is neccesary for the polyfill | |
| 54 // because custom elements are not upgraded during clone() | |
| 55 // TODO(jmesserly): polymer removed this in: | |
| 56 // https://github.com/Polymer/platform/commit/344ffeaae475babb529403f6608588a0fc
73f4e7 | |
| 57 Set<DocumentFragmentCreated> get instanceCreated { | |
| 58 if (_instanceCreated == null) { | |
| 59 _instanceCreated = new Set<DocumentFragmentCreated>(); | |
| 60 } | |
| 61 return _instanceCreated; | |
| 62 } | |
| 63 | |
| 64 | |
| 65 // TODO(jmesserly): investigate if expandos give us enough performance. | |
| 66 | |
| 67 // The expando for storing our MDV wrappers. | |
| 68 // | |
| 69 // In general, we need state associated with the nodes. Rather than having a | |
| 70 // bunch of individual expandos, we keep one per node. | |
| 71 // | |
| 72 // Aside from the potentially helping performance, it also keeps things simpler | |
| 73 // if we decide to integrate MDV into the DOM later, and means less code needs | |
| 74 // to worry about expandos. | |
| 75 final Expando _mdvExpando = new Expando('mdv'); | |
| 76 | |
| 77 _mdv(node) { | |
| 78 var wrapper = _mdvExpando[node]; | |
| 79 if (wrapper != null) return wrapper; | |
| 80 | |
| 81 if (node is InputElement) { | |
| 82 wrapper = new _InputElementExtension(node); | |
| 83 } else if (node is SelectElement) { | |
| 84 wrapper = new _SelectElementExtension(node); | |
| 85 } else if (node is TextAreaElement) { | |
| 86 wrapper = new _TextAreaElementExtension(node); | |
| 87 } else if (node is Element) { | |
| 88 if (node.isTemplate) { | |
| 89 wrapper = new _TemplateExtension(node); | |
| 90 } else { | |
| 91 wrapper = new _ElementExtension(node); | |
| 92 } | |
| 93 } else if (node is Text) { | |
| 94 wrapper = new _TextExtension(node); | |
| 95 } else if (node is Node) { | |
| 96 wrapper = new _NodeExtension(node); | |
| 97 } else { | |
| 98 // TODO(jmesserly): this happens for things like CompoundBinding. | |
| 99 wrapper = node; | |
| 100 } | |
| 101 | |
| 102 _mdvExpando[node] = wrapper; | |
| 103 return wrapper; | |
| 104 } | |
| OLD | NEW |