gmac / backbone.epoxy

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

Compatibility with backbone-nested #28

Closed darky closed 10 years ago

darky commented 11 years ago

I want to write less code bindings, which work correctly with object-attributes n - nesting level.

Example:

"#login-input" : "value:Credentials.login"

Backbone.Stickit work correctly with this situation, but your library looks more modern.

gmac commented 11 years ago

StickIt undoubtedly works differently from Epoxy. Epoxy treats each value referenced as an accessor function, and calls the accessor to get the underlying value. What you're talking about should be fairly easy to achieve using filter functions. I'll mark this as a feature and we'll explore it as a new development item. I agree, it could be a useful addition.

aboudreault commented 11 years ago

any news about this enhancement?

ghost commented 10 years ago

+1 for adding support for this.

How can this be done with a filter? Does a filter allow you to listen for changes in a nested attribute? I think that is the main issue - setting and getting nested attributes on the model.

aboudreault commented 10 years ago

@gmac Do you know the amount of work to implement this feature? Also, you said it could be done using a filter... are you sure all epoxy feature would be supported with that hack? (two-way binding especially) Thanks!

gmac commented 10 years ago

The problem with that pattern is that its referencing a random object attribute with no formal events model, therefore nothing for Epoxy to hook update events onto. While I'm sure other binding packages support deep attribute access, they'd also have their own system of event binding and change management used to trigger UI updates. Epoxy provides a lot of automation, but does so by relying on a one-to-one mapping of model attributes to view bindings.

That said, there is no plan for Epoxy to support deep attribute binding... that's fundamentally not how this library works. However, if you do have an object stored within a model, you should be able to configure a binding filter to read and write a specific data attribute to/from it. Still, I wouldn't necessarily encourage this practice unless you fundamentally understand the manual effort required to ensure Backbone Models trigger change events for Object data. There are a lot of disadvantages to storing Objects as data within Models; I highly encourage flattening out your data so that all fields are managed directly by a model.

cime commented 10 years ago

Could you please elaborate on this please? I would like to bind to a NestedModel (https://github.com/afeld/backbone-nested) which triggers events like expected (using dot as a separator) and has set/get functions overriden so you can access nested properties using a dot. I'm only interest in one-to-one nested attributes.

gmac commented 10 years ago

RE @cime: Epoxy does not (and will not) provide native support for the features of other third-party extensions. There are just too many of them, and all with such wildly different features and use cases. While I've never used NestedModel before, scanning the docs looks like it uses it's own proprietary formatting for event names (ie: change:name.first). Because that formatting doesn't follow native Backbone conventions, Epoxy probably wouldn't pick that event up. Note that Epoxy does provide a basic method for performing deep model updates (see modifyObject).

In general, I'd advise against building Backbone apps using the plugin-soup approach. While a couple discrete plugins may really help give your application a boost on some core problems, you'll generally find more problems created than solutions offered when the roles and responsibilities of plugins begin to overlap.

darky commented 10 years ago

I think backbone.linear more convenience for this