Skip to content

Instantly share code, notes, and snippets.

@guilhermeblanco
Created January 9, 2012 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guilhermeblanco/1584974 to your computer and use it in GitHub Desktop.
Save guilhermeblanco/1584974 to your computer and use it in GitHub Desktop.
Widget support in PureMVC
Object.declare('base.widget.Command');
base.widget.Command = function ()
{
org.puremvc.js.patterns.command.SimpleCommand.call(this);
};
Object.extend(base.widget.Command, org.puremvc.js.patterns.command.SimpleCommand);
Object.declare('base.widget.Mediator');
base.widget.Mediator = function (mediatorName, view)
{
org.puremvc.js.patterns.mediator.Mediator.call(this, mediatorName, view);
this._notificationInterests = [];
this._notificationHandlers = {};
}
Object.extend(base.widget.Mediator, org.puremvc.js.patterns.mediator.Mediator);
var _p = base.widget.Mediator.prototype;
_p.bind = function (eventName, callback, scope)
{
scope = scope || this;
if (this._notificationInterests.indexOf(eventName) === -1) {
this._notificationInterests[this._notificationInterests.length] = eventName;
}
this._notificationHandlers[eventName] = Relegate.create(scope, callback);
};
_p.unbind = function (eventName)
{
var eventIndex = this._notificationInterests.indexOf(eventName);
if (eventIndex !== -1) {
this._notificationInterests.splice(eventIndex, 1);
this._notificationHandlers[eventName] = null;
delete this._notificationHandlers[eventName];
}
};
_p.listNotificationInterests = function ()
{
return this._notificationInterests;
};
_p.handleNotification = function (notification)
{
var notificationName = notification.getName();
if (typeof this._notificationHandlers[notificationName] !== "undefined") {
this._notificationHandlers[notificationName](notification);
}
};
Object.declare('base.widget.ViewComponent');
base.widget.ViewComponent = function (component)
{
org.puremvc.js.patterns.observer.Notifier.call(this);
this._component = component;
}
Object.extend(base.widget.ViewComponent, org.puremvc.js.patterns.observer.Notifier);
var _p = base.widget.ViewComponent.prototype;
_p.getComponent = function ()
{
return this._component;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment