This repository has been archived by the owner on Feb 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(NodeCursor): Removes nodeList() in favor of current
Closes #644
- Loading branch information
Showing
4 changed files
with
77 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,49 @@ | ||
part of angular.core.dom; | ||
|
||
class NodeCursor { | ||
List<dynamic> stack = []; | ||
final stack = []; | ||
List<dom.Node> elements; | ||
int index; | ||
int index = 0; | ||
|
||
NodeCursor(this.elements) : index = 0; | ||
NodeCursor(this.elements); | ||
|
||
isValid() => index < elements.length; | ||
bool moveNext() => ++index < elements.length; | ||
|
||
cursorSize() => 1; | ||
dom.Node get current => index < elements.length ? elements[index] : null; | ||
|
||
macroNext() { | ||
for (var i = 0, ii = cursorSize(); i < ii; i++, index++){} | ||
|
||
return this.isValid(); | ||
} | ||
|
||
microNext() { | ||
var length = elements.length; | ||
|
||
if (index < length) { | ||
index++; | ||
} | ||
|
||
return index < length; | ||
} | ||
|
||
nodeList() { | ||
if (!isValid()) return []; // or should we return null? | ||
|
||
return elements.sublist(index, index + cursorSize()); | ||
} | ||
|
||
descend() { | ||
bool descend() { | ||
var childNodes = elements[index].nodes; | ||
var hasChildren = childNodes != null && childNodes.length > 0; | ||
var hasChildren = childNodes != null && childNodes.isNotEmpty; | ||
|
||
if (hasChildren) { | ||
stack.add(index); | ||
stack.add(elements); | ||
stack..add(index)..add(elements); | ||
elements = new List.from(childNodes); | ||
index = 0; | ||
} | ||
|
||
return hasChildren; | ||
} | ||
|
||
ascend() { | ||
void ascend() { | ||
elements = stack.removeLast(); | ||
index = stack.removeLast(); | ||
} | ||
|
||
insertAnchorBefore(String name) { | ||
var current = elements[index]; | ||
void insertAnchorBefore(String name) { | ||
var parent = current.parentNode; | ||
|
||
var anchor = new dom.Comment('ANCHOR: $name'); | ||
|
||
elements.insert(index++, anchor); | ||
|
||
if (parent != null) { | ||
parent.insertBefore(anchor, current); | ||
} | ||
if (parent != null) parent.insertBefore(anchor, current); | ||
} | ||
|
||
replaceWithAnchor(String name) { | ||
NodeCursor replaceWithAnchor(String name) { | ||
insertAnchorBefore(name); | ||
var childCursor = remove(); | ||
this.index--; | ||
return childCursor; | ||
} | ||
|
||
remove() { | ||
var nodes = nodeList(); | ||
|
||
for (var i = 0; i < nodes.length; i++) { | ||
// NOTE(deboer): If elements is a list of child nodes on a node, then | ||
// calling Node.remove() may also remove it from the list. Thus, we | ||
// call elements.removeAt first so only one node is removed. | ||
elements.removeAt(index); | ||
nodes[i].remove(); | ||
} | ||
|
||
return new NodeCursor(nodes); | ||
} | ||
NodeCursor remove() => new NodeCursor([elements.removeAt(index)..remove()]); | ||
|
||
isInstance() => false; | ||
bool get isInstance => false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters