Skip to main content

Segregation of responsibilty with EmberJS router actions and store

Recently we upgraded our application to ember 1.3.0 and ember-data 1.0.0-beat4.Though it was a challenging task , since most of the api’s , conventions and names had changed so it involved in a lot of effort ( the upgrade deserves a separate blog post ).The one of the many things which has changed in the ember-data and ember 1.0 is the actions hash in the routes .

So routes can now have actions which look something like.

You can call these actions from Handelbars using

{{my-button action=showUser”}}

or  from the view code using 

this.sendAction(action’, param1, param2);

The events gets bubble up from the { Handebars } -> View -> Route 

This picture form Emberjs docs explains it in a better way. 


you can read for more details about action bubbling.

The other change which the ember-data library brings about is making store the centre of all the interactions to the server , Store basically is a repository of all you DS.Models and it is responsible for with the help of adapters to fetch , serialize ,deserialize the records.Also now store is only accessible from either the routes or the controller.By imposing that restriction ( though there are workarounds for that too) the framework basically restricts the communication the the server to routes and controller, so when you write code you know that the correct place to talk to the backend is either controller or the route and if you want anything view/dom specific you need to put that in the view class , which makes sense.

And When you mix the actions hash with the store concept it basically means that any server interaction related actions get routed to controller–> route and any view related action should lie in the specific view class.

Following this convention makes the code really clean and easy to understand and debug.


Popular posts from this blog

It was a great experience to talk to a huge audience in Mumbai and Delhi about how to start your ML journey at Google Cloud Summit ’18 India
And the dinners have started #marrigeaftereffects

Fractals and Mandelbrot Set

While mathematics is in itself quite interesting and forms the basis of any modern day research, be it computational biology, machine learning or building complex structure, it can be quite a challenge to decide where to start.  That is why i decided to explore Fractals, thinking of it as a bridge between the nature and science. It brings in some really fascinating concepts which should be good enough for me as a gateway go deeper.  Fractals are in simple language never ending patterns which keep on repeating without an end, because fractals are never ending they have an infinite perimeter but finite area.  Since the patterns repeats indefinitely but if you draw a circle around the peremeter the area will remain finite.  It is like adding 1+0.1+0.01+0.001 and never making 2 This video explains the basic concept really well  Fractals are found everywhere nature in Trees, Rivers, Branching patterns, Hurricanes and Galaxies. It tries to bring order and understanding to the patterns that w