Giter Club home page Giter Club logo

Comments (6)

fat avatar fat commented on June 4, 2024

Currently an event is not passed to elements -- because it's less of an event than a callback. However, with the next major release of bean, you'll be passed an even obj.

With the firing of custom events, you don't need to put your args in an array.

just do:

 bean.fire(obj, 'doSomething', 'val1', 'val2');

from bean.

codecomputerlove avatar codecomputerlove commented on June 4, 2024

Hi just picking this back up again. When I try your above suggestion I get the following error:

second argument to Function.prototype.apply must be an array
bean.js
Line 193

Any ideas? I'm still looking into this myself, but even when I do pass any array, I only the first element of the array is passed as an argument to the event handler function.

Many thanks in advance

from bean.

codecomputerlove avatar codecomputerlove commented on June 4, 2024

Hi, don't worry about this. Issue still stands, but we've developed our own event framework. Many thanks.

from bean.

jmalloc avatar jmalloc commented on June 4, 2024

Hi guys, I was experiencing the same problem as above (ie, second argument to Function.prototype.apply must be an array). It seems you do need to pass your arguments to custom events in an array (which probably better anyway) but I noticed only the first argument was making it back to the handler.

To fix the problem I've changed the definition of customHandler as follows in our local copy from:

  customHandler = function (element, fn, type, condition, args) {
    return function (event) {
      if (condition ? condition.call(this, event) : W3C_MODEL ? true : event && event.propertyName == '_on' + type || !event) {
        fn.apply(element, [event].concat(args));
      }
    };
  },

to:

  customHandler = function (element, fn, type, condition, args) {
    return function (event) {
      if (condition ? condition.call(this, event) : W3C_MODEL ? true : event && event.propertyName == '_on' + type || !event) {
        fn.apply(element, Array.prototype.slice.call(arguments).concat(args));
      }
    };
  },

I'm not sure if this is the best solution, and neither am I sure whether or not it affects anything else - hence no pull request - but hopefully this is useful :)

from bean.

valueof avatar valueof commented on June 4, 2024

I went the other way and just pass an array of a single element that acts as an event object.

bean.fire(myObject, 'myEvent', [ { keyOne: 'valueOne', keyTwo: 'valueTwo' } ]);

And in the event handler:

function handler (ev) {
  console.log(ev.keyOne); // valueOne
}

That said, I think there is a bug with my approach. I have opened a separate ticket about it: #18.

from bean.

fat avatar fat commented on June 4, 2024

this is working now with this commit: 8b8851a

i'll be republishing to npm this evening. thanks for all your help!

from bean.

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.