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

extendable custom events for bean #41

Closed
wants to merge 1 commit into from
Closed

Conversation

eleith
Copy link

@eleith eleith commented Nov 28, 2011

how it works:

  1. expose bean.customEvents out in the open
  2. allow for customEvents to have base, handler and condition fields
  3. on add/bind (on a custom event with both a base and a handler), register a listener for the base type using the custom handler and normally register a listener for the custom event
  4. custom handler should eventually lead to a fire/trigger on the custom event type

here is an example of how to extend the custom events with a basic tripleclick event

bean.customEvents.threeclicks = {
      base: 'click',
      handler: function(event)
      {
        var elem = this, clicks = this.__threeclicks__ || 0;
        clicks += 1;
        if ( clicks === 3) {
            clicks = 0;

            // set event type to "tripleclick"
            event.type = "threeclicks";

            //FIRE AWAY
            bean.fire(this, "threeclicks", event);
        }
        this.__threeclicks__ = clicks;
      }
    }

to register the event:

bean.add(element, "tripleclick", function() { alert('triple clicked!'); });

to remove the event:

bean.remove(element, "tripleclick")

it should still support namespacing, using the element/ender object as context in the handlers, and all the different ways add/remove can be called.

i've also added these examples in the tests.js framework to show (and prove) how add/remove works on these extended custom events.

added tripleclick event in tests.js to show how it works and test functionality as well
@eleith
Copy link
Author

eleith commented Nov 28, 2011

some of the previous commits on bean for adding the one method are showing up as additions in my diffs. not sure why, but those are in the current master branch, so they shouldn't be there.

@rvagg
Copy link
Collaborator

rvagg commented Jan 25, 2012

FWIW, I'm still mindful of this PR and I think that customEvents should be made public in some way but I don't think it' flexible enough as it is, I wouldn't mind seeing it able to better handle extensions such as #50 and perhaps other crazy additions. At the moment, the uses of customEvents is just to limited.

@eleith eleith closed this Nov 4, 2013
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 this pull request may close these issues.

2 participants