Comments (6)
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.
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.
Hi, don't worry about this. Issue still stands, but we've developed our own event framework. Many thanks.
from bean.
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.
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.
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)
- The event argument is not passed for listners attached to a JS object HOT 7
- focusin/focusout does not work in IE8
- API Documentation bug
- Ender methods conflicts with Bonzo HOT 1
- textinput event doesn't work
- Support matchesSelector and the like HOT 1
- IE8 can't fire native events on window
- Missing semi-colon at end of minified version. HOT 5
- Cannot `one()` recursively HOT 1
- copy, cut, paste events
- Events not firing in Chrome/Chromium since v42 HOT 3
- Custom events doesn't bubble HOT 1
- Allow bean.off to use selectors as bean.on does HOT 3
- KeyboardEvent.keyIdentifier deprecated
- No valid bower.json was found in any branch or tag of https://github.com/fat/bean.git HOT 2
- Typo in README
- Is it possible to listen to propertychange events from INPUT elements?
- Use bean outside of Ender but without Ender syntax HOT 2
- Extending event data with fire
- bean is not compatible with "ender compile" HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bean.