Sunday, 6 September 2015

Continuous deployment of Node, Express application on Azure using Github

Normally we deploy the projects on Azure using Visual Studio IDE, but Azure is not just limited to all Microsoft technologies specially when the majority of developers are on open source or moving to open source.

In this post I am going to provide you a very step by step process to deploy your Nodejs project having a source control on Github to Microsoft Azure cloud.

The basic things which you need to setup before you can start your deployment are as follows:

  1. Nodejs : You can download Nojejs from here  https://nodejs.org/en/
  2. Github repository account: First you need to setup a new account (if you don’t already have) in https://github.com/
  3. Github for Desktop: I am using Github for windows to Commit and Push my changes to Github repository, but you can use other tools as well to push your files to Github. You can download from here: https://desktop.github.com/.
  4. Microsoft Azure: If you don’t have Azure subscription you can signup for 1 month free trial. This will give you $200 credit to spend on all the Azure Services: You can visit this link to Signup for a month free service: https://azure.microsoft.com/en-us/pricing/free-trial/

You don’t need to have very advanced knowledge of Node, Github or Microsoft Azure to follow the steps I have covered here but I am assuming that you have at least basic knowledge of Nodejs, Github and Azure. Now Once you have all the required setup installed on your machine, lets get started with the basic steps which is required to deploy your Nodejs sample application on Azure using Github.

Step 1 Setup your environment: Create a working folder which you want to use for your application, and start Git Bash on your working directory. Alternately you can use windows command prompt. For this example I have created a folder in my local C drive as C:/Source/NodeOnAzureSample

If you already have your application which you want to deploy on Azure you can use that. For this example I am using express-generator to quickly create a sample application using Node, Express and Jade, I am using this just to save time and keep our focus on the actual topic.

Step 2 (Optional) Setup my demo project: This is a optional step if you already have your application ready. Here I am using the command “npm install express-generator -g” to generate my sample application template with a basic welcome page. You can find more detail of express-generator @ http://expressjs.com/starter/generator.html

This will create the sample files inside node modules globally in your C:/Users/YourUserName/AppData/Roaming/npm/express folder, or you can create the files in your local application folder by removing the –g from the command.

Now run “express NodeOnAzureSample” command, this is going to create all the required folders and files which you are going to start your development.

image

Step 3 (Optional) Restore the dependencies: Run “npm install”, this will restore all the dependencies like jade, express, etc which your application has dependencies.

Step 4 Test the application on localhost: After executing Step 1 to 3, we have our application ready to run on local machine, lets go ahead and test our sample application by switching to the application directory and run the command “npm start” in Git Bash (you can use powershell or windows command prompt) and enter “localhost:3000” in your browser. This should give you the following screen and your sample application is ready for hosting. Now in Next Steps I am going to configure my application with Github repository.

image

For simplicity sake and stick to the topic, I am not going to explain the folder structure, code, and other granular details of this sample application.

Step 5: Setup Github Repository @ Guthub.com Go to https://github.com/new and create a new repository, once you select all your desired options as shown in the image below. Click on the button “Create Repository”

image

You will be provided step by step information on the new repository which you have created,

image

Copy the URL, in your clipboard or notepad, you are going to need this URL during commit and push of your local application files to github repository at github.com online.

For this example my repository URL is : https://github.com/bmdayal/NodeOnAzureSample.git

Step 6: Setup Github Repository on you Desktop: Open Git Gui and Select Create new Repository from the menu which will ask you to locate your application directory, select the folder which you want to deploy to Azure. In my case I have mapped my “NodeOnAzureSample” application to Git repository.

Once you select create, Git GUI will list all the files which are either new or modified. Next step is you need to Stage Changed files, Commit and Sign Off, to perform these first you need to setup a new repository in https://github.com which I have already explained in Step 5 above.

image

Select “Stage changed” –> Sign Off –> Provide initial commit message –>Commit—>and Push.

Selecting Push is going to final commit your files to online github repository, to do this you will need the URL of your GitHub repository at github.com, and this will also prompt you to authenticate yourself.

image

Once your files successfully pushed to online repository, you will get a confirmation message as below.

image

Now that your files are ready for deployment, lets switch to Azure to configure continuous deployment.

Step  7 Configure Azure website: to do this you need to go to https://manage.windowsazure.com dashboard. Select Web Apps—>And select New from the footer menu.

image

This is going to provide you a wizard to create a new WEB APPS. For this example I am going to use Quick Create option to create my web application and named this as NodeOnAzureSample. If the name is available you will get a green check mark next to the name. This will provide you with a URL as https://nodeonazuresample.azurewebsites.net. Once you are happy with the name click on “Create Web App” button.

image

You can see the site is now listed in the WEB APP list and showing as Running, now click on the URL to test your web site @ http://nodeonazuresample.azurewebsites.net/.

This is going to provide you a welcome page of Azure Web site. In my nest steps I am going to replace the welcome page with actual application which we have created and pushed in Github.

image

Step 8 Configure deployment using Github: Select the Web App listed in the image above and Select Dashboard from the top menu.

image

From the dashboard, select Set up deployment from source control from right navigation menu.

image

You will be provided with a list of options, where you need to select GitHub, and select Next

image

You will need to authenticate yourself to GitHub where you have created your repository that needs to be deployed on Azure.

image

On successful authorization, you will be provided with the list of your applications which you have deployed on Github, for this example I have selected my “NodeOnAzureSample” application.

image

Select Done when you have made your selection, and this is pretty much what we need to do to link my Github repository to Azure website.

Deployment Stage 1image

Deployment Stage 2: Notice you got a new menu called “Deployments” after Dashboard. Be patience, this might take few seconds to minutes depending upon the size of your application.image

Deployment Stage 3: Deployment completed, you can see the initial comments which I had provided during my Commit to Githubimage

Step 9 Testing your deployment on Azure website: Now that your application is deployed on Azure the next step is to test my application, yes no further configuration is required. Azure configures everything for you. Lets go to the WEB APP Dashboard and hit on the URL : nodeonazuresample.azurewebsites.net

