get a few transition tests passing

pull/1864/head
Rich Harris 7 years ago
parent be8b971104
commit 2b15ae3ad1

@ -521,7 +521,7 @@ export default class ElementWrapper extends Wrapper {
renderer.hasComplexBindings = true; renderer.hasComplexBindings = true;
block.builders.hydrate.addLine( block.builders.hydrate.addLine(
`if (!(${allInitialStateIsDefined})) #component.root._beforecreate.push(${handler});` `if (!(${allInitialStateIsDefined})) #component.$$root._beforecreate.push(${handler});`
); );
} }
@ -529,7 +529,7 @@ export default class ElementWrapper extends Wrapper {
renderer.hasComplexBindings = true; renderer.hasComplexBindings = true;
block.builders.hydrate.addLine( block.builders.hydrate.addLine(
`#component.root._beforecreate.push(${handler});` `#component.$$root._beforecreate.push(${handler});`
); );
} }
}); });
@ -723,10 +723,10 @@ export default class ElementWrapper extends Wrapper {
const fn = `ctx.${intro.name}`; const fn = `ctx.${intro.name}`;
block.builders.intro.addConditional(`#component.root._intro`, deindent` block.builders.intro.addConditional(`#component.$$root.$$intro`, deindent`
if (${name}) ${name}.invalidate(); if (${name}) ${name}.invalidate();
#component.root._aftercreate.push(() => { @after_update(() => {
if (!${name}) ${name} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true); if (!${name}) ${name} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true);
${name}.run(1); ${name}.run(1);
}); });
@ -760,8 +760,8 @@ export default class ElementWrapper extends Wrapper {
`); `);
} }
block.builders.intro.addConditional(`#component.root._intro`, deindent` block.builders.intro.addConditional(`#component.$$root.$$intro`, deindent`
#component.root._aftercreate.push(() => { @after_update(() => {
${introName} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true); ${introName} = @wrapTransition(#component, ${this.var}, ${fn}, ${snippet}, true);
${introName}.run(1); ${introName}.run(1);
}); });

