swyxio/svelte-actions

Discuss high level policy

swyxio opened this issue · 4 comments

  • what is our criteria for inclusion in this library?
  • I have chosen not to camelcase the action names as i feel it is more like an event ("lazyload") than a function ("lazyLoad"). does it matter?
  • what else?

Can the library be open to generic utility actions or should it be reserved for more specific use cases?

Example: I needed a conditional click listener action the other day and realized that it could just be a conditional anything listener. Something like this (based on clickOutside):

function conditionalEvent(node, {condition, event, cb}) {
    function update(condition) {    
        if (condition) {
            node.addEventListener(event, cb); 
        } else {
            node.removeEventListener(event, cb);
        }
    }

    update(condition);

    return {
        update,
        destroy() {
            node.removeEventListener(event, cb);
        }
    }
}

This is kind of a trivial example, but that's the general idea. Let people wire up their own logic, but the boilerplate is taken care of. The other Svelte built-ins don't have something like this (transition and animate), but actions can apply to so many things and those two are more specific in their applications.

@kindoflew could you show a usage example? having trouble understanding how to use. in general am concerned about getting too meta too soon, but willing to consider if genuinely useful in many apps

This was just a generic example based off a use-case I had. I was submitting a PR (beyonk-group/svelte-carousel#56) to svelte-carousel. Basically, it's a carousel with an autoplay option and I needed to add a click-handler, but only if an autoplay duration was specified. My example above was a more generic version of that idea and might be useful for those writing libraries with components that have different needs depending on their configuration?

Anyway, my question was less about the example and more high-level asking about intent of the library I guess. In thinking of ideas for actions to submit/suggest I didn't know if they should be tailored to specific use cases or more like helper actions where the user would fill in the details. Not wanting to get too meta too soon kind of answers that though, I think.

thanks, yea the idea is that this isn't a library so much as a prototype for what would fit in svelte by default. prone to some bikshedding ofc but also have to consider things like documentation and time to usefulness. could also serve as inspiration (what can we do with actions? well, look at the default ones!)