Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip and ref behaviour for vdom.elementVoid #744

Merged
merged 1 commit into from Aug 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/api/vdom.js
Expand Up @@ -3,7 +3,6 @@ import {
attributes,
elementClose,
elementOpen,
elementVoid,
skip,
symbols,
text,
Expand Down Expand Up @@ -247,11 +246,6 @@ function stackClose(tname) {
return tname(props, () => chren.forEach(args => args[0](...args[1])));
}

function stackVoid(...args) {
stackOpen(...args);
return stackClose(args[0]);
}

// Incremental DOM overrides
// -------------------------

Expand All @@ -268,7 +262,10 @@ const newElementOpen = wrapIdomFunc(elementOpen, stackOpen);
const newElementClose = wrapIdomFunc(elementClose, stackClose);

// Ensure we call our overridden functions instead of the internal ones.
const newElementVoid = wrapIdomFunc(elementVoid, stackVoid);
function newElementVoid(tag, ...args) {
newElementOpen(tag, ...args);
return newElementClose(tag);
}

// Text override ensures their calls can queue if using function helpers.
const newText = wrapIdomFunc(text);
Expand Down
12 changes: 12 additions & 0 deletions test/unit/vdom/ref.js
Expand Up @@ -73,12 +73,24 @@ function test(name, el) {

describe('vdom/ref', () => {
test('normal elements', 'div');

test('custom elements', define('x-test', {
render() {
vdom.element('slot');
},
}));

test('function helpers', (lprops, chren) => {
vdom.element('div', lprops, chren);
});

it('void elements', done => {
const Elem = define('x-test', {
render() {
vdom.elementVoid('div', null, null, 'ref', () => done());
},
});
const elem = new Elem();
fixture(elem);
});
});
19 changes: 19 additions & 0 deletions test/unit/vdom/skip.js
Expand Up @@ -129,4 +129,23 @@ describe('vdom/skip', () => {
done
);
});

it('re-rendering an void, skipped element should keep the mutated content', done => {
const Elem = define('x-test', {
props: {
test: {},
},
render() {
elementVoid('div', null, null, 'skip', true);
},
});
const elem = new Elem();
fixture(elem);
afterMutations(
() => (elem[symbols.shadowRoot].firstElementChild.textContent = 'testing'),
() => props(elem, { test: 0 }),
() => expect(elem[symbols.shadowRoot].firstElementChild.textContent).to.equal('testing'),
done
);
});
});