gmac / backbone.epoxy

Declarative data binding and computed models for Backbone
http://epoxyjs.org
MIT License
615 stars 89 forks source link

Allow JSON for code bindings #79

Closed vjpr closed 9 years ago

vjpr commented 10 years ago

On the root of a view I have three CSS classes which need separate toggling like so:-

  bindings:
    '@sk-tile':
      "classes: {
        'sk-is-saved':saved,
        'sk-is-hover':isMouseOver,
        'sk-is-loading':isLoading
      }"

I really don't like using a string of JSON-like code.

This is how it looked like in a Jade template:-

.sk-tile(role='sk-tile', data-bind="classes:{\
'sk-is-saved':saved,\
'sk-is-hover':isMouseOver,\
'sk-is-loading':isLoading }")

Both are ugly. I moved to code bindings to try make things nicer, but it didn't help so much.

Questions

  1. Should I be creating a custom binding handler to avoid squeezing too much into the data-bind tag, or is there some other way to do it?
  2. Can you allow bindings declarations to be plain JSON so the first example can be written as:
  bindings:
    '@sk-tile':
      classes:
        'sk-is-saved': 'saved'
        'sk-is-hover': 'isMouseOver'
        'sk-is-loading': 'isLoading'

I can't even use JSON.stringify with the first example because bindings (saved, isMouseOver, etc.) cannot be wrapped in quotes.

3) Is it possible to use code bindings and HTML bindings at the same time. HTML bindings make templates easier to understand, but when they get long it becomes ugly and hard to format.

Thanks!

gmac commented 10 years ago

Ha, you crazy Node guys... thanks for the pull request, I'll need to spend some time looking at it to understand it better. Looks pretty cool though!

maximkoretskiy commented 9 years ago

Have this issue any chance? :blush:

maximkoretskiy commented 9 years ago

@gmac Excuse me for my insistence. Has my PR any chance? Does it suite epoxy?