Over 10 years of community discussion and knowledge are maintained here as a read-only archive.
puremvc.define ( // class info- defined separately to avoid collision with property // names defined on the prototype. None of these properties are added // to the classes produced. { /** * The classlets qualified name. The framework will automatically * create this object hierarchy for you, and your classes * constructor will be its referent * * @type {String} */ classname: 'example.UserMediator' /** * The classlets superclass. The helper method will take care * of subclassing your class. Optional. * * @type {Function} */ , parent: puremvc.Mediator /** * Your classes constructor. If not provided, one will be created * automatically for you. The automatically created constructor will * take care of invoking super constructors if the class is * extended from another * * @constructor */ , constructor: function (viewComponent) { puremvc.Mediator.call(this.constructor.NAME, viewComponent); } } // prototypal traits- all instances will have these properties and // you can override superclass methods , { /** @override */ listNotificationInterests: function () { return [ ]; } /** @override */ , onRegister: function () { } /** @override */ , onRemove: function () { } /** * Get the UserMediators UiComponent * @return {User} */ , getUser: function () { return this.viewComponent; } } , // static traits, i.e. properties which will be defined on constructors { /** * @static * @const * @type {String} */ NAME: 'UserMediator' } );
Why not using no name at all for the creational method?
activateMvcPowers
How would that work?
puremvc( // class info- defined separately to avoid collision with property // names defined on the prototype. None of these properties are added // to the classes produced. { /** * The classlets qualified name. The framework will automatically * create this object hierarchy for you, and your classes * constructor will be its referent * * @type {String} */ classname: 'example.UserMediator' /** * The classlets superclass. The helper method will take care * of subclassing your class. Optional. * * @type {Function} */ , parent: puremvc.Mediator /** * Your classes constructor. If not provided, one will be created * automatically for you. The automatically created constructor will * take care of invoking super constructors if the class is * extended from another * * @constructor */ , constructor: function (viewComponent) { puremvc.Mediator.call(this.constructor.NAME, viewComponent); } } // prototypal traits- all instances will have these properties and // you can override superclass methods , { /** @override */ listNotificationInterests: function () { return [ ]; } } , // static traits, i.e. properties which will be defined on constructors { /** * @static * @const * @type {String} */ NAME: 'UserMediator' } );
var MyClassObject = puremvc("example.UserMediator");
is someone working on a super-simple Hello World example yet?
var BaseMediator = Class.create( puremvc.Mediator, { initialize: function($super, name, viewComponent) { $super(name, viewComponent); }, listNotificationInterests: function() { return [ ApplicationFacade.NOTIFICATION_A ]; }, handleNotification: function(notification) { switch(notification.getName()) { case ApplicationFacade.NOTIFICATION_A: // do stuff for A break; } } });
var ExtendedMediator = Class.create( BaseMediator, { initialize: function($super, name, viewComponent) { $super(name, viewComponent); }, listNotificationInterests: function($super) { var interests = $super(); interests.push(ApplicationFacade.NOTIFICATION_B); return interests; }, handleNotification: function($super, notification) { switch(notification.getName()) { case ApplicationFacade.NOTIFICATION_B: // do stuff for B break; default: // let the super class handle it $super(notification); break; } } });ExtendedMediator.NAME = "ExtendedMediator";
Also, there is a PureMVC Dart port. Dart has proper inheritance and typing.
I checked out John Resig's solution, which seems proper. I don't know what it would take to adapt it to the oop.js class, but its worth looking into.
can have a look into porting the John Resig solution into PureMVC. I have studied those kind of solution