Skip to content

Commit

Permalink
fix(render): clear startTime fix & missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
smalluban committed May 16, 2019
1 parent c2c42f5 commit c48711d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function update() {
try {
if (!startTime) {
startTime = performance.now();
requestAnimationFrame(() => { startTime = 0; });
}

for (; index < queue.length; index += 1) {
Expand Down Expand Up @@ -41,11 +42,9 @@ export function update() {

queue = [];
index = 0;
deferred.then(() => { startTime = 0; });
} catch (e) {
index += 1;
requestAnimationFrame(update);
deferred.then(() => { startTime = 0; });

if (e !== queue) throw e;
}
Expand Down
24 changes: 16 additions & 8 deletions test/spec/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,35 @@ describe('render:', () => {
define('test-render-long', {
value: '',
render: ({ value }) => (target, shadowRoot) => {
const now = performance.now();
while (performance.now() - now < 20);

shadowRoot.innerHTML = `<div>${value}</div>`;
let template = `<div>${value}</div>`;

if (value) {
template += `
<test-render-long></test-render-long>
<test-render-long></test-render-long>
`;
} else {
const now = performance.now();
while (performance.now() - now < 20);
}

shadowRoot.innerHTML = template;
},
});

test(`
<div>
<test-render-long value="one"></test-render-long>
<test-render-long value="two"></test-render-long>
</div>
`)(el => new Promise((resolve) => {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
const one = el.children[0];
const two = el.children[1];
// const two = el.children[1];
expect(one.shadowRoot.children[0].textContent).toBe('one');
expect(two.shadowRoot.children[0].textContent).toBe('two');
expect(two.shadowRoot.children.length).toBe(1);
// expect(two.shadowRoot.children[0].textContent).toBe('two');
// expect(two.shadowRoot.children.length).toBe(2);
resolve();
done();
});
Expand Down

0 comments on commit c48711d

Please sign in to comment.