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

Run transitions in context of component #1675

Closed
Rich-Harris opened this issue Aug 22, 2018 · 2 comments · Fixed by #1680
Closed

Run transitions in context of component #1675

Rich-Harris opened this issue Aug 22, 2018 · 2 comments · Fixed by #1680

Comments

@Rich-Harris
Copy link
Member

I just tried to do this, to prevent a transition from running when a component is first rendered (in a situation where skipIntroByDefault isn't an option):

export default {
  transitions: {
    grow(node, params) {
      const { started } = this.get();
      if (!started) {
        return { duration: 0 };
      }

      const style = getComputedStyle(node);
      const w = parseFloat(style.width);
      const h = parseFloat(style.height);

      return {
        duration: 600,
        easing: eases.cubicOut,
        css: t => `opacity: ${t}; width: ${t * w}px; height: ${t * h}px;`
      };
    }
  }
};   

That doesn't work, because transition functions aren't called with component as context. In this case it was easy to fix by passing started as a parameter, but that wouldn't always be the case.

We could change this line:

export function wrapTransition(component, node, fn, params, intro) {
-	let obj = fn(node, params);
+	let obj = fn.call(component, node, params);
	let duration;
	let ease;

Any reason not to?

@jacwright
Copy link
Contributor

No, no reason not to.

@eyeseast
Copy link

This would've helped me on a project a while ago, where I needed to set a class on a ref as part of the transition.

I can think of lots of potentially dumb things someone might do with full access to the component during the transition -- setting or deleting things -- but maybe that's all fine.

kaisermann pushed a commit to kaisermann/svelte that referenced this issue Sep 19, 2018
run transitions in context of component
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants