-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add skip function to allow skipping subtrees dynamically.
- Loading branch information
sparhami
committed
Oct 29, 2015
1 parent
e5974d6
commit 35b0f3c
Showing
4 changed files
with
79 additions
and
6 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 |
---|---|---|
|
@@ -20,7 +20,10 @@ import { | |
} from './alignment'; | ||
import { updateAttribute } from './attributes'; | ||
import { getData } from './node_data'; | ||
import { getContext } from './context'; | ||
import { | ||
getContext, | ||
currentElement | ||
} from './context'; | ||
import { | ||
firstChild, | ||
nextSibling, | ||
|
@@ -116,6 +119,18 @@ if (process.env.NODE_ENV !== 'production') { | |
} | ||
|
||
|
||
/** | ||
* Skips the children in a subtree, allowing an Element to be closed without | ||
* clearing out the children. | ||
*/ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sparhami
Contributor
|
||
var skip = function() { | ||
var openElement = currentElement(); | ||
var data = getData(openElement); | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
jridgewell
Contributor
|
||
data.lastVisitedChild = openElement.lastChild; | ||
}; | ||
|
||
|
||
/** | ||
* @param {string} tag The element's tag. | ||
* @param {?string=} key The key used to identify this element. This can be an | ||
|
@@ -307,10 +322,9 @@ var elementPlaceholder = function(tag, key, statics, var_args) { | |
assertPlaceholderKeySpecified(key); | ||
} | ||
|
||
var node = elementOpen.apply(null, arguments); | ||
updateAttribute(node, symbols.placeholder, true); | ||
elementClose.apply(null, arguments); | ||
return node; | ||
elementOpen.apply(null, arguments); | ||
skip(); | ||
return elementClose.apply(null, arguments); | ||
}; | ||
|
||
|
||
|
@@ -355,6 +369,7 @@ export { | |
elementVoid, | ||
elementClose, | ||
elementPlaceholder, | ||
skip, | ||
text, | ||
attr | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/** | ||
* Copyright 2015 The Incremental DOM Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { | ||
patch, | ||
elementOpen, | ||
elementClose, | ||
skip, | ||
text | ||
} from '../../index'; | ||
|
||
describe('skip', () => { | ||
var container; | ||
|
||
beforeEach(() => { | ||
container = document.createElement('div'); | ||
document.body.appendChild(container); | ||
}); | ||
|
||
afterEach(() => { | ||
document.body.removeChild(container); | ||
}); | ||
|
||
function render(data) { | ||
elementOpen('div'); | ||
if (data.skip) { | ||
skip(); | ||
} else { | ||
text('some '); | ||
text('text'); | ||
} | ||
elementClose('div'); | ||
} | ||
|
||
it('should keep any DOM nodes in the subtree', () => { | ||
patch(container, render, { skip: false }); | ||
patch(container, render, { skip: true }); | ||
|
||
expect(container.textContent).to.equal('some text'); | ||
}); | ||
|
||
}); | ||
|
Mind doing this in a PR next time? There are other things like the
placeholder
attribute that could be removed with this.