Skip to content

Commit

Permalink
allow parameterised transitions - fixes #962
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Nov 27, 2017
1 parent a717c82 commit ada52c7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 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
19 changes: 19 additions & 0 deletions test/runtime/samples/transition-js-parameterised/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default {
solo: true,

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>

0 comments on commit ada52c7

Please sign in to comment.