@ -84,7 +84,7 @@ export default class InlineComponentWrapper extends Wrapper {
const name = this.var; const name = this.var;
const componentInitProperties = [ const componentInitProperties = [
`root: #component.root` `root: #component.$$root`
]; ];
if (this.fragment) { if (this.fragment) {
@ -289,7 +289,7 @@ export default class InlineComponentWrapper extends Wrapper {
`); `);
beforecreate = deindent` beforecreate = deindent`
#component.root._beforecreate.push(() => { #component.$$root._beforecreate.push(() => {
${name}._bind({ ${this.node.bindings.map(b => `${quoteNameIfNecessary(b.name)}: 1`).join(', ')} }, ${name}.get()); ${name}._bind({ ${this.node.bindings.map(b => `${quoteNameIfNecessary(b.name)}: 1`).join(', ')} }, ${name}.get());
}); });
`; `;
@ -377,7 +377,7 @@ export default class InlineComponentWrapper extends Wrapper {
${name} = new ${switch_value}(${switch_props}(ctx)); ${name} = new ${switch_value}(${switch_props}(ctx));
${this.node.bindings.length > 0 && deindent` ${this.node.bindings.length > 0 && deindent`
#component.root._beforecreate.push(() => { #component.$$root._beforecreate.push(() => {
const changed = {}; const changed = {};
${this.node.bindings.map(binding => deindent` ${this.node.bindings.map(binding => deindent`
if (${binding.value.snippet} === void 0) changed.${binding.name} = 1;`)} if (${binding.value.snippet} === void 0) changed.${binding.name} = 1;`)}

@ -10,8 +10,10 @@ export class SvelteComponent {
this.$$onupdate = []; this.$$onupdate = [];
this.$$ondestroy = []; this.$$ondestroy = [];
// TODO can we get rid of references to $$root and put
// the relevant code in the scheduler instead?
this.$$root = options.root || this;
this.$$callbacks = blankObject(); this.$$callbacks = blankObject();
this.$$slotted = options.slots; this.$$slotted = options.slots;
set_current_component(this); set_current_component(this);
@ -33,8 +35,10 @@ export class SvelteComponent {
this.$$fragment = this.$$create_fragment(this, this.$$.get_state()); this.$$fragment = this.$$create_fragment(this, this.$$.get_state());
if (options.target) { if (options.target) {
this.$$intro = false; // TODO can we put this in the scheduler instead?
this.$$mount(options.target); this.$$mount(options.target);
flush(); flush();
this.$$intro = true;
} }
} }

@ -1,6 +1,7 @@
let update_scheduled = false; let update_scheduled = false;
const dirty_components = []; const dirty_components = [];
const after_update_callbacks = [];
export function schedule_update(component) { export function schedule_update(component) {
dirty_components.push(component); dirty_components.push(component);
@ -10,11 +11,19 @@ export function schedule_update(component) {
} }
} }
export function after_update(fn) {
after_update_callbacks.push(fn);
}
export function flush() { export function flush() {
while (dirty_components.length) { while (dirty_components.length) {
dirty_components.pop().$$update(); dirty_components.pop().$$update();
} }
while (after_update_callbacks.length) {
after_update_callbacks.shift()();
}
update_scheduled = false; update_scheduled = false;
} }

@ -8,7 +8,7 @@ export default {
}, },
test(assert, component, target, window, raf) { test(assert, component, target, window, raf) {
const { things } = component.get(); const { things } = component;
component.things = []; component.things = [];
const spans = target.querySelectorAll('span'); const spans = target.querySelectorAll('span');

@ -1,6 +1,6 @@
export default { export default {
props: { props: {
foo: false, visible: false,
threshold: 5 threshold: 5
}, },

@ -1,5 +1,5 @@
<script> <script>
export let foo; export let visible;
export let threshold; export let threshold;
function foo(node) { function foo(node) {
@ -13,7 +13,7 @@
</script> </script>
{#each [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as number} {#each [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as number}
{#if foo} {#if visible}
{#if threshold >= number} {#if threshold >= number}
<div transition:foo>{number}</div> <div transition:foo>{number}</div>
{/if} {/if}

@ -1,6 +1,6 @@
export default { export default {
props: { props: {
foo: false, visible: false,
threshold: 5 threshold: 5
}, },

@ -1,5 +1,5 @@
<script> <script>
export let foo; export let visible;
export let threshold; export let threshold;
function foo(node) { function foo(node) {
@ -13,7 +13,7 @@
</script> </script>
{#each [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as number} {#each [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as number}
{#if foo} {#if visible}
{#if threshold >= number} {#if threshold >= number}
<div transition:foo>{number}</div> <div transition:foo>{number}</div>
{/if} {/if}

@ -14,7 +14,7 @@ export default {
assert.equal(window.getComputedStyle(div).opacity, 0); assert.equal(window.getComputedStyle(div).opacity, 0);
raf.tick(600); raf.tick(600);
assert.equal(component.refs.div, undefined); assert.equal(component.div, undefined);
assert.equal(target.querySelector('div'), undefined); assert.equal(target.querySelector('div'), undefined);
} }
}; };

@ -1,6 +1,5 @@
<script> <script>
export let div; export let div;
export let visible; export let visible;
function fade(node, params) { function fade(node, params) {

@ -4,17 +4,17 @@ export default {
}, },
test(assert, component, target, window, raf) { test(assert, component, target, window, raf) {
assert.equal(target.querySelector('div'), component.refs.no); assert.equal(target.querySelector('div'), component.no);
component.x = true; component.x = true;
raf.tick(25); raf.tick(25);
assert.equal(component.refs.yes.foo, undefined); assert.equal(component.yes.foo, undefined);
assert.equal(component.refs.no.foo, 0.75); assert.equal(component.no.foo, 0.75);
raf.tick(75); raf.tick(75);
assert.equal(component.refs.yes.foo, undefined); assert.equal(component.yes.foo, undefined);
assert.equal(component.refs.no.foo, 0.25); assert.equal(component.no.foo, 0.25);
raf.tick(100); raf.tick(100);
} }

@ -1,16 +1,16 @@
export default { export default {
test(assert, component, target, window, raf) { test(assert, component, target, window, raf) {
assert.equal(target.querySelector('div'), component.refs.no); assert.equal(target.querySelector('div'), component.no);
component.x = true; component.x = true;
raf.tick(25); raf.tick(25);
assert.equal(component.refs.yes.foo, undefined); assert.equal(component.yes.foo, undefined);
assert.equal(component.refs.no.foo, 0.75); assert.equal(component.no.foo, 0.75);
raf.tick(75); raf.tick(75);
assert.equal(component.refs.yes.foo, undefined); assert.equal(component.yes.foo, undefined);
assert.equal(component.refs.no.foo, 0.25); assert.equal(component.no.foo, 0.25);
raf.tick(100); raf.tick(100);
} }

@ -5,18 +5,18 @@ export default {
}, },
test(assert, component, target, window, raf) { test(assert, component, target, window, raf) {
assert.equal(target.querySelector('div'), component.refs.no); assert.equal(target.querySelector('div'), component.no);
component.x = true; component.x = true;
component.y = false; component.y = false;
raf.tick(25); raf.tick(25);
assert.equal(component.refs.yes.foo, undefined); assert.equal(component.yes.foo, undefined);
assert.equal(component.refs.no.foo, 0.75); assert.equal(component.no.foo, 0.75);
raf.tick(75); raf.tick(75);
assert.equal(component.refs.yes.foo, undefined); assert.equal(component.yes.foo, undefined);
assert.equal(component.refs.no.foo, 0.25); assert.equal(component.no.foo, 0.25);
raf.tick(100); raf.tick(100);
} }

@ -6,5 +6,5 @@
</script> </script>
{#if x} {#if x}
<Widget :things/> <Widget {things}/>
{/if} {/if}
Loading…
Cancel
Save