This repository was archived by the owner on Feb 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 216
feat(blockhole): Change blockhole to have the insert / remove / move instead of block #689
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,104 +1,61 @@ | ||
part of angular.core.dom; | ||
|
||
/** | ||
* ElementWrapper is an interface for [Block]s and [BlockHole]s. Its purpose is | ||
* to allow treating [Block] and [BlockHole] under same interface so that | ||
* [Block]s can be added after [BlockHole]. | ||
*/ | ||
abstract class ElementWrapper { | ||
List<dom.Node> elements; | ||
ElementWrapper next; | ||
ElementWrapper previous; | ||
} | ||
|
||
/** | ||
* A Block is a fundamental building block of DOM. It is a chunk of DOM which | ||
* can not be structural changed. It can only have its attributes changed. | ||
* A Block can have [BlockHole]s embedded in its DOM. A [BlockHole] can | ||
* contain other [Block]s and it is the only way in which DOM can be changed | ||
* structurally. | ||
* can not be structurally changed. A Block can have [BlockHole] placeholders | ||
* embedded in its DOM. A [BlockHole] can contain other [Block]s and it is the | ||
* only way in which DOM structure can be modified. | ||
* | ||
* A [Block] is a collection of DOM nodes | ||
* | ||
|
||
* A [Block] can be created from [BlockFactory]. | ||
* | ||
*/ | ||
class Block implements ElementWrapper { | ||
List<dom.Node> elements; | ||
ElementWrapper next; | ||
ElementWrapper previous; | ||
class Block { | ||
final List<dom.Node> nodes; | ||
Block(this.nodes); | ||
} | ||
|
||
/** | ||
* A BlockHole maintains an ordered list of [Block]'s. It contains a | ||
* [placeholder] node that is used as the insertion point for block nodes. | ||
*/ | ||
class BlockHole { | ||
final dom.Node placeholder; | ||
final NgAnimate _animate; | ||
final List<Block> _blocks = <Block>[]; | ||
|
||
Block(this.elements, this._animate); | ||
|
||
Block insertAfter(ElementWrapper previousBlock) { | ||
// Update Link List. | ||
next = previousBlock.next; | ||
if (next != null) { | ||
next.previous = this; | ||
} | ||
previous = previousBlock; | ||
previousBlock.next = this; | ||
BlockHole(this.placeholder, this._animate); | ||
|
||
// Update DOM | ||
List<dom.Node> previousElements = previousBlock.elements; | ||
dom.Node previousElement = previousElements[previousElements.length - 1]; | ||
dom.Node insertBeforeElement = previousElement.nextNode; | ||
dom.Node parentElement = previousElement.parentNode; | ||
void insert(Block block, { Block insertAfter }) { | ||
dom.Node previousNode = _lastNode(insertAfter); | ||
_blocksInsertAfter(block, insertAfter); | ||
|
||
_animate.insert(elements, parentElement, insertBefore: insertBeforeElement); | ||
|
||
return this; | ||
_animate.insert(block.nodes, placeholder.parentNode, | ||
insertBefore: previousNode.nextNode); | ||
} | ||
|
||
Block remove() { | ||
bool preventDefault = false; | ||
|
||
_animate.remove(elements); | ||
|
||
// Remove block from list | ||
if (previous != null && (previous.next = next) != null) { | ||
next.previous = previous; | ||
} | ||
next = previous = null; | ||
return this; | ||
void remove(Block block) { | ||
_blocks.remove(block); | ||
_animate.remove(block.nodes); | ||
} | ||
|
||
Block moveAfter(ElementWrapper previousBlock) { | ||
var previousElements = previousBlock.elements, | ||
previousElement = previousElements[previousElements.length - 1], | ||
insertBeforeElement = previousElement.nextNode, | ||
parentElement = previousElement.parentNode; | ||
|
||
elements.forEach((el) => parentElement.insertBefore(el, insertBeforeElement)); | ||
void move(Block block, { Block moveAfter }) { | ||
dom.Node previousNode = _lastNode(moveAfter); | ||
_blocks.remove(block); | ||
_blocksInsertAfter(block, moveAfter); | ||
|
||
// Remove block from list | ||
previous.next = next; | ||
if (next != null) { | ||
next.previous = previous; | ||
} | ||
// Add block to list | ||
next = previousBlock.next; | ||
if (next != null) { | ||
next.previous = this; | ||
} | ||
previous = previousBlock; | ||
previousBlock.next = this; | ||
return this; | ||
_animate.move(block.nodes, placeholder.parentNode, | ||
insertBefore: previousNode.nextNode); | ||
} | ||
} | ||
|
||
/** | ||
* A BlockHole is an instance of a hole. BlockHoles designate where child | ||
* [Block]s can be added in parent [Block]. BlockHoles wrap a DOM element, | ||
* and act as references which allows more blocks to be added. | ||
*/ | ||
class BlockHole extends ElementWrapper { | ||
List<dom.Node> elements; | ||
ElementWrapper previous; | ||
ElementWrapper next; | ||
void _blocksInsertAfter(Block block, Block insertAfter) { | ||
int index = (insertAfter != null) ? _blocks.indexOf(insertAfter) : -1; | ||
_blocks.insert(index + 1, block); | ||
} | ||
|
||
BlockHole(this.elements); | ||
dom.Node _lastNode(Block insertAfter) => | ||
insertAfter == null | ||
? placeholder | ||
: insertAfter.nodes[insertAfter.nodes.length - 1]; | ||
} | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_childBlocks ?