image

Yes our application is ready and running on Azure Smile

Step 10 Continuous deployment: To verify Continuous deployment. Go to your index.js, in NodeOnAzureSample/routes folder and change the text from “Express” to “Node, Express, Azure and Github”

image

Save the file, go to your Github Desktop—> Rescan—>Commit and Push the file with comment “Changed the welcome text from Express to Node, Express, Azure and Github”

image

Once you complete these steps, go back to your Azure dashboard. And probably by the time you switch back to your Azure your changes might have already been deployed to your website. Lets go ahead and verify.

image

And here we go, on my azure dashboard above I can see the latest changes are already deployed with the comment I have provided in my github commit.

Lets test this change in my browser by refreshing the page, and yes my changes are reflected below.

image

This is just a simple example of how the things are simplified in Microsoft Azure. This post will give a head start to integrate Node, Express, Github and Azure.

You can use any of your favorite open source like Angular, Knockout, Backbone, Jade, etc with your favorite source control like Visual Studio, GitHuib, Dropbox, Codeplex, etc and integrate with Microsoft Azure and above all you don’t need to be a Ninja on this technologies.

Happy Coding and Keep exploring Smile

Share:

Tuesday, 1 September 2015

Angular 2 Survey Results

Angular Devs taking survey

This is a guest post from Jeff Whelpley and Patrick Stapleton. Though they're not full time Angular team members, they are incredible contributors to the Angular community. I think this post is a great summary of what users want to see from us. Enjoy!

- Brad Green


A couple weeks ago, Patrick and I sent out a survey to Angular developers with questions about how they plan on using Angular 2. We got over 2,100 responses and a lot of additional feedback. All of the results are posted below with some context and analysis.

Disclaimer

Originally we were only thinking about getting feedback from the small group of developers that are already spending most of their day working on Angular 2. This quickly changed, however, as more and more people started submitting responses. Angular 2 is only in alpha and you cannot build production apps with it yet. It is probably safe to assume that many people who responded are just starting to learn about Angular 2. Therefore, we now view the results in terms of what developers think they will do in the future rather than what they are actually doing right now.

With that disclaimer out of the way, let’s get to the results…


Transpilers

Which approach do you prefer when hacking Angular 2? (choose one)

Transpilers used by Angular 2 devs
TypeScript 45.0% 950
Babel 33.2% 700
Not sure 11.3% 238
ES5 9.0% 190
Other 1.6% 33

Analysis

For the first 1,000 results or so, TypeScript was in a dead heat with Babel but then TypeScript started to pull away. This is not surprising given that the Angular core team has a preference for TypeScript. We had a great discussion about TypeScript vs Babel on Angular Air and we concluded that much of the decision is going to come down to the personal preferences of the team.

Although sticking with ES5 is not a good long term strategy, a number of developers have used it to help with the transition from Angular 1 to Angular 2. If you are thinking about sticking with ES5 just because you don’t like transpilers, however, you should give them another shot. Transpilers in general have vastly improved over the past year.

"Other" Transpilers

A couple people wrote in that they use both TypeScript and Babel which may seem a little odd at first, but both teams have discussed ways that they can potentially work together in the future.

There were about a half dozen responses for Dart and 1 for Closure Compiler.

Also, there were 7 responses for CoffeeScript, presumably from the Ruby/Python crowd.

Template Syntax

Which template binding syntax will you use? (choose one)

Template syntax used by Angular 2 devs
bind-prop="val" 56.7% 1192
[prop]="val" 43.3% 912

Analysis

This was initially one of the most surprising results, but the more we thought about it, the more it made a lot of sense. Although the Angular core team prefers the second option (i.e. [prop]=val which is the canonical syntax), most developers seem have the same initial reaction. It feels weird and unfamiliar (is it even valid html?). The first option (i.e. bind-prop="val") looks and feels like Angular 1.x template code.

Despite this, it may be interesting to note that all developers we know who hack on Angular 2 every day use the canonical syntax in most cases. It was weird at first, but we all got used to it. Remember that when Angular 1 first came out, everyone was freaking out about using non-standard attributes that start with the prefix ng-. Initially many Angular 1 developers thought about either prefixing attributes with data- (ex. data-ng-bind) or using the xmlns notation of ng:*. Those ideas quickly faded away, however, once people realized they didn’t provide any real benefits.

"Other"

I thought this was sort of interesting:

Some of this particular concern will go away once text editors properly support Angular 2 syntax highlighting, but it is nice that you can mix and match the canonical syntax with the alternate syntax as you please. For example, even though we use the canonical syntax for binding and events, we prefer the alternate syntax for vars:

*ng-for="var item of collection"

instead of:

*ng-for="#item of collection"

We suggest trying out different variations of syntax yourself. Don't shy away from the canonical syntax just because it feels weird. Finally, keep an eye on out for what others are using in examples online and at conferences. More than likely, the community will converge on a set of standards over time.

Template Location

Where do you prefer to keep your templates? (choose one)

Template location used by Angular 2 devs
Both 47.6% 1008
External file 46.5% 986
Inline 3.4% 73
Not sure 1.8% 39
Other 0.6% 13

Analysis

We have a strong preference for inline templates, but there are a number of use cases where separate template files make more sense.

Advantages of inline templates:

  1. All code for a given component in one file
  2. Encourages developers to keep templates small and refactor when they get too big

Advantages of separate template files:

  1. Angular 1 developers familiar with this approach
  2. Easier to share with designers and other non-developers
  3. Generally better intellisense support in editors today
  4. More natural home for large templates that can can’t be broken down into smaller pieces (ex. forms and layouts)

We think that the numbers in favor of inline templates will increase over the next year as developers get familiar with Angular 2 and intellisense support increases. As far as sharing templates with designers, it should be noted that in the React world, there has been some success getting designers to modify inline templates.

Routing

Which routing mechanism do you prefer? (choose one)

