Skip to content

Commit

Permalink
Merge pull request #963 from sveltejs/gh-962
Browse files Browse the repository at this point in the history
allow parameterised transitions
  • Loading branch information
Rich-Harris authored Nov 27, 2017
2 parents a717c82 + faf5ca8 commit b26be1c
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 58 deletions.
5 changes: 5 additions & 0 deletions src/generators/Generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,11 @@ export default class Generator {
});
this.skip();
}

if (node.type === 'Transition' && node.expression) {
node.metadata = contextualise(node.expression, contextDependencies, indexes);
this.skip();
}
},

leave(node: Node, parent: Node) {
Expand Down
6 changes: 3 additions & 3 deletions src/generators/dom/visitors/Element/addTransitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function addTransitions(
if (intro === outro) {
const name = block.getUniqueName(`${node.var}_transition`);
const snippet = intro.expression
? intro.expression.metadata.snippet
? intro.metadata.snippet
: '{}';

block.addVariable(name);
Expand Down Expand Up @@ -51,7 +51,7 @@ export default function addTransitions(
if (intro) {
block.addVariable(introName);
const snippet = intro.expression
? intro.expression.metadata.snippet
? intro.metadata.snippet
: '{}';

const fn = `%transitions-${intro.name}`; // TODO add built-in transitions?
Expand All @@ -76,7 +76,7 @@ export default function addTransitions(
if (outro) {
block.addVariable(outroName);
const snippet = outro.expression
? intro.expression.metadata.snippet
? outro.metadata.snippet
: '{}';

const fn = `%transitions-${outro.name}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ export default {
selected: [ values[1] ]
},

'skip-ssr': true, // values are rendered as [object Object]

html: `
<label>
<input type="checkbox"> Alpha
<input type="checkbox" value="[object Object]"> Alpha
</label>
<label>
<input type="checkbox"> Beta
<input type="checkbox" value="[object Object]"> Beta
</label>
<label>
<input type="checkbox"> Gamma
<input type="checkbox" value="[object Object]"> Gamma
</label>
<p>Beta</p>`,
Expand All @@ -40,15 +38,15 @@ export default {

assert.htmlEqual( target.innerHTML, `
<label>
<input type="checkbox"> Alpha
<input type="checkbox" value="[object Object]"> Alpha
</label>
<label>
<input type="checkbox"> Beta
<input type="checkbox" value="[object Object]"> Beta
</label>
<label>
<input type="checkbox"> Gamma
<input type="checkbox" value="[object Object]"> Gamma
</label>
<p>Alpha, Beta</p>
Expand All @@ -61,15 +59,15 @@ export default {

assert.htmlEqual( target.innerHTML, `
<label>
<input type="checkbox"> Alpha
<input type="checkbox" value="[object Object]"> Alpha
</label>
<label>
<input type="checkbox"> Beta
<input type="checkbox" value="[object Object]"> Beta
</label>
<label>
<input type="checkbox"> Gamma
<input type="checkbox" value="[object Object]"> Gamma
</label>
<p>Beta, Gamma</p>
Expand Down
20 changes: 9 additions & 11 deletions test/runtime/samples/binding-input-checkbox-group/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ export default {
selected: [ values[1] ]
},

'skip-ssr': true, // values are rendered as [object Object]

html: `
<label>
<input type="checkbox"> Alpha
<input type="checkbox" value="[object Object]"> Alpha
</label>
<label>
<input type="checkbox"> Beta
<input type="checkbox" value="[object Object]"> Beta
</label>
<label>
<input type="checkbox"> Gamma
<input type="checkbox" value="[object Object]"> Gamma
</label>
<p>Beta</p>`,
Expand All @@ -40,15 +38,15 @@ export default {

assert.htmlEqual( target.innerHTML, `
<label>
<input type="checkbox"> Alpha
<input type="checkbox" value="[object Object]"> Alpha
</label>
<label>
<input type="checkbox"> Beta
<input type="checkbox" value="[object Object]"> Beta
</label>
<label>
<input type="checkbox"> Gamma
<input type="checkbox" value="[object Object]"> Gamma
</label>
<p>Alpha, Beta</p>
Expand All @@ -61,15 +59,15 @@ export default {

assert.htmlEqual( target.innerHTML, `
<label>
<input type="checkbox"> Alpha
<input type="checkbox" value="[object Object]"> Alpha
</label>
<label>
<input type="checkbox"> Beta
<input type="checkbox" value="[object Object]"> Beta
</label>
<label>
<input type="checkbox"> Gamma
<input type="checkbox" value="[object Object]"> Gamma
</label>
<p>Beta, Gamma</p>
Expand Down
20 changes: 9 additions & 11 deletions test/runtime/samples/binding-input-radio-group/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,17 @@ export default {
selected: values[1]
},

'skip-ssr': true, // values are rendered as [object Object]

html: `
<label>
<input type="radio"> Alpha
<input type="radio" value="[object Object]"> Alpha
</label>
<label>
<input type="radio"> Beta
<input type="radio" value="[object Object]"> Beta
</label>
<label>
<input type="radio"> Gamma
<input type="radio" value="[object Object]"> Gamma
</label>
<p>Beta</p>`,
Expand All @@ -40,15 +38,15 @@ export default {

assert.htmlEqual( target.innerHTML, `
<label>
<input type="radio"> Alpha
<input type="radio" value="[object Object]"> Alpha
</label>
<label>
<input type="radio"> Beta
<input type="radio" value="[object Object]"> Beta
</label>
<label>
<input type="radio"> Gamma
<input type="radio" value="[object Object]"> Gamma
</label>
<p>Alpha</p>
Expand All @@ -65,15 +63,15 @@ export default {

assert.htmlEqual( target.innerHTML, `
<label>
<input type="radio"> Alpha
<input type="radio" value="[object Object]"> Alpha
</label>
<label>
<input type="radio"> Beta
<input type="radio" value="[object Object]"> Beta
</label>
<label>
<input type="radio"> Gamma
<input type="radio" value="[object Object]"> Gamma
</label>
<p>Gamma</p>
Expand Down
17 changes: 17 additions & 0 deletions test/runtime/samples/transition-js-parameterised/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
test(assert, component, target, window, raf) {
component.set({ visible: true });
const div = target.querySelector('div');
assert.equal(div.foo, 0);

raf.tick(50);
assert.equal(div.foo, 100);

raf.tick(100);
assert.equal(div.foo, 200);

raf.tick(101);

component.destroy();
},
};
18 changes: 18 additions & 0 deletions test/runtime/samples/transition-js-parameterised/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{#if visible}}
<div in:foo='{k: 200}'>fades in</div>
{{/if}}

<script>
export default {
transitions: {
foo: function(node, params) {
return {
duration: 100,
tick: t => {
node.foo = t * params.k;
}
};
}
}
};
</script>
Loading

0 comments on commit b26be1c

Please sign in to comment.