Code Monkey home page Code Monkey logo

Comments (3)

kfranqueiro avatar kfranqueiro commented on May 20, 2024

Kinda curious what the use case for hashes in particular is?

from compose.

kitsonk avatar kitsonk commented on May 20, 2024

When you have a lot of listeners to supply for different events. In particular it came up in the app factory, when configuring up certain instances, it is often easier to supply a map/hash, which is especially functional when combined with the terse method expression in object literals. It is also actually supported on creation already:

/* already works */
const evented = createEvented({
  listeners: {
    foo(evt) { /* handle event */ }
  }
});

/* also this would work with the change */
evented.on({
  bar(evt) { /* handle event */ },
  qat(evt) { /* handle event */ }
});

As a consumer, you can register for all the events you care about and get a single handle return which would disconnect those listeners.

You can also use additional ES6 syntax to make it even more concise (and more easy to read what you are doing):

function foo(evt: CustomEvent) { /* do something */ }
function bar(evt: CustomEvent) { /* do something */ }

evented.on({ foo, bar });

from compose.

kfranqueiro avatar kfranqueiro commented on May 20, 2024

Oh, I didn't think about it enabling shorthand with ES6 syntax. But yeah, I've at least had a couple of occasions in the past where I've wanted a handle for a group of events and did that myself for an array.

from compose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.