Thanks for the feedback.

I will be happy to release them once I've kicked the tires. Trying to
make them really reusable begets another question with respect to
event delegation.

I have a series of very specific classes (Contact, Message,
Attachment, etc) that represent business objects and communicate via
web services. Typically these classes have a target DOM element they
use to display their content.

I then have generic behavior to field things like pagination of a list
of Contacts (or Messages, or Attachments, etc.).

When a pagination event fires, I essentially want my Contact class to
listen for it.

Option 1: create an custom event on Element

Create a custom event on Element (Element.paginate, based on the click
handler), and have the Contact's DOM element listen for the paginate
event.

However, that strikes me as "resource intensive". I may well
misunderstand, but the Element.paginate's condition function would be
evaluated on every mouse click on every element. Given the complexity
of some of my pages, I'm worried about performance.

I had hoped something like this would work instead:

http://jsfiddle.net/kBGLQ/

Option 2:

In my Paginate behavior, I call a global function to find and return
the containing class (Contact), and fire a custom event on the
class.

This works, and strikes me a reasonably efficient. However, it ties my
Paginate behavior to the existence of very specific classes.

See http://jsfiddle.net/wB3n7/1/

Option 3:

I suspect I'm missing a more generic, equally efficient option.

Thanks as always,

Eric

On Sep 14, 2:32 pm, Aaron Newton <aa...@iminta.com> wrote:
> Hi Eric,
>
> Thus far I haven't worried about namespacing filters. Remember that you
> control which ones are loaded and which ones are in effect. Behavior
> instances can have local filters that override globals, etc.
>
> If, however, you want to be safe, you could use any of the examples below. I
> don't know if I have a preference.
>
> Are you going to release these behaviors? I'd love to see more people
> publishing them...
>
>
>
>
>
>
>
> On Wed, Sep 14, 2011 at 10:09 AM, Eric Patrick <epatr...@quandis.com> wrote:
> > Thanks for the Behavior / BehaviorAPI Aaron; it's great to work with!
>
> > I am developing a bunch of behaviors centered on dealing with AJAX-
> > loaded data grids:
>
> > - Paginate: handles creation of DOM elements for a pagination row,
> > raising an event when a page or display size is changed
> > - OrderBy: handles making column headers sortable
> > - Filter: handles modification of JSON from a form to re-submit via
> > Request.HTML or Request.JSON
>
> > It occurs to me others may do something similar. Any thoughts or
> > advice on "name spacing" behaviors?
>
> > <div data-behaviors="Paginate, Filter"/>
>
> > vs. my name space (mns)
>
> > <div data-behaviors="mns.Paginate, mns.Filter"/>
>
> > vs.
>
> > <div data-behaviors="mns-Paginate, mns-Filter"/>
>
> > vs.
>
> > <div data-behaviors="mnsPaginate, mnsFilter"/>
>
> > Thanks in advance,
>
> > Eric

Reply via email to