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

wrapper for using bean outside of ender #93

Open
devth opened this issue Aug 1, 2013 · 7 comments
Open

wrapper for using bean outside of ender #93

devth opened this issue Aug 1, 2013 · 7 comments

Comments

@devth
Copy link

devth commented Aug 1, 2013

I want to use the familiar syntax for querying, dom manip, events, etc:

$('.foo').on('click', function() { alert('bar') });

but without the ender glue that typically allows it. I've got bonzo and qwery working together with a snippet I found:

function $(selector) {
  return bonzo(qwery(selector));
}

How do I then glue bean into this mix? Just wrapping it doesn't work.

@ColemanGariety
Copy link

+1

.setSelectorEngine feels a bit jacky to use outside of an Ender bridge.

@rvagg
Copy link
Collaborator

rvagg commented Oct 19, 2013

Depends on your use-case, this one made @JacksonGariety happy because he's using Browserify: https://github.com/rvagg/nodei.co/blob/master/browser-lib/ender.js

But it still uses ender-js to glue them together. @devth are you trying to avoid using ender-js here in particular? It does the magic that builds $ nicely but it's not exactly super-complex so you could write your own replacement if need be.

@mrmartineau
Copy link

+1

Does anyone have a solution to this?

@rvagg
Copy link
Collaborator

rvagg commented Oct 22, 2013

You could try bonzo.aug(bean) because Bonzo has some basic augmentation functionality built in for this case, see this method. The methods on the object you feed it will be added to Bonzo.prototype and should be usable from wherever Bonzo is being used.

Depends on precisely how you're piecing these things together and if you're using some other tool to bundle the components together.

@ryanve
Copy link

ryanve commented Oct 22, 2013

A standalone solution I often use in my own modules is to create the .fn methods in the main file (not in the ender bridge) such that they are callable standalone like bean.fn.on.call(els, type, fn). See vibe for example. Having the effins exposed lets them augment any existing wrapper.

@ryanve
Copy link

ryanve commented Oct 22, 2013

Maybe bean deserves its own simple wrapper:

function Bean(o) {
    [].push.apply(this, null == o ? [] : o.nodeType || o.window == o ? [o] : o);
}
function bean(o) {
    return new Bean(o);
}
bean.fn = bean.prototype = Bean.prototype;

@devth
Copy link
Author

devth commented Oct 22, 2013

@rvagg yeah, I just wanted to pick a couple lightweight modules according to my needs without relying on the package management side of Ender, which felt pretty heavy for a little prototype I was working on. Didn't realize ender-js was the glue, maybe that's what I'm missing.

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

No branches or pull requests

5 participants