Routing libraries used by Angular 2 devs
Component Router 36.7% 776
UI Router 33.0% 698
Not sure 28.1% 594
Custom 1.7% 35
Other 0.4% 9

Analysis

There are a few things to keep in mind while looking at these results:

  1. There is a lot of hype around the new router and it has the support of the core team which is why it is in the lead.
  2. That said, many of the developers that have been working with Angular 2 so far have experienced frustrations (i.e. things not working or features missing) which is why it doesn’t have an overwhelming lead.
  3. The UI Router doesn’t yet have any Angular 2 support, but it is what many developers use with Angular 1 apps and what they expect.

This is not an ideal situation, but we believe that this is just a short term issue. Many of the problems developers have encountered with the Component Router have either already been fixed or are in the process of being addressed. There are also plans to integrate the UI Router with Angular 2 in the near future. So, by the time Angular 2 is released, developers should have two great options for routing.

Data Libraries

Select any of the following data-related libraries that you will likely utilize on a majority of your Angular 2 projects: (choose multiple)

RxJS 38.7% 522
Immutable.js 34.7% 469
Firebase 33.3% 449
angular-meteor 23.8% 321
Falcor 14.5% 196
Other 9.1% 123
BaconJS 6.6% 89

Analysis

There are a lot of libraries out there that can help you manage your data both in Angular 1 and Angular 2. Some interesting notes for each library:

1. RxJS

This library implements observables, which are objects that model push-based data sources. We think the popularity of RxJS in Angular 2 boils down to two primary things. First, a great API for handling one or more asynchronous operations (this is why RxJS is used in the Angular 2 core http module). Second, performance gains from using observables with Angular 2 change detection (reducing complexity from O(N) to O(logN)). For more information on RxJS, check out our discussion with the creator of RxJS on Angular Air. For more information on observables, take a look at the proposed implementation of observables in ES2016.

2. Immutable.js

It is probably safe to attribute the popularity of Immutable.js to React. As mentioned further below, a significant portion of Angular developers also use React. An even bigger portion, including many of the Angular core team members, are aware of the concepts and ideas coming out of the React community and have started to use those concepts in their Angular development. Lee Bryon from the React team gave a great talk earlier this year about the benefits of immutability in general. One of the biggest benefits of using immutable objects in Angular 2, is that it reduces change detection complexity from O(N) to O(1). In other words, change detection occurs in constant time that is not linked to the number of bindings on the page.

3. Firebase

Firebase has always been extremely popular in the Angular community and I wouldn’t expect anything to change with Angular 2. In fact, the numbers here can and should be much higher because we didn’t include Firebase as an option in the survey when it was originally sent out. We added Firebase and angular-meteor after 50 responses were already submitted.

4. angular-meteor

Uri, the creator of angular-meteor, hit me over the head about five minutes after I posted the survey and I quickly added it as an option. There is a strong, vibrant community around this library and it supports both Angular 1 and Angular 2.

5. Falcor

The new kid on the block (just recently released) has been getting a lot of hype since it is backed by Netflix and has been frequently touted by Jafar Husain over the past couple months. Falcor leverages asynchronous data binding in Angular 2 and can be extremely powerful if you have a mostly read-only application.

6. Bacon.js

Bacon.js is another observables library, but not as popular as RxJS.

"Other" Data Libraries

There where a number of other libraries in responses including:

Angular 2 Data

This library isn’t available yet (which is why it wasn’t in the survey), but is being modeled after Ember Data to provide a higher level interface for your data in Angular 2. Other data libraries may be used in conjunction at lower levels. We talked with the Angular core team about Angular 2 Data on Angular Air.

Relay/GraphQL

Created by Facebook and part of the “React stack”, this library is similar in concept to Falcor, but with more features and more complicated (Jafar compares the two here).

Breeze.js

Works well with Angular 1 for caching, model validation, offline support and more.

Server Rendering

Will you use the server rendering features when they are available in Angular 2? (choose one)

Server rendering with Angular 2
Yes 27.2% 566
Sometimes 25.9% 539
No 25.7% 534
Not sure 21.2% 442

Analysis

We split this question out from the general Angular 2 features question below because Patrick and I are heavily involved in the effort to get Angular 2 rendering on the server. As we discussed on Adventures in Angular, universal rendering is fundamentally better than client-only rendering so the only question is about how much effort it takes. We view this result as very positive since we haven’t released the feature yet and only a handful of developers have used it yet. So, if 52.7% of developers think they will use server rendering on at least some of their projects now, we feel really good about gaining a majority of the mind share by the time we release this feature.

Track our progress on the Universal Angular repo and/or follow us on Twitter (@jeffwhelpley and @gdi2290). Also be sure to tune into Angular Connect in October for an update.

Editors

Which editors will you use most often when hacking on Angular 2? (choose multiple)

Webstorm 43.0% 907
Sublime 39.0% 822
VS Code 30.1% 634
Atom 25.0% 528
Other 11.2% 237
VIM 10.7% 226
Emacs 1.6% 33

Analysis

It is interesting to see the most feature packed IDE, Webstorm, in the lead. There are many “enterprise” developers that use Java or .NET along with Angular and they are used to heavier weight development environments.

On the other end of the spectrum, VIM actually got more responses than I thought it would. Our friend Mike Hartington from Ionic is an avid VIM user and thinks it works really well with Angular 2 and TypeScript.

Most of the Angular core team has started to use Visual Studio Code. If you haven’t tried it yet, Visual Studio Code has a Sublime-like feel and it works really well right out of the box with TypeScript.

"Other" Editors

The numbers for Webstorm and Visual Studio Code would even be bigger if you combined them with their “sister” products that people wrote in (ex. IntelliJ and RubyMine with Webstorm and VS.NET with Visual Studio Code).

A half dozen developers also strongly recommended Brackets.

Build Tools

Which build tools do you plan on using when hacking on Angular 2? (choose multiple)

