Click here to Skip to main content
15,885,989 members
Articles / Web Development / HTML

A Sample Real-time Web Application using Ember.js, REST API, and SignalR

Rate me:
Please Sign up or sign in to vote.
4.82/5 (36 votes)
9 Jul 2013MIT6 min read 223.4K   3.9K   140  
A sample real-time web application using Ember.js, REST API, and SignalR.
/// <reference path="_references.js" />

(function (a) {
    var hub = $.connection.customerHub;

    function findCustomer(id) {
        var c = app.customerController.get('customers').findProperty('id', id);
        return c;
    }

    hub.client.add = function (message) {
        var customer = JSON.parse(message);
        var c = findCustomer(customer.id);
        !c && app.customerController.get('customers').pushObject(app.CustomerModel.create(customer));
    }

    hub.client.update = function (message) {
        var customer = JSON.parse(message);
        var c = findCustomer(customer.id);
        c && c.set('quiet', true) && c.setProperties(customer) && c.set('quiet', false);
    }

    hub.client.remove = function (message) {
        var customer = JSON.parse(message);
        var c = findCustomer(customer.id);
        if (c) {
            if (c.id === app.customerController.get('currentCustomer').id) {
                app.customerController.set('currentCustomer', null);
                app.customerController.random();
            }
            app.customerController.get('customers').removeObject(c);
        }
    }

    $.connection.hub.start();

    a.hub = hub;

})(window.App);

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Technical Lead
Vietnam Vietnam
Learning IT Technology since 2001, I get started with C++ from 2003. I switch to C# and.NET framework since 2004. Now I am a NodeJS / .NET Core programmer on Azure.

Comments and Discussions