Ember 2 best practices - ember.js

I'm trying to find best practices for ember 2 related to class defining. I have a few questions...
Are we supposed to be using the ECMA6 "class", or does ember strictly rely on Ember.Object.extend?
If my class is not supposed to be an ember service does that auto make it a Utility?
Do all custom classes belong in Utility, or is it okay to create
another folder for my classes?
More specifically my class is a wrapper for server sent events.

Are we supposed to be using the ECMA6 "class", or does ember strictly
rely on Ember.Object.extend?
I find Ember.js to be a strict framework. But it does not strictly rely on Ember.Object.extend. You can use whatever you want that is valid Javascript.
However, in my experience I would not try to re-implement too much stuff myself. Also, please note not inheriting from Ember.Object will prevent you from using these methods : http://emberjs.com/api/classes/Ember.Object.html.
Do all custom classes belong in Utility, or is it okay to create
another folder for my classes
Why would you create a new folder ? Ember-cli already provides you with Services and Utilities.

Related

Zend Framework, Architecture with Doctrine

im learning Zend Framework (3) ... I installed Doctrine because i do not want to write sql queries to learn all other stuff faster....
First Question:
So know i configured a factory that loads me the doctrine entity manager to my Controllers (with DI).
So its really simple to get my entities to my controller ... e.g in my Project Controller createAction i can easy get my user entities to show them in my project form (project <--> user many-to-many).
But know im struggling, would it be better to create repository classes and inject this to my controllers instead of the doctrine entity manager, so i can filtering etc all my entities?
Second question:
When i want to filter my projects (e.g by user)
where should i do this ... in simpler slim projects i created Collection classes and injected them all of my entities and after that i called a filter method in my collection ... but the problem there is, i just loaded all entities from my database to the collection. In larger application i think there are to many entities loaded from the Database?
Third Question (Conclusion):
When i want to load data from the db to my Controllers whats best Practice here?
Load it from the entity manager ?
Load it from a Repository (the Repository load it from the entity manager)?
Load it from a Collection (the Collection loads data from the repository class and the repository loads data from the entity manager)?
I did not thought about Pagination #all... thats what i have to do next ... but there are many questions similar to my other questions.
(I know there is a zend module for this .. but have no idea how this works.. have too learn this too)
Im thankful for every hint, meaning etc.
Answers to this question are possibly all opinion based. I would say it is all about personal preference. There is no such thing as best practice here it all depends on what you will do in your controller. On top of that you can easily get a repository from your entity-manager if you need it:
$userRepository = $entityManager->getRepository('Application\Entity\User');
A more common might be to make a custom UserService (a wrapper class) around your repository/entity-manager that you populate with the custom methods you would like to use with your User resources.
I hope this helps you a bit...

Customizing the implementation for auto generated controllers using EmberCLI

When using globals we could have defined App.Controller, App.ObjectController and App.ArrayController to control what class Ember will use to generate controllers.
With EmberCLI, I see documentation for routes - using app/routes/basic.js. This works fine.
Does it also work for views? What about controllers? How would I implement the 'basic' for each kind of controller?
Yes, this works for just about any object Ember would generate, including controllers. If you look here you can see that Ember looks for 3 different types of controllers to generate: basic, object, and array. You can override these defaults by creating the following files:
app/controllers/basic.js
app/controllers/object.js
app/controllers/array.js
Ember is moving away from views and controllers in favor of components. (See the Routable Components section of The Road to Ember 2.0.) To that end, I don't believe Ember-CLI provides the ability to provide a basic implementation of each of these controllers in order to discourage their use. (At least I could not find anything from searching the code base.)

Why/when do you need to reopen classes in ember.js?

There are times when you use App.Model.reopenClass() on a model (link) and the Ember guides talk about App.Router.reopen() (link). From the Ember guides:
reopen is used to add instance methods and properties that are shared
across all instances of a class. It does not add methods and
properties to a particular instance of a class as in vanilla
JavaScript (without using prototype).
But when you need to create class methods or add properties to the
class itself you can use reopenClass.
When is this necessary/advantageous? Is it not possible to just add everything right up front?
reopenClass is analogous to adding methods to the prototype instead of adding methods on each and every instance of your classes. You can think of them as static variables/methods, instead of instance variables/methods.
It's a major performance gain, and possibly makes more sense for the problem you are solving.
One example where you would reopen a class is that when you want to add properties to an existing default generated class. For example: many instances of ember applications don't extend router class. They just use default router class. But what if you want to add some properties to router class that you want to use somewhere else. reopen is pretty usefull there. This is one use case I can think of.
Also, In the case of Router extending the class is difficult as most of the code within ember just uses router class. Even if you extend, some callbacks/closures will still refer to the older router class.

Where can I find documentation on Ember's {{control}}?

I don't see a listing in the Ember API. Where can I find which parameters for this template method? Can I use it, given that it's an unfinished feature?
It is not a good idea to use {{control}} yet as it is still being developed and is very likely to change behaviour. Basically it will be like a sandboxed {{render}} which won't inherit any context. It is mentioned on this page of the emberjs guide:
{{control}} works like render, except it uses a new controller instance for every call, instead of reusing the singleton controller.
This helper is currently under heavy development, and will likely change soon.

MVC pattern in Qt4 - how to organize code besides using Interview

i was recently suggested to use MVC pattern to organize my Qt4 application.
I'm a little puzzled :).
How do I implement:
1. model
2. view
3. controller
In HTTP based apps its quite straigtforward. But here I'm not sure what is a view and what is a controller ?
Lets asume that I'm not using Interview right now.
Thanks for help
you can look at this like this:
Controller is the window/form that You created. Member functions in this class should handle all user input and call apropriate member functions in your model.
Model is your class that handles data and implements other logic.
Views are qt widgets used to design your forms/windows
(You could also treat *.ui files as views and Classes that are bound with ui files as controllers)
Hope this helps.