Is there an example of a mixin that implements a child view that are common to several view of an application. For example, I like to add a toolbar to every part of my application and to avoid to duplicate the toolbar element in my views template, I'd like to use mixins
Check out the layout property on Ember.View. You can have a shared layout template across the views.
http://docs.emberjs.com/#doc=Ember.View&src=false
You could also potentially achieve something like this using Ember.ContainerView. Your classes could add views to the childViews array.
http://docs.emberjs.com/#doc=Ember.ContainerView&src=false
Related
I want to test a Backbone.js view. All rather generic view methods (get template, get model data, render HTML) are stored in a baseview most of my views extend.
Question 1: Since the two – the view to test and the baseview - are separated, does this mean I don't need to test a view's render method because baseview's test should cover this? Or should I test every view's render method, even when this falls back to methods defined on the baseview, to test how the two play together?
Question 2: I am not sure how the baseview can be tested in isolation. If another view extends it, a template name needs to be set for the baseview to work. Should I just mock the template or treat this view like an abstract class that can't be tested in isolation?
Disclaimer: testing is an art, I don't think there's an obvious "best" answer here. But here's what I would do:
I would test everything: test the base view and all the inheriting views. After all, how do you know that your inheriting views are sharing the same render method as the base view? As your project evolves, you may find that the views you inherit from change—but you probably want to make sure that all your views always render!
I would test the base view as its own instantiated object, even if that's not how you're using it in your application. If a template needs to be set for the base view to work, set a template! I don't think you need to "mock" the template—perhaps you can just use underscore's _.template function?
Mortar view do not directly inflate it's content. Instead there is an assumption that layout with mortar view will have view content nested in it.
I feel it makes little harder to manage connection between view and it's layout.
What was the reason to put view classes to layout instead of inflating layout inside view class?
It's not a requirement, but for one thing it helps with responsive layout. Android can inflate totally different views for you based on configuration. And we like having a single convention in our code, less to think about.
Originally the #Layout annotation could also take a view class reference. We screwed up that code in a way that broke theming, liked this pattern better, and yanked the broken code since we weren't using it anyway. But there's no requirement that you map screens to views that way. That's why the Layout helper is an annotation, not built into any api. And it's why the new PathContainer delegates view construction.
I have an existing DetailController and DetailView in my app that has some pretty complicated UI / data manipulation logic (hotkeys, copy paste, duplication, autocomplete, etc) -- the view sends UI events to the controller; the controller handles the logic.
I want to convert this to an Ember component.
Does this basically mean I merge the view and controller into DetailComponent? This seems messy and wrong to me.
If not, how do I use controllers and views internally within a component? That is, I still want the complete isolation and well-defined public interface of the component, but internally within the component, I'd like to use controllers and views for organization. Is that possible?
Is it possible to use {{render}}, {{view}}, {{partial}} within the component template?
Does this basically mean I merge the view and controller into DetailComponent? This seems messy and wrong to me.
Yes that is what it means.
internally within the component, I'd like to use controllers and views for organization. Is that possible?
So component basically replaces a single view/controller pair. Beyond that a component is just an extension of Ember.View and can be organized just like any other view.
Is it possible to use {{render}}, {{view}}, {{partial}} within the component template?
Yes. Any of those helpers will work.
I've gone through the source code comments and the emberjs api but I don't really feel as though I've gotten a very clear idea at the differences between the two types of Ember.View. If anyone could delineate the situations where one might use Ember.ContainerView as opposed to Ember.CollectionView, and vice versa, I would be very grateful. Thanks!
CollectionView = the same child view over and over
This useful when you want to have a view object for every element in an array. For example, if have a list of posts and want to show a PostSummary view for each of them. A typical ember application will get this done by using the handlebars {{each}} helper, which has been implemented using CollectionView.
ContainerView = different child views
Ember.ContainerView when you need to manage an arbitrary list of child views programmatically. CollectionView extends ContainerView. As an alternative you can use handlebars helpers to insert child templates using conditionals around {{view}} helpers instead.
I'm building a desktop app in QT (although that may be irrelevant) and I'm having a hard time working through the class structure and layout. The data model is fairly simple with a root container with a number of containers of items. Consider the following representation:
Root
+ Parent
+ Child
The UI is fairly simple and follows that data model with a main window with a scrollable area (root), widgets that contain layouts (parents) of custom widgets (children) with some labels and buttons.
My trouble is with handling events that need to go up the chain and then back down like moving a child from one parent to another, moving elements, or updating child meta-data that impacts several to many other widgets.
I'm currently splitting UI widgets and model objects but having each widget and corresponding model object pointing to and from each other feels cumbersome and I think it is leading to too much maintenance.
I'd suggest following a standard MVC pattern and ensure there are no dependencies from the model to the view; in your case this would mean that while there is a widget for every model item, the model items do not reference their corresponding widgets.
While the MVC pattern has many flavours, one way to accomplish this would be to have a view class that monitors the model for any changes and updates the view accordingly (this can be accomplished by connecting a slot in the view class to a signal emitted from the model class). Any changes the user initiates through the view can then be:
1) handled directly by the model
through a simple signal/slot
connection
2) handled
by a controller class which can
direct the model to update accordingly
Either of these would then cause the model to emit an update signal which would cause your view to update. The benefit of this is the ability to change your view (or add additional views) without having to update your model.
I'd recommend reading Qt's Model/View Programming Guide to better understand how MVC works in Qt and to see if there's an existing class or interface (e.g. QAbstractItemModel) that you could use instead of baking your own.
Consider using factory pattern and command pattern. There are plenty of samples. I am just giving a hint here.
http://en.wikipedia.org/wiki/Factory_method_pattern
http://en.wikipedia.org/wiki/Command_pattern
Forgot mention about qt book: cartan-cas-dot-suffolk-dot-edu/oopdocbook/html/