Gulp 72.4% 1464
Grunt 39.5% 799
Webpack 23.6% 478
SystemJS 17.0% 344
Browserify 16.3% 330
JSPM 12.8% 258
Other 3.1% 63
Broccoli 2.3% 46

Analysis

Clearly Gulp is the winner here, but it should be noted that most of these tools can be used at the same time and are not mutually exclusive. We were not surprised to see Webpack have such a strong showing.

Also note that since JSPM uses SystemJS behind the scenes, we can effectively add it to all responses with JSPM that didn’t already have SystemJS. That would put SystemJS usage on par with Webpack.

"Other" Build Tools

There were many write in submissions for simply using npm scripts. Other options submitted by more than five people included Gradle, Meteor's build system, RequireJS and Bower.

Frameworks

What frameworks other than Angular 1.x do you use regularly today? (choose multiple)

jQuery 54.7% 1111
React 26.8% 545
Only Angular 24.2% 491
Backbone 12.6% 255
Meteor 9.7% 196
Other 8.3% 168
Sails 3.8% 77
Ember 3.8% 77

Analysis

As much as we like to think about the future of the web, the fact is that everyone still has to support older browsers and no library does that better than jQuery. Even so, it is amazing to see how predominant jQuery still is with Angular developers today.

Also interesting to see more than 1/4th of Angular developers also using React. There is a lot of hype around React, but it is based on some really good ideas. You could argue that number is going to increase over the next year as React becomes even more popular or you could argue it will decrease since Angular 2 has adopted many of the best concepts from React (and thus less motivation for Angular developers to go outside Angular).

"Other" Frameworks

If we could have changed one question on this survey this would have been it. We forgot to include 4 frameworks that a number of people wrote in about:

  • Ionic  — An extremely popular library for building hybrid mobile/web apps that uses Angular. The Ionic team are huge fans of Angular 2 and are one of the only groups writing production-level code on top of Angular 2 today.
  • Dart  — I am sure someone outside Google uses Dart, but I just haven’t met that person yet. In any case, it will be interesting to see if Dart remains popular inside Google given the decision not to include the Dart VM in Chrome and the fact that Angular 2 with TypeScript addresses some of the problems that Dart is trying to solve.
  • Polymer  — Unlike Dart, I have actually met a number of groups that are using Polymer in the wild. Polymer will likely never be as popular as Angular, but as modern browsers become more prevalent and web component standards solidify, there will be a niche for Polymer.
  • Aurelia  — A framework similar to Angular created by a former Angular core team member.

Features

Which Angular 2 features ar eyou most looking forward to? (choose multiple)

Change Detection 65.0% 1298
Web Components 57.9% 1157
Zone.js 53.1% 1060
Component Router 42.3% 845
DI updates 39.4% 788
Server Rendering 37.1% 742
i18n 29.2% 583
Animation updates 25.7% 513
Other 3.6% 72

Analysis

As I wrote about last year, many developers love to hate Angular. In that article I wrote:

The typical anti-Angular rant usually includes one or more of the following gripes:

  1. Subpar features (ex. routing, model layer)
  2. Missing features (ex. server rendering, async loading)
  3. Cumbersome and/or confusing APIs (ex. injection arrays, service/factory/provider, directives)
  4. Fundamental design decisions (ex. working off the DOM, dirty checking vs KVO vs Virtual DOM, mutable data vs immutable data).

Let’s match up these Angular 1 issues with the top Angular 2 features that people are excited about:

1. Change Detection

