Skip to main content

Introducing ember-data

Model objects, defined by the ember-data library abstracts away the complexities
involved with handling the communication with the server, serializing, as well
as de-serializing of the response received from the server. In order to define your
ember-data model object, you just need to extend the DS.Model object present in
ember-data module as follows:
Models form the core of any MVC design pattern as they describe the core business
domain at hand. In Ember.js, every route has an associated model that describes the
business domain that the route needs to work on. Almost all of the examples that we
have seen so far operate on the static data that is returned from the model property
of the routes. But most of the times the data that needs to be operated upon is not
static and is fetched from a remote server.

Traditionally we have used jQuery or plain JavaScript to fetch the data from the
server, using AJAX calls and then using those returned JSON objects as models
in our application. This approach works well for applications that are simpler in
nature, but very quickly get difficult to maintain when working on domains that are
complex in nature, especially the ones that have relationships among them. We need
to make sure that the correct relationship is linked and updated in our application.

The ember-data library tries to solve the problems highlighted earlier that are
encountered in building single page web applications, by providing a standard way
of accessing, finding, modifying, and saving the model objects of your application.
By using the ember-data library, you can easily simplify your code that handles
the communication with the backend server, by letting ember-data handle most of
the complexity for you. This lets you focus more on solving the business problem at
hand. The library also brings in a lot of optimizations to your code that improve the
overall performance of your application.

Ember Data is designed to be agnostic to the underlying storage technique, and hence
it works equally well will HTTP based JSON API, as well as streaming WebSockets.

The ember-data library is actively being developed and improved, and is under the
beta quality. The API is highly stabilized and there are a lot of companies who have
been using ember-data in production for quite some time now.

The current beta of ember-data is already included with Ember CLI and can be
checked from the bower.json file, present in the project’s root directory.

Defining ember-data models

Model objects, defined by the ember-data library abstracts away the complexities
involved with handling the communication with the server, serializing, as well
as de-serializing of the response received from the server. In order to define your
ember-data model object, you just need to extend the DS.Model object present in
ember-data module as follows:


As you can see in the preceding code, we created a new file in app/models directory
with the name book.js. The book object has a few differences from the objects we
have seen so far.

The book object extends the DS.Model object, instead of Ember.Object. The
DS.Model class inherits itself from the Ember.Object class; as a result, you can use
all the features provided by Ember.Object, including computed properties and
observers. The DS.Model class also adds in other additional capabilities, including
serializing, deserializing a record, and saving it back to the server.

Comments

Popular posts from this blog

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 understandin...
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

Las Vegas

January has been pretty exciting for me since last three years, It marks my annual ritual trip to Las Vegas, this is my third trip this year. Almost all of my trips have been because of work. Since Las Vegas has some of the biggest hotels[1] in the world it has become a natural choice for some of the biggest American companies to host their internal and external conferences. As an example, CES hosts some 200,000 people every year [2]. This year I started my 30-hour flight journey, yes you heard it right I had a 9-hour layover at the London airport. Though it was far from ideal it was not that bad. If you can arrange priority pass [3] card from your credit card company or pay for it. Then you can use the lounge, showers and much more for free. I manage to steal the below picture from a hoarding at the airport.  Then after much rest and time pass at the airport terminal, I boarded my next flight to Las Vegas. When I landed McCarran International Airport, the first surprise for me was the...