highland
highland copied to clipboard
Without jQuery
So I was wondering if theres a way to use highland without the need of a jquery wrapped selector.
Ex: A very trivial concept I would like to achieve this which logs each click to the console
var stream _('click', document.body);
stream.each(_.log);
however I have to do
var stream _('click', $('body'));
stream.each(_.log);
Essentially I should be able to do
document.querySelector('.selectorName')
vs $('.selectorName')
Any thoughts?
Thank you -David
the problem is not the selector, but the expected api. highland expects an EventEmitter with .on() method. you could make it work without jQuery by shiming this method:
var elem = document.querySelector('.foo')
elem.on = elem.on || function(event, fn){ this.addEventListener(event, fn)};
_('click', elem)
you could take the shim from jquery source or use some lib from http://microjs.com/# or whatever.
Hmm interesting coming from other libraries such as bacon, kefir, most.. they all seem to offer a simpler api without any shimming, im curious to understand the methodology behind this approach.
highland has also a simple api. it's just so, that a specific event source api is expected. i guess the stream constructor could check for presence of addEventListener itself. it's just not implemented that way yet, but it could. wanna go for PR?
Sure, do we need to support older browsers? specifically attachEvent
(ie8)
i don’t know, @caolan should. but since highland doesn’t even support addEventListener yet… :)
Am 23.10.2014 um 03:44 schrieb David Chase [email protected]:
Sure, do we need to support older browsers? specifically attachEvent (ie8)
— Reply to this email directly or view it on GitHub.
Right so it seems to add addEventListener
piece is straightforward its just a check, but just making sure we dont need attachEvent
check
You could potentially use dom-event-stream and pipe that into Highland
@RangerMauve using addEventListener
rather than jquery is a quick addition, i like dom-event-stream
but don't want to use a library when something can be fixed
There's also ever, which wraps elements with an EventEmitter.
I had a look at this library because it seems one of the dryest, cleanest i've seen since now, but I stuck after "addEventListener"... and shimming something built in sounds weird. I hope in some news. 'cause i like this great library
I was looking to use highland with Google's polymer.js which recommends avoiding jQuery due to potential problems with shadow dom implementations/polyfills. An api that doesn't support elements returned by document.querySelector is a dealbreaker. Any update for adding support for this?
This is a very old issue, so my guess is that no one is working on it at the moment. It's a fairly easy change, and a PR would be welcome if you want to do it yourself. I'm a bit busy at the moment, so I don't have the time to do it myself. I could probably do it in a few weeks, if no one else has volunteered.