ember.js – the right choice for the Open Event Front-end
With the development of the API server for the Open Event project we needed to decide which framework to choose for the new Open Event front-end. With the plethora of javascript frameworks available, it got really difficult to decide, which one is actually the right choice. Every month a new framework arrives, and the existing ones keep actively updating themselves often. We decided to go with Ember.js. This article covers the emberJS framework and highlights its advantages over others and demonstrates its usefulness.
EmberJS is an open-source JavaScript application front end framework for creating web applications, and uses Model-View-Controller (MVC) approach. The framework provides universal data binding. It’s focus lies on scalability.
Why is Ember JS great?
Convention over configuration – It does all the heavy lifting.
Ember JS mandates best practices, enforces naming conventions and generates the boilerplate code for the various components and routes itself. This has advantages other than uniformity. It is easier for other developers to join the project and start working right away, instead of spending hours on existing codebase to understand it, as the core structure of all ember apps is similar. To get an ember app started with the basic route, user doesn’t has to do much, ember does all the heavy lifting.
ember new my-app ember server
After installing this is all it takes to create your app.
Ember CLI
Similar to Ruby on Rails, ember has a powerful CLI. It can be used to generate boiler plate codes for components, routes, tests and much more. Testing is possible via the CLI as well.
ember generate component my-component ember generate route my-route ember test
These are some of the examples which show how easy it is to manage the code via the ember CLI.
Tests.Tests.Tests.
Ember JS makes it incredibly easy to use test-first approach. Integration tests, acceptance tests, and unit tests are in built into the framework. And can be generated from the CLI itself, the documentation on them is well written and it’s really easy to customise them.
ember generate acceptance-test my-test
This is all it takes to set up the entire boiler plate for the test, which you can customise
Excellent documentation and guides
Ember JS has one of the best possible documentations available for a framework. The guides are a breeze to follow. It is highly recommended that, if starting out on ember, make the demo app from the official ember Guides. That should be enough to get familiar with ember.
Ember Guides is all you need to get started.
Ember Data
It sports one of the best implemented API data fetching capabilities. Fetching and using data in your app is a breeze. Ember comes with an inbuilt data management library Ember Data.
To generate a data model via ember CLI , all you have to do is
ember generate model my-model
Where is it being used?
Ember has a huge community and is being used all around. This article focuses on it’s salient features via the example of Open Event Orga Server project of FOSSASIA. The organizer server is primarily based on FLASK with jinja2 being used for rendering templates. At the small scale, it was efficient to have both the front end and backend of the server together, but as it grew larger in size with more refined features it became tough to keep track of all the minor edits and customizations of the front end and the code started to become complex in nature. And that gave birth to the new project Open Event Front End which is based on ember JS which will be covered in the next week.
With the orga server being converted into a fully functional API, the back end and the front end will be decoupled thereby making the code much cleaner and easy to understand for the other developers that may wish to contribute in the future. Also, since the new front end is being designed with ember JS, it’s UI will have a lot of enhanced features and enforcing uniformity across the design would be much easier with the help of components in ember. For instance, instead of making multiple copies of the same code, components are used to avoid repetition and ensure uniformity (change in one place will reflect everywhere)
<.div class="{{if isWide 'event wide ui grid row'}}"> {{#if isWide}} {{#unless device.isMobile}} <.div class="ui card three wide computer six wide tablet column"> <.a class="image" href="{{href-to 'public' event.identifier}}"> {{widgets/safe-image src=(if event.large event.large event.placeholderUrl)}} <./a> <./div> {{/unless}} {{/if}} <.div class="ui card {{unless isWide 'event fluid' 'thirteen wide computer ten wide tablet sixteen wide mobile column'}}"> {{#unless isWide}} <.a class="image" href="{{href-to 'public' event.identifier}}"> {{widgets/safe-image src=(if event.large event.large event.placeholderUrl)}} <./a> {{/unless}} <.div class="main content"> <.a class="header" href="{{href-to 'public' event.identifier}}"> <.span>{{event.name}}<./span> <./a> <.div class="meta"> <.span class="date"> {{moment-format event.startTime 'ddd, MMM DD HH:mm A'}} <./span> <./div> <.div class="description"> {{event.shortLocationName}} <./div> <./div> <.div class="extra content small text"> <.span class="right floated"> <.i role="button" class="share alternate link icon" {{action shareEvent event}}><./i> <./span> <.span> {{#if isYield}} {{yield}} {{else}} {{#each tags as |tag|}} <.a>{{tag}}<./a> {{/each}} {{/if}} <./span> <./div> <./div> <./div>
This is a perfect example of the power of components in ember, this is a component for event information display in a card format which in addition to being rendered differently for various screen sizes can act differently based on passed parameters, thereby reducing the redundancy of writing separate components for the same.
Ember is a step forward towards the future of the web. With the help of Babel.js it is possible to write ES6/2015 syntax and not worry about it’s compatibility with the browsers. It will take care of it.
This is perfectly valid and will be compatible with majority of the supported browsers.
actions: { submit() { this.onValid(()=> { }); } }
Some references used for the blog article:
- https://www.codeschool.com/blog/2015/10/26/7-reasons-to-use-ember-js/
- https://www.quora.com/What-are-the-advantages-of-using-Ember-js
- Official Ember Guides: https://guides.emberjs.com
This page/product/etc is unaffiliated with the Ember project. Ember is a trademark of Tilde Inc
You must be logged in to post a comment.