lib/assets/javascripts/jax/mvc/controller.js in jax-2.0.12 vs lib/assets/javascripts/jax/mvc/controller.js in jax-3.0.0.rc1

- old
+ new

@@ -51,11 +51,11 @@ * -- up to a target rate of 60 passes per second. * **/ (function() { var protected_instance_method_names = [ - 'initialize', 'toString', 'getControllerName', 'constructor', 'isKindOf', 'fireAction', + 'initialize', 'toString', 'getControllerName', 'constructor', 'fireAction', 'eraseResult' ]; function is_protected(method_name) { for (var i = 0; i < protected_instance_method_names.length; i++) @@ -63,37 +63,50 @@ return true; return false; } Jax.Controller = (function() { - function setViewKey(self) { - self.view_key = self.getControllerName()+"/"+self.action_name; - self.rendered_or_redirected = true; - } - return Jax.Class.create({ + index: function() { + /* override for scene setup */ + }, + /** - * Jax.Controller#fireAction(action_name) -> Jax.Controller + * Jax.Controller#fireAction(action_name, context) -> Jax.Controller * * Erases the results of the last action, then calls the specified action. If it doesn't exist, * an error is raised. Finally, unless the action redirects to a different action or renders * a different action directly, the specified action becomes the focus of the current view. * * Returns this controller. **/ - fireAction: function(action_name) { + fireAction: function(action_name, context) { + if (!this.context) { + this.context = context; + this.world = context && context.world; + if (!this.activeCamera) + this.activeCamera = context.world.cameras[0]; + // TODO remove deprecated `player` from controller + if (!this.player) + Object.defineProperty(this, 'player', {get: function() { return context.player; }}); + } + this.eraseResult(); this.action_name = action_name; if (this[action_name]) this[action_name].call(this, []); else throw new Error("Call to missing action: '"+action_name+"' in controller '"+this.getControllerName()+"'"); if (!this.rendered_or_redirected) - setViewKey(this); + this.view_key = this.getControllerName()+"/"+this.action_name; + this.view = Jax.views.find(this.view_key); + this.rendered_or_redirected = true; return this; }, + + getControllerName: function() { return null; }, /** * Jax.Controller#eraseResults() -> Jax.Controller * * Erases the results of the most recent render action. That is, whether or not it rendered @@ -122,13 +135,10 @@ * * Returns the newly-constructed controller. **/ invoke: function(action_name, context) { var instance = new this(); - instance.context = context; - instance.world = context && context.world; - instance.player = context && context.player; - instance.fireAction(action_name); + instance.fireAction(action_name, context); return instance; } }; /**