Skip to content

wrapper for using bean outside of ender #93

@devth

Description

@devth

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.

Activity

ColemanGariety

ColemanGariety commented on Oct 18, 2013

@ColemanGariety

+1

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

rvagg

rvagg commented on Oct 19, 2013

@rvagg
Collaborator

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

mrmartineau commented on Oct 21, 2013

@mrmartineau

+1

Does anyone have a solution to this?

rvagg

rvagg commented on Oct 22, 2013

@rvagg
Collaborator

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

ryanve commented on Oct 22, 2013

@ryanve

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

ryanve commented on Oct 22, 2013

@ryanve

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

devth commented on Oct 22, 2013

@devth
Author

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mrmartineau@devth@rvagg@ryanve@ColemanGariety

        Issue actions

          wrapper for using bean outside of ender · Issue #93 · fat/bean