bruth / synapse

Hooks to support data binding between virtually any object.
http://bruth.github.com/synapse/docs/
BSD 2-Clause "Simplified" License
150 stars 6 forks source link

Added feature I requested in issue #19 (renamed to avoid clash) #20

Closed dbushong closed 12 years ago

dbushong commented 12 years ago
bruth commented 12 years ago

Note sure if oneClass is the most intuitive name for this. Also do you mind adding the interface to the Zepto and Backbone.View hooks as well. The code should virtually be the same.

dbushong commented 12 years ago

I originally called it toggleClass, but that only really reflects the setting action, and is misleading, since it's only toggle in the "i'm telling you what to set it to" sense.

singleClass, maybe? Ideally it would be class, but you've claimed that. If you don't mind breaking things, I think class would be a good name, and call the existing behavior className or allClasses or even just drop it and let people use attr.class for that purpose.

Zepto: done. Backbone.View: I'll need to do some research.

bruth commented 12 years ago

I implemented it as a simple interface since it's a tad more complicated then setting or getting the className property. The value must be cleared prior to setting the value. However, I agree that your case (existential) is more common and/or more useful than interfacing with the class name directly. In fact KnockoutJS implements this existential class toggle binding as well http://knockoutjs.com/documentation/css-binding.html.

I am fine to demote the class interface to className (I may rename it or drop it altogether).

Regarding the Backbone View interface, it it literally identical to the other two: https://github.com/bruth/synapse/blob/master/src/synapse/hooks/backbone-view.coffee#L166-173

dbushong commented 12 years ago

OK, in my fork I've renamed oneClass to class, and deleted the class simple interface. As far as I can tell, just doing attr.class for the old behavior works fine. Feel free to pull if you like, doc updates are obviously needed, but as changelog notes with version numbers are included in that doc, I didn't feel comfortable making the edits.

Regarding Backbone.View, I don't understand where its @removeClass and @addClass methods are coming from; I don't see any mention of such methods in the backbone docs... It mentions you can call things using $, but I probably just don't understand what you're doing in that code. (Hopefully once I start using views I'll figure it out)

bruth commented 12 years ago

Looks good. The Backbone.View hook uses a wrapped this.el object (resulting in a jQuery/Zepto object) as the default context (this) for the interfaces. I will update it on my end no worries.