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

Reactivity: Modifiers #18

Open
kategengler opened this issue Jan 22, 2024 · 2 comments
Open

Reactivity: Modifiers #18

kategengler opened this issue Jan 22, 2024 · 2 comments
Assignees

Comments

@kategengler
Copy link
Member

No description provided.

@kategengler kategengler converted this from a draft issue Jan 22, 2024
@kategengler kategengler moved this from Todo to Blocked in Polaris Edition of Ember Mar 18, 2024
@kategengler
Copy link
Member Author

Possibly descoped from Polaris after discussion at 2024 f2f.

@NullVoxPopuli
Copy link

I think the design is easy once we ship resources (looking at pure public API perspective)

import { Resource } from '@ember/primitives'; // starbeam? 🤷 

function wiggle(element, howMuch, options = {}) {
  let animate = () => { /* omitted for brevity */ };
  
  return Resource(({ on }) => {
    element.addEventListener('mouseover', animate);
    
    // aka 'on.cleanup'
    on.finalize(() => element.removeEventListener('mouseover', animate);
  });
}

<template>
  <h1 {{wiggle "a lot" color="random"}}>Hello there!</h1>
</template>

which... maybe we abstract to:

import { Modifier } from '@ember/primitives';

const wiggle = Modifier(({ on, element }, howMuch, options = {}) => {
  let animate = () => { /* omitted for brevity */ };
  
  element.addEventListener('mouseover', animate);
  
  on.finalize(() => element.removeEventListener('mouseover', animate);
  // also available (on is from resource, so that whole API)
  // on.sync(() => {})
});

<template>
  <h1 {{wiggle "a lot" color="random"}}>Hello there!</h1>
</template>

@wycats and I will try to get more aggressive at figuring out what we want for an RFC -- and I'll report back here (I through something on his calendar for tomorrow)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Blocked
Development

No branches or pull requests

3 participants