| OLD | NEW |
| 1 Sky DOM APIs | 1 Sky DOM APIs |
| 2 ============ | 2 ============ |
| 3 | 3 |
| 4 ```dart | 4 ```dart |
| 5 SKY MODULE | 5 SKY MODULE |
| 6 <!-- part of sky:core --> | 6 <!-- part of sky:core --> |
| 7 | 7 |
| 8 <script> | 8 <script> |
| 9 // ELEMENT TREE API | 9 // ELEMENT TREE API |
| 10 | 10 |
| 11 abstract class Node extends EventTarget { | 11 abstract class Node extends EventTarget { |
| 12 @override | 12 @override |
| 13 external List<EventTarget> getEventDispatchChain(); // O(N) in number of ances
tors across shadow trees | 13 external List<EventTarget> getEventDispatchChain(); // O(N) in number of ances
tors across shadow trees |
| 14 // implements EventTarget.getEventDispatchChain() | 14 // implements EventTarget.getEventDispatchChain() |
| 15 // returns the event dispatch chain (including handling shadow trees) | 15 // returns the event dispatch chain (including handling shadow trees) |
| 16 | 16 |
| 17 external Root get owner; // O(1) | 17 external Root get owner; // O(1) |
| 18 | 18 |
| 19 external ParentNode get parentNode; // O(1) | 19 external ParentNode get parentNode; // O(1) |
| 20 external Element get parentElement; // O(1) // if parentNode isn't an element,
returns null | 20 external Element get parentElement; // O(1) // if parentNode isn't an element,
returns null |
| 21 external Node get previousSibling; // O(1) | 21 external Node get previousSibling; // O(1) |
| 22 external Node get nextSibling; // O(1) | 22 external Node get nextSibling; // O(1) |
| 23 | 23 |
| 24 // the following all throw if parentNode is null | 24 // the following all throw if parentNode is null |
| 25 external void insertBefore(List nodes); // O(N) in number of arguments plus al
l their descendants | 25 external void insertBefore(List nodes); // O(N) in number of arguments plus al
l their descendants |
| 26 external void insertAfter(List nodes); // O(N) in number of arguments plus all
their descendants | 26 external void insertAfter(List nodes); // O(N) in number of arguments plus all
their descendants |
| 27 // TODO(ianh): rename insertBefore() and insertAfter() since the Web has an in
sertBefore() that means |
| 28 // something else. What's a good name, though? |
| 27 external void replaceWith(List nodes); // O(N) in number of descendants plus a
rguments plus all their descendants | 29 external void replaceWith(List nodes); // O(N) in number of descendants plus a
rguments plus all their descendants |
| 28 // nodes must be String, Text, or Element | 30 // nodes must be String, Text, or Element |
| 29 | 31 |
| 30 external void remove(); // O(N) in number of descendants | 32 external void remove(); // O(N) in number of descendants |
| 31 | 33 |
| 32 // called when parentNode changes | 34 // called when parentNode changes |
| 33 // this is why insertBefore(), append(), et al, are O(N) -- the whole affected
subtree is walked | 35 // this is why insertBefore(), append(), et al, are O(N) -- the whole affected
subtree is walked |
| 34 // mutating the element tree from within this is strongly discouraged, since i
t will result in the | 36 // mutating the element tree from within this is strongly discouraged, since i
t will result in the |
| 35 // callbacks being invoked while the element tree is in a different state than
implied by the callbacks | 37 // callbacks being invoked while the element tree is in a different state than
implied by the callbacks |
| 36 external void parentChangeCallback(ParentNode oldParent, ParentNode newParent,
Node previousSibling, Node nextSibling); // O(N) in descendants | 38 external void parentChangeCallback(ParentNode oldParent, ParentNode newParent,
Node previousSibling, Node nextSibling); // O(N) in descendants |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 abstract class ParentNode extends Node { | 71 abstract class ParentNode extends Node { |
| 70 external Node get firstChild; // O(1) | 72 external Node get firstChild; // O(1) |
| 71 external Node get lastChild; // O(1) | 73 external Node get lastChild; // O(1) |
| 72 | 74 |
| 73 // Returns a new List every time. | 75 // Returns a new List every time. |
| 74 external List<Node> getChildren(); // O(N) in number of child nodes | 76 external List<Node> getChildren(); // O(N) in number of child nodes |
| 75 external List<Element> getChildElements(); // O(N) in number of child nodes | 77 external List<Element> getChildElements(); // O(N) in number of child nodes |
| 76 // TODO(ianh): might not be necessary if we have the parser drop unnecessary w
hitespace text nodes | 78 // TODO(ianh): might not be necessary if we have the parser drop unnecessary w
hitespace text nodes |
| 77 | 79 |
| 78 external void append(List nodes); // O(N) in number of arguments plus all thei
r descendants | 80 external void append(List nodes); // O(N) in number of arguments plus all thei
r descendants |
| 79 external void appendSingle(Node nodes); // O(N) in number of descandants | 81 external void appendChild(Node child); // O(N) in number of descandants |
| 80 external void prepend(List nodes); // O(N) in number of arguments plus all the
ir descendants | 82 external void prepend(List nodes); // O(N) in number of arguments plus all the
ir descendants |
| 81 external void replaceChildrenWith(List nodes); // O(N) in number of descendant
s plus arguments plus all their descendants | 83 external void replaceChildrenWith(List nodes); // O(N) in number of descendant
s plus arguments plus all their descendants |
| 82 // nodes must be String, Text, or Element | 84 // nodes must be String, Text, or Element |
| 83 } | 85 } |
| 84 | 86 |
| 85 class Attr { | 87 class Attr { |
| 86 const Attr (this.name, [this.value = '']); // O(1) | 88 const Attr (this.name, [this.value = '']); // O(1) |
| 87 final String name; // O(1) | 89 final String name; // O(1) |
| 88 final String value; // O(1) | 90 final String value; // O(1) |
| 89 } | 91 } |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 external bool matches(Element element); // O(F()) | 292 external bool matches(Element element); // O(F()) |
| 291 external Element find(node root); // O(N*F())+O(M) where N is the number of de
scendants and M the average depth of the tree | 293 external Element find(node root); // O(N*F())+O(M) where N is the number of de
scendants and M the average depth of the tree |
| 292 external List<Element> findAll(Node root); // O(N*F())+O(N*M) where N is the n
umber of descendants and M the average depth of the tree | 294 external List<Element> findAll(Node root); // O(N*F())+O(N*M) where N is the n
umber of descendants and M the average depth of the tree |
| 293 // find() and findAll() throw if the root is not one of the following: | 295 // find() and findAll() throw if the root is not one of the following: |
| 294 // - Element | 296 // - Element |
| 295 // - Fragment | 297 // - Fragment |
| 296 // - Root | 298 // - Root |
| 297 } | 299 } |
| 298 </script> | 300 </script> |
| 299 ``` | 301 ``` |
| OLD | NEW |