I am building a web app using Ember. Drag and drop ( and other animations such as automatic slide ) is a significant part of how the user will interact with the app.
I’ve already decided all animation logic will sit by itself in an Ember mixin class vis a vis this blog:
http://www.dynopia.com/index.php/en/blog/article/771/ember-js-animations-with-jquery-animate
However, I am little confused whether I should have two Views per draggable element, one to render the element and one to handle the animation logic?
In addition, after the animations is complete, the current css attributes of the element should be updated in its corresponding model. I can take care of this with a simple two way binding between view and model, ie:
/** element view **/
App.elemOneView = Ember.View.create({
name: 'element One',
cssAttr: {},
...
});
/** element controller**/
App.elemController = Ember.ArrayController.create({
content: [],
....
});
/** element model **/
App.elemOneModel = Ember.Model.create({
name: 'element one',
cssAttrBinding: 'App.elemOneView.cssAttr'
...
});
My question is that it frowned upon that model is directly bound to view, even though there is a controller layer in between them? Should I have both view and model sync to an intermediate object?
Note: currently, I plan on declaring view ( for animation logic ) and model ( to store css attributes, among other things ) for each element that appears on the page, so there will be lots of views and models. I should ask whether this is bad too?
I don’t think what you’re doing is a bad thing, remember that in javascript applications we’ve seen a rise in popularity of MVVM, notice the last two letters – ‘ViewModel’.
For that reason, I don’t think the relationship is a bad one. but surely one could say otherwise.