Change detection in Angular 2 completely eliminates most of the fundamental design decision issues from Angular 1 (issue #4 above). Right out of the box, Angular 2 change detection is faster than Angular 1. You can see evidence of this in a number of experiments that developers are starting to come out with like this recent blog post from the Meteor team. You can also use immutable or observable data as you wish to make your app even faster. In addition, the design of change detection allows for unidirectional data flow which makes your app easier to reason about. In short, the developer has full control over how change detection works in Angular 2 and can optimize it for their specific situation. It’s no wonder this is the top feature people are excited about.

2. Web Components

To be quite frank, we don’t think most developers care about Web Components. When we talk to developers about this, they talk more about the component-driven design of Angular 2 rather than integration with actual Web Components. Building your web app with a highly structured component tree in Angular 2 solves many of the issues with cumbersome and/or confusing APIs in Angular 1 (issue #3).

3. Zone.js

This library has many uses in Angular 2 core, but the most notable benefit is that it eliminates the need for developers to use $scope.$apply() whenever they change data outside the context of Angular. This is huge.

4. Component Router

When it is ready, the Component Router will address one of the biggest subpar features of Angular 1 (issue #1). It will also enable the asychronous loading of different components (issue #2). We talked with Brian Ford about the Component Router on Angular Air.

5. Dependency Injection

One of the biggest noticeable impacts of the Angular 2 DI system is that Angular no longer needs to call toString() on a function to get the arguments as string tokens. This means no more minification issues with Angular and no need to manually declare the string tokens with an array (i.e. issue #3). Overall, the DI interface is much cleaner and more flexible. Pascal wrote a great blog post about the Angular 2 DI system that explains more.

6. Server Rendering

This is one of the biggest missing features from Angular 1 (issue #2) and it is going to be awesome. We explain the motivations behind this feature and how we are building it into Angular 2 in our recent AngularU talk.

"Other" Features

There were a couple other notable features submitted including:

Demographics

What is your Angular 1.x experience level? (choose one)

Demographics for the Angular 2 survey
Novice / beginner 13.9% 292
Experienced (simple apps) 27.6% 581
Advanced (1+ large prod app) 37.2% 784
Expert 21.3% 448

Analysis

This survey was originally intended for more advanced Angular developers, so we were happy to see that a majority of the responders (58.7%) came from the Advanced or Expert buckets. However, since we changed the focus from “what are people using” to “what do people think they will use”, it was also great to get a healthy showing from less experienced Angular developers. As a result, we feel that this survey is a pretty good representation of the Angular community as a whole.

Final Word

Angular 2

A really big thank you to the thousands of Angular developers that participated in this survey. Also thanks to the dozens of friends that reviewed this post and provided feedback. In particular, thanks to Brad Green for giving us the chance to do a guest post on the official Angular blog.

We found the results extremely interesting and we hope that this blog post helps everyone in the community get a sense of what other developers are thinking about Angular 2 so far. That said, keep in mind that the responses to these same questions will likely be quite different a year from now after Angular 2 has been released and developers are using it in production. We will have to do a follow up to this survey at that time to see how sentiment has changed.

Jeff Whelpley | GetHuman | @jeffwhelpley
Patrick Stapleton | Angular Class | @gdi2290

Share:

Thursday, 27 August 2015

Build Better Mobile Apps with FirebaseUI

Mike McDonald
Mike McDonald
Engineer

Designed to help native mobile developers quickly and easily develop Firebase apps, FirebaseUI eliminates bloat in your application code by providing native bindings to common UI controls.

FirebaseUI adds support to quickly hook a Firebase database reference or query to a ListView, GridView, RecyclerView on Android or a UITableView or UICollectionView iOS.

Start by creating an Android Firebase project or iOS Firebase project then follow our Android or iOS quickstarts below.

Android Quickstart

On Android, add the latest version of FirebaseUI to your build.gradle:


compile 'com.firebase:firebase-ui:0.2.0'

Resync your project and you're ready to continue.

More information, including a more in-depth installation walkthrough, can be found on the FirebaseUI-Android README.

Once we've installed FirebaseUI, create a FirebaseListAdapter which binds a Firebase database reference or query to a ListAdapter and provides developers an easy way to populate ListView views with developer specified model objects (more information on using Java Objects is available in the docs).


Firebase.setAndroidContext(this);
Firebase ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");

mAdapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, ref) {
@Override
protected void populateView(View view, ChatMessage object) {
/* Populate view with contents of the model object */
}
};

mListView.setListAdapter(mAdapter);

If you want more examples, check out the Android README, or see our Android chat app example. The Javadoc is available here.

iOS Quickstart

On iOS, add the latest version of FirebaseUI to your podfile:


pod 'FirebaseUI', '~> 0.2.0'

If you're using Swift, make sure to add:


platform :ios, '8.0'
use_frameworks!

pod install, then open the generated .xcworkspace.

More information, including a more in-depth installation walkthrough, can be found on the FirebaseUI-iOS README.

Once we've installed FirebaseUI, create a FirebaseTableViewDataSource. This datasource will provide cells and the associated FDataSnapshots (or a custom model object, a feature in beta) to populate UITableViewCells, a custom subclass, or even a custom XIB.


Firebase *ref = [Firebase alloc] initWithUrl:@"https://<YOUR-FIREBASE-APP>.firebaseio.com/chat"];

self.dataSource = [[FirebaseTableViewDataSource alloc] initWithRef:ref
modelClass:[FDataSnapshot class]
cellClass:[UITableViewCell class]
cellReuseIdentifier:@""
view:self.tableView];

[self.dataSource populateCellWithBlock:^void(UITableViewCell *__nonnull cell, FDataSnapshot *__nonnull snap) {
/* Populate cell with contents of the snapshot */
}
}];

self.tableView.dataSource = self.dataSource;

let ref = Firebase(url: "https://<YOUR-FIREBASE-APP>.firebaseio-demo.com")

self.dataSource = FirebaseTableViewDataSource(ref: ref,
modelClass: FDataSnapshot.self,
cellClass: UITableViewCell.self,
cellReuseIdentifier: "",
view: self.tableView)

self.dataSource.populateCellWithBlock { (cell: UITableViewCell, obj: NSObject) -> Void in
let snap = obj as! FDataSnapshot // Force cast to an FDataSnapshot
/* Populate cell with contents of the snapshot */
}

self.tableView.dataSource = self.dataSource

FirebaseUI can also be used to back a UICollectionView using the FirebaseCollectionViewDataSource.

If you want more examples, check out the iOS README, or see our iOS chat app example. The Appledoc is available here.

Next up, Login

We're working on making mobile development as effortless as possible, so we're always looking for ways to improve development speed and reduce complexity. One major area that we hear a lot of developers struggle is around mobile authentication, which typically requires installation of third party SDKs and understanding lots of additional docs.

While we have login demo apps on Android and iOS that explain these processes, FirebaseUI 0.3 will incorporate a set of login helper classes and standard views to make adding authentication to your mobile apps simple.

Our long term strategy involves adding support for pagination, infinite scroll, and client side filtering. We'd also love to hear feature requests from you.

Submit a Pull Request!

Do you want to see those features added faster? Are you excited about making Firebase apps easier to develop? Is writing quality code your passion?

We'd love to have your help building and maintaining these libraries. Please submit issues for bugs and feature requests on Android and iOS, and pull requests are always welcome.

Lastly, if you've built anything, don't be shy! Share your apps with us on Twitter @Firebase or in our Google Group--we're excited to see what you build.

Share:

Tuesday, 25 August 2015

Angular 1 and Angular 2 integration: the path to seamless upgrade

Have an existing Angular 1 application and are wondering about upgrading to Angular 2?  Well, read on and learn about our plans to support incremental upgrades.

Summary

Good news!
  • We're enabling mixing of Angular 1 and Angular 2 in the same application.
  • You can mix Angular 1 and Angular 2 components in the same view.
  • Angular 1 and Angular 2 can inject services across frameworks.
  • Data binding works across frameworks.

Why Upgrade?

Angular 2 provides many benefits over Angular 1 including dramatically better performance, more powerful templating, lazy loading, simpler APIs, easier debugging, even more testable and much more.  Here are a few of the highlights:

Better performance

We've focused across many scenarios to make your apps snappy.  3x to 5x faster on initial render and re-render scenarios.
  • Faster change detection through monomorphic JS calls
  • Template precompilation and reuse
  • View caching
  • Lower memory usage / VM pressure
  • Linear (blindingly-fast) scalability with observable or immutable data structures
  • Dependency injection supports incremental loading

More powerful templating

  • Removes need for many directives
  • Statically analyzable - future tools and IDEs can discover errors at development time instead of run time
  • Allows template writers to determine binding usage rather than hard-wiring in the directive definition

Future work

We've decoupled Angular 2's rendering from the DOM.  We are actively working on supporting the following other capabilities that this decoupling enables:
  • Server-side rendering.  Enables super-fast initial render and web-crawler support.
  • Web Workers. Move your app and most of Angular to a Web Worker thread to keep the UI smooth and responsive at all times.
  • Native mobile UI. We're enthusiastic about supporting the Web Platform in mobile apps.  At the same time, some teams want to deliver fully native UIs on their iOS and Android mobile apps.  
  • Compile as build step.  Angular apps parse and compile their HTML templates.  We're working to speed up initial rendering by moving the compile step into your build process.  

Angular 1 and 2 running together

Angular 2 offers dramatic advantages over Angular 1 in performance, simplicity, and flexibility.  We're making it easy for you to take advantage of these benefits in your existing Angular 1 applications by letting you seamlessly mix in components and services from Angular 2 into a single app. By doing so, you'll be able to upgrade an application one service or component at a time over many small commits.

For example, you may have an app that looks something like the diagram below.  To get your feet wet with Angular 2, you decide to upgrade the left nav to an Angular 2 component.  Once you're more confident, you decide to take advantage of Angular 2's rendering speed for the scrolling area in your main content area.



For this to work, four things need to interoperate between Angular 1 and Angular 2:
  • Dependency injection
  • Component nesting
  • Transclusion
  • Change detection
To make all this possible, we're building a library named ng-upgrade. You'll include ng-upgrade and Angular 2 in your existing Angular 1 app, and you'll be able to mix and match at will.

You can find full details and pseudocode in the original upgrade design doc or read on for an overview of the details on how this works.  In future posts, we'll walk through specific examples of upgrading Angular 1 code to Angular 2.

Dependency Injection

First, we need to solve for communication between parts of your application. In Angular, the most common pattern for calling another class or function is through dependency injection. Angular 1 has a single root injector, while Angular 2 has a hierarchical injector. Upgrading services one at a time implies that the two injectors need to be able to provide instances from each other.

The ng-upgrade library will automatically make all of the Angular 1 injectables available in Angular 2. This means that your Angular 1 application services can now be injected anywhere in Angular 2 components or services.

Exposing an Angular 2 service into an Angular 1 injector will also be supported, but will require that you to provide a simple mapping configuration.

The result is that services can be easily moved one at a time from Angular 1 to Angular 2 over independent commits and communicate in a mixed-environment.

Component Nesting and Transclusion

In both versions of Angular, we define a component as a directive which has its own template.  For incremental migration, you'll need to be able to migrate these components one at a time. This means that ng-upgrade needs to enable components from each framework to nest within each other.

To solve this, ng-upgrade will allow you to wrap Angular 1 components in a facade so that they can be used in an Angular 2 component. Conversely,  you can wrap Angular 2 components to be  used in Angular 1. This will fully work with transclusion in Angular 1 and its analog of content-projection in Angular 2.

In this nested-component world, each template is fully owned by either Angular 1 or Angular 2 and will fully follow its syntax and semantics. This is not an emulation mode which mostly looks like the other, but an actual execution in each framework, dependending on the type of component. This means that components which are upgraded to Angular 2 will get all of the benefits of Angular 2, and not just better syntax.

This also means that an Angular 1 component will always use Angular 1 Dependency Injection, even when used in an Angular 2 template, and an Angular 2 component will always use Angular 2 Dependency Injection, even when used in an Angular 1 template.

Change Detection

Mixing Angular 1 and Angular 2 components implies that Angular 1 scopes and Angular 2 components are interleaved. For this reason, ng-upgrade will make sure that the change detection (Scope digest in Angular 1 and Change Detectors in Angular 2) are interleaved in the same way to maintain a predictable evaluation order of expressions.

ng-upgrade takes this into account and bridges the scope digest from Angular 1 and change detection in Angular 2 in a way that creates a single cohesive digest cycle spanning both frameworks.

Typical application upgrade process

Here is an example of what an Angular 1 project upgrade to Angular 2 may look like.
  1. Include the Angular 2 and ng-upgrade libraries with your existing application
  2. Pick a component which you would like to migrate
    a. Edit an Angular 1 directive's template to conform to Angular 2 syntax
    b. Convert the directive's controller/linking function into Angular 2 syntax/semantics
    c. Use ng-upgrade to export the directive (now a Component) as an Angular 1 component (this is needed if you wish to call the new Angular 2 component from an Angular 1 template)
  3. Pick a service which you would would like to migrate
    a. Most services should require minimal to no change.
    b. Configure the service in Angular 2
    c. (optionally) re-export the service into Angular 1 using ng-upgrade if it's still used by other parts of your Angular 1 code.
  4. Repeat doing step #2 and #3 in an order convenient for your application developmen
  5. Once no more services/components need to be converted drop the top level Angular 1 bootstrap and replace with Angular 2 bootstrap.
Note that each individual change can be checked in separately and the application continues working letting you continue to release updates as you wish.

We are not planning on adding support for allowing non-component directives to be usable on both sides. We think most of the non-component directives are not needed in Angular 2 as they are supported directly by the new template syntax (i.e. ng-click vs (click) )

Q&A

I heard Angular 2 doesn't support 2-way bindings. How will I replace them?
Actually, Angular 2 supports two way data binding and ng-model, though with slightly different syntax.

When we set out to build Angular 2 we wanted to fix issues with the Angular digest cycle. To solve this we chose to create a unidirectional data-flow for change detection. At first it was not clear to us how the two way forms data-binding of ng-model in Angular 1 fits in, but we always knew that we had to make forms in Angular 2 as simple as forms in Angular 1.

After a few iterations we managed to fix what was broken with multiple digests and still retain the power and simplicity of ng-model in Angular 1.

Two way data-binding has a new syntax: [(property-name)]="expression" to make it explicit that the expression is bound in both directions. Because for most scenarios this is just a  small syntactic change we expect easy migration.

As an example, if in Angular 1 you have:
<input type="text" ng-model="model.name" />

You would convert to this in Angular 2:
<input type="text" [(ng-model)]="model.name" />

What languages can I use with Angular 2?
Angular 2 APIs fully support coding in today's JavaScript (ES5), the next version of JavaScript (ES6 or ES2015), TypeScript, and Dart.

While it's a perfectly fine choice to continue with today's JavaScript, we'd like to suggest that you explore ES6 and TypeScript (which is a superset of  ES6) as they provide dramatic improvements to your productivity.

ES6 provides much improved syntax and standards for common libraries like promises and modules.  TypeScript gives you dramatically better code navigation, automated refactoring in IDEs, documentation, finding errors, and more.

Both ES6 and TypeScript are easy to adopt as they are supersets of today's ES5.  This means that all your existing code is valid and you can add their features a little at a time.

What should I do with $watch in our codebase?
In order to gain speed and predictability, in Angular 2 you specify watch expressions declaratively in the HTML template or in annotations on your component directives. One additional benefit from this is that Angular 2 applications can be safely minified/obfuscated for smaller payload.

For any scenarios that don't fit with these mechanisms, you can take advantage of observables -- ES7 Observables as in Rx.js for JavaScript or Streams in Dart.

What can I do today to prepare myself for the migration?
Follow the best practices and build your application using components and services in Angular 1 as described in the AngularJS Style Guide.

Wasn't the original upgrade plan to use the new Component Router?
The upgrade plan that we announced at ng-conf 2015 was based on upgrading a whole view at a time and having the Component Router handle communication between the two versions of Angular.

The feedback we received was that while yes, this was incremental, it wasn't incremental enough.  We went back and redesigned for the plan as described above.

Are there more details you can share?
Yes!  In the Angular 1 to Angular 2 Upgrade Strategy design doc.

We're working on a series of upcoming posts on related topics including:
  • Mapping your Angular 1 knowledge to Angular 2.
  • A set of FAQs on details around Angular 2.
  • Detailed migration guide with working code samples.
See you back here soon!

Share:

Wednesday, 19 August 2015

Announcing Lower, Simpler Pricing

Max Henderson
Max Henderson
Head of Growth

Firebase is growing faster every day, and since joining Google last year, we've gained access to world-class infrastructure and scale. Today, we're announcing across-the-board price drops to lower the barrier to entry for Firebase, so developers everywhere can create extraordinary experiences for their users.

Here are the changes we've made:

Removing Concurrent Caps

We've heard from you that concurrents are confusing. So today, we're eliminating the need to worry about them… they're now unlimited for our Candle plan and above!

To prevent abuse, we're limiting simultaneous connections to a single Firebase to 10,000 by default, which is generally enough for applications with at least 100,000 daily active users. We can scale far beyond that limit, and users can contact us to permanently raise the cap with 24 hours notice.

Doubling the Free Tier and $5 Custom Domains

Firebase is about giving people the tools to build extraordinary apps. Experimentation is core to what we stand for, and we believe people should be able to build non-trivial apps on Firebase for free.

Therefore, we are widening our free tier to:

  • 100 concurrent users (2x the previous 50)
  • 10 GB database bandwidth (2x the previous 5 GB)
  • 1 GB database storage (10x the previous 100 MB)

In addition, you can now add a custom domain to your free app for only $5/month, with our new Spark plan. No more need to upgrade to the Candle plan just to get a custom domain!

Increasing Paid Plan Resources up to 300%

Finally, we're increasing the resource limits on all our paid plans. The Candle, Bonfire, Blaze, and Inferno plans are all seeing big increases in database bandwidth and storage, up to 3x. We've also lowered overage fees to increase flexibility as your app scales.

Here's a full summary of the changes, and you can check out our new pricing page here:

Database Bandwidth Database Storage
New Limit Increase New Limit Increase
Free / Spark 10 GB 2x 1 GB 10x
Candle 50 GB 2.5x 10 GB 3x
Bonfire 150 GB 2x 30 GB 3x
Blaze 500 GB 2x 100 GB 3x
Inferno 1500 GB 1.5x 300 GB 3x

It has been a pleasure building Firebase, and it's humbling to see the great things you build with us. We've got some great new features coming soon, and are more excited than ever for the future.

Happy Coding!

Share:

Tuesday, 28 July 2015

EmberFire 1.5.0

Tim Stirrat
Tim Stirrat
Frontend Developer

Today's EmberFire release includes new features that will make it even easier for Ember developers to connect their apps to Firebase. The EmberFire 1.5.0 release brings Ember Data 1.13.0 compatibility, integration with Firebase Authentication, and some updates for embedded records.

What is EmberFire?

EmberFire is an adapter for using Firebase with Ember Data. It is packaged as an Ember CLI addon, which makes it incredibly easy to add Firebase as the backend for your Ember app. Using EmberFire, all of your models stored in Ember Data will be automatically synchronized with our remote Firebase database. Simply calling save() on a record will save it to the store and persist that data in your Firebase database.

New Features in EmberFire 1.5.0

Ember Data 1.13.0 Compatibility

Ember Data has made it out of beta, which means we can count on a stable API. This is great news for EmberFire. In addition to 1.13.0 compatibility, we're working on staying up to date with the latest releases, and our tests are also passing for 2.0 canary!

Torii Authentication

You can now authenticate users in your EmberFire app with Facebook, Twitter, GitHub, and Google using our Torii adapter. Get started by enabling the authentication provider you’d like to use in your Firebase Dashboard, installing the Torii addon, and following the authentication section in our guide. Once you've set it up, you can authenticate a user inside your route or controller with the following snippet:


this.get("session").open("firebase", { provider: "twitter"})
.then(function(data) {
console.log(data.currentUser);
});

This snippet of code will authenticate a user with Twitter and log the returned user object to the console.

Many thanks to Matt Sumner for his work on this.

Embedded Record Changes

This release also changes the way embedded records are declared. If you have an embedded hasMany / belongsTo relationship in your EmberFire app, you should now follow the Ember Data conventions by configuring embedded record settings in a serializer. Visit the relationships section of our guide for details. Just be sure to use Ember Data 1.13.6+ for embedded records compatibility.

Getting Started

If you're new to EmberFire, using it with your Ember CLI app is as simple as installing our addon:


ember install emberfire

Then, update your Firebase URL in config/environment.js and you're ready to persist your Ember Data records in your Firebase database. Check out our guide for a detailed walkthrough on all things EmberFire.

We'd love to hear what you think of the latest release. Post any feedback in our Ember Google Group, or open an issue on GitHub. Contributions to EmberFire are always welcome, so feel free to submit a pull request if there's something you'd like to see added.

We're excited to see what you build with Firebase and Ember!

Share:

Wednesday, 15 July 2015

ReactFire 0.5.0

Jacob Wenger
Jacob Wenger
Core Developer

React and Firebase were made for each other. And with the introduction of ReactFireback in May 2014, we provided a simpler way to build apps using both technologies. Today we're announcing ReactFire 0.5.0 - the biggest update since that initial release. The update brings improved performance, a handful of bug fixes, and some extra features to simplify development.

What is ReactFire?

For those who aren't familiar, ReactFire is a React mixin. The ReactFireMixin makes it dead simple to bind data stored in Firebase to a component's state. It handles both array-like and object-like data via the bindAsArray() and bindAsObject() methods, respectively.

For example, say you have a list of messages stored in your Firebase database that looks like this:

{
"messages": {
"-JqpIO567aKezufthrn8": {
"uid": "barney",
"text": "Welcome to Bedrock City!"
},
"-JqpIP5tIy-gMbdTmIg7": {
"uid": "fred",
"text": "Yabba dabba doo!"
}
}
}

You can bind the message data to your component's state by calling bindToArray() in your componentWillMount() method:

var ExampleComponent = React.createClass({
mixins: [ReactFireMixin],

getInitialState: function() {
return {
messages: []
};
},

componentWillMount: function() {
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com/messages");
this.bindAsArray(ref, "messages");
},

render: function() {
// ...
}
});

The message data is now bound to this.state.messages. Whenever messages are added, removed, updated, or moved in Firebase, those changes are reflected automatically in this.state.messages

  • no calls to this.setState() required! The bound data can be used as normal in your component's render() method:
render: function() {
var messages = this.state.messages.map(function(message) {
return (
<li key={ message['.key'] }>{ message.uid } says { message.text } </li>
);
});
return <ul>{ messages }</ul>
;
}

What's new in ReactFire 0.5.0?

The 0.5.0 release is the first major upgrade to the ReactFireMixin since its initial release. The API is still just as minimal, but a lot has changed under the hood.

The initial implementation of bindAsArray() was quite simplistic. It had poor performance and did not properly handle complex Firebase queries. The new implementation provides improved performance (especially on large data sets) and works well with all Firebase queries. Best of all, no changes to your code are required to enable these improvements.

Another major change with 0.5.0 is the addition of the .key attribute. ReactFire now adds the .key attribute to every record it creates via the bindAsArray() and bindAsObject() methods. In previous versions, it was impossible to retrieve key names for bound items. The 0.5.0 release fixes this by including the key name by adding a .key attribute to each bound item.

As an example, let's look again at the messages array from above. The resulting bound array stored in this.state.messages will be:

[
{
".key": "-JqpIO567aKezufthrn8", // New in version 0.5.0!
"uid": "barney",
"text": "Welcome to Bedrock City!"
},
{
".key": "-JqpIP5tIy-gMbdTmIg7", // New in version 0.5.0!
"uid": "fred",
"text": "Yabba dabba doo!"
}
]

The inclusion of .key makes it possible to easily write data back to Firebase to update, remove, or move a record in the array. All objects synced via bindAsObject() now include the .key attribute as well.

Finally, version 0.5.0 changes how primitive values (strings, numbers, booleans) are handled. As an example, say you have the following data in your Firebase database:

{
"foo": "bar"
}

If you call bindAsObject() on the /foo/ path, previous versions bound the value as a string "bar". As of today's 0.5.0 release, the bound object now looks like this:

{
".key": "foo",
".value": "bar"
}

You have access to the key that was bound to (.key) as well as the bound value (.value). Primitive values bound via bindAsArray() behave in the same way with the primitive value being stored in .value. Non-primitive values (that is, regular JavaScript objects) have not changed and behave in the same in all versions, except for the addition of .key.

Looking Forward

There is a lot of excitement in the React community about ES6+, Relay, GraphQL, and ReactNative. Discussions about these topics are even ongoing in the ReactFire GitHub repo. We are following the new announcements and technologies closely. Since we use React in production at Firebase, we want the two technologies to work as well as possible together.

We've found that using the vanilla React and Firebase libraries together works great and somewhat replaces the need for an application architecture like Flux. Things like ReactFire simplify development further by providing a shorthand for a lot of common use cases. And community contributions like the recently released re-baselibrary show how well Firebase can fit into new technologies like Relay. The future of a React + Firebase application tech stack is exciting and promising. The two technologies make it that much easier to build scalable apps in a fraction of the time they traditionally have taken. You can expect ReactFire to evolve alongside React over the course of the comings months.

Getting Started with ReactFire

The best place to get started with ReactFire is by heading over to the docs. We have a five minute quickstart, a guide which walks you through making an example app, and a full API reference with more examples of binding data via bindAsArray() and bindAsObject().

If you run across any bugs or have feature suggestions, please file them on GitHub. If you have questions about the API or how to build apps with ReactFire, post them on the Firebase Google Group.

We are excited to see what you create!

Share: