Skip to content

run transitions in context of component #1680

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

Merged
merged 1 commit into from
Aug 24, 2018
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
4 changes: 0 additions & 4 deletions src/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ export function on(eventName, handler) {
};
}

export function run(fn) {
fn();
}

export function set(newState) {
this._set(assign({}, newState));
if (this.root._lock) return;
Expand Down
8 changes: 3 additions & 5 deletions src/shared/transitions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createElement } from './dom.js';
import { noop } from './utils.js';
import { noop, run } from './utils.js';

export function linear(t) {
return t;
Expand Down Expand Up @@ -27,7 +27,7 @@ export function hash(str) {
}

export function wrapTransition(component, node, fn, params, intro) {
let obj = fn(node, params);
let obj = fn.call(component, node, params);
let duration;
let ease;
let cssText;
Expand Down Expand Up @@ -137,9 +137,7 @@ export function wrapTransition(component, node, fn, params, intro) {
});

if (--program.group.remaining === 0) {
program.group.callbacks.forEach(fn => {
fn();
});
program.group.callbacks.forEach(run);
}
} else {
if (obj.css) transitionManager.deleteRule(node, program.name);
Expand Down
4 changes: 4 additions & 0 deletions src/shared/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ export function exclude(src, prop) {
const tar = {};
for (const k in src) k === prop || (tar[k] = src[k]);
return tar;
}

export function run(fn) {
fn();
}
9 changes: 9 additions & 0 deletions test/runtime/samples/transition-js-context/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
test(assert, component, target, window, raf) {
const div = target.querySelector('div');
assert.equal(div.foo, 42);

raf.tick(50);
assert.equal(div.foo, 42);
}
};
20 changes: 20 additions & 0 deletions test/runtime/samples/transition-js-context/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div transition:foo></div>

<script>
export default {
data() {
return { x: 42 };
},

transitions: {
foo(node, params) {
return {
duration: 100,
tick: t => {
node.foo = this.get().x;
}
};
}
}
};
</script>