highland icon indicating copy to clipboard operation
highland copied to clipboard

Without jQuery

Open davidchase opened this issue 10 years ago • 12 comments

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

davidchase avatar Oct 20 '14 17:10 davidchase

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.

greelgorke avatar Oct 21 '14 09:10 greelgorke

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.

davidchase avatar Oct 22 '14 03:10 davidchase

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?

greelgorke avatar Oct 22 '14 06:10 greelgorke

Sure, do we need to support older browsers? specifically attachEvent (ie8)

davidchase avatar Oct 23 '14 01:10 davidchase

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.

greelgorke avatar Oct 23 '14 06:10 greelgorke

Right so it seems to add addEventListener piece is straightforward its just a check, but just making sure we dont need attachEvent check

davidchase avatar Oct 23 '14 15:10 davidchase

You could potentially use dom-event-stream and pipe that into Highland

RangerMauve avatar Nov 12 '14 17:11 RangerMauve

@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

davidchase avatar Nov 12 '14 17:11 davidchase

There's also ever, which wraps elements with an EventEmitter.

apaleslimghost avatar Nov 22 '14 09:11 apaleslimghost

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

marcog83 avatar Mar 03 '15 11:03 marcog83

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?

dwsmorris avatar May 11 '16 13:05 dwsmorris

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.

vqvu avatar May 11 '16 21:05 vqvu