Oh, one other thing, when BehaviorAPI reads from inline properties, it
converts dashes to camelCase, like so:
data-foo-some-thing="bar"
myAPI.get('someThing') //bar
It also supports namespacing the "foo" part, so if you have a prefix like
"Foo.Bar" you would reference it in the html as foo-bar. Example:
<div id="foobar" data-foo-bar-some-thing="bar">
new BehaviorAPI($('foobar'), 'Foo.Bar').get('someThing') //bar
I think I have that right; I'm going off memory here. It's in the docs.
On Tue, Nov 22, 2011 at 3:42 PM, Aaron Newton <[email protected]> wrote:
> It does but only in kind of a half-measure for speed purposes. Iterating
> over all the properties of an element looking for ones that start with
> data-* is expensive. Elements have a lot of properties!
>
> Instead, BehaviorAPI requires that you ask for what you want, but you can
> do that by just listing their names:
>
> myAPI.get('foo', 'bar', 'baz);
>
> This is preferable to iterating over all the attributes anyway.
>
> Further, some of these may need to be cast into types - arrays or numbers
> for example. There you can do:
>
> myAPI.getAs({
> foo: Number,
> bar: String,
> baz: Array
> });
>
> The thing you get here by doing this is some stability with the thing that
> you throw these values to because you aren't allowing the user to just
> throw *anything* through that pipe. By describing what options you support,
> you don't end up with messy situations where you don't know what users are
> passing in, making it impossible to provide forward and backward
> compatibility.
>
> The BehaviorAPI stores these values once they are parsed, so it's stupid
> fast if you make the reference numerous times. It also has mechanisms for
> passing along additional properties and methods
> (myAPI.doSomethingWithSomeElement(someElement)). Etc.
>
> I seriously thought this stuff out; it's some of the best code I've ever
> written. Use it or don't, but I'll bet that you'll find it suits your
> needs, even if it does require you to be a little overly prescriptive and
> verbose when you use it. The trade off there is speed and stability.
>
>
> On Tue, Nov 22, 2011 at 3:08 PM, Jonathan Bomgardner <[email protected]>wrote:
>
>> Aaron,
>>
>> I thought I had looked at this but maybe I missed it... can
>> behaviourAPI create an object from the data-* attributes? The reason I need
>> this is that the JxLib library is so large that it would be pretty hard to
>> feed the API with specific attributes to look for for each Object... what I
>> need is something that will take the DOM element and push all of the
>> options into an object. JxLib already (just about) has the ability to
>> render it's objects from a single javascript object that contains the
>> options... this is just the next step from that.
>>
>> Thanks,
>> Jon
>>
>
>