leonidas / transparency

Transparency is a semantic template engine for the browser. It maps JSON objects to DOM elements by id, class and data-bind attributes.
http://leonidas.github.com/transparency/
MIT License
969 stars 112 forks source link

Appending content #22

Closed pyykkis closed 12 years ago

pyykkis commented 12 years ago

Currently, Transparency replaces existing content. Sometimes, e.g., when adding a new class for an element, appending would be handy.

Current functionality

directive =
  'foo@class': (e) -> $(e).attr('class') + " " + "newclass"

Proposed functionality

directive =
  'foo@class+':  " newclass"

I'm not sure if this is common enough scenario justifying the implementation, so let's have discussion first.

If the feature is worth implementing, in what extent we should support it? Only for attributes, or directives in general, or for both data and directives?

pyykkis commented 12 years ago

Another possibility to tackle both this issue and https://github.com/leonidas/transparency/issues/21 would be MongoDB convention, e.g.,

directive =
  foo: () -> push: {class: " new-class"}

http://www.mongodb.org/display/DOCS/Updating#Updating-ModifierOperations

miohtama commented 12 years ago

jQuery have funtion addClass() which should be used with conjunction of $(elem)

  $(elem).addClass("foobar")

Also native addClass() implementations exist / are coming, I believe.

pyykkis commented 12 years ago

I'd rather write directives as pure functions without side-effects. Anyway, I'm happy to drop the issue until someone else asks for it. Closing.