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

allow parameterised transitions #963

Merged
merged 3 commits into from
Nov 27, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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