web-apps/apps/common/main/lib/core/NotificationCenter.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-03-11 00:48:53 +00:00
/**
* NotificationCenter.js
*
* A pub-sub object that can be used to decouple various parts
* of an application through event-driven architecture.
*
* Created by Alexander Yuzhin on 1/21/14
* Copyright (c) 2014 Ascensio System SIA. All rights reserved.
*
*/
/**
* Using:
*
* Common.NotificationCenter.on("foo", function(){
* alert("bar");
* });
*
* Common.NotificationCenter.trigger("foo"); // => alert box "bar"
*
*/
if (Common === undefined)
var Common = {};
define([
'backbone'
], function (Backbone) {
'use strict';
var NotificationCenter = function(){};
// Copy the basic Backbone.Events on to the event aggregator
_.extend(NotificationCenter.prototype, Backbone.Events);
if(typeof Common.NotificationCenter == 'undefined') {
// Method to create new Common.NotificationCenter class
NotificationCenter.extend = Backbone.Model.extend;
Common.NotificationCenter = new NotificationCenter();
}
else {
throw ('Native Common.NotificationCenter instance already defined.')
}
});