stdlib.behavior.EnterKeyBehavior 1.1.4 -- incomplete?

3 views
Skip to first unread message

Aaron Drake

unread,
Jun 28, 2010, 11:23:21 AM6/28/10
to Blast Mojo
I am working with version 1.1.4 or Mojo, and have just begun to
familiarize myself with the code. There is a class in stdlib that
appears to be incomplete.

Am I missing an approach to setting the onResponse method? Otherwise,
I'm not sure what the purpose of this behavior is. Here's the key
lines of code in that file:

execute: function(requestObj) {
var e = requestObj.eventObj;
var characterCode;
if(e && e.which){
e = e
characterCode = e.which;
} else{
e = event
characterCode = e.keyCode;
}
if(characterCode == 13){
this.onResponse();
return false
} else{
return true
}
},
onResponse: function() {
}
});

Jaime Bueza

unread,
Jun 28, 2010, 11:32:08 AM6/28/10
to blast...@googlegroups.com
Hey Aaron,

keyCode 13 is the Enter key. So, in your controller, you can do this:

this.addObserver(this.getContextElement(), "onkeyup", "EnterKey");
this.addObserver(this.getCommand("EnterKey"), "onResponse",
"MyCustomCommand", { } );

As you can see above, we're observing the EnterKey behavior for when
onResponse fires and then executing your "MyCustomCommand".

Hope this clears up some things about chaining and observing commands,
Jaime Bueza

Aaron Drake

unread,
Jun 28, 2010, 11:53:31 AM6/28/10
to blast...@googlegroups.com
Thanks, but could you clarify one point? In your sample code, I assume
there is also an unwritten step where, after assigning those observers
below: after including the addObserver calls, we then point the
'EnterKey' command to the EnterKeyBehavior class in stdlib via the
addCommands method:

this.addCommand("EnterKey", "stdlib.behavior.EnterKeyBehavior");

Correct?

Jaime Bueza

unread,
Jun 28, 2010, 12:18:05 PM6/28/10
to blast...@googlegroups.com
this.addCommand only adds "a command" to the Controller's command registry:

http://blastmojo.com/docs/files/controller/Controller-js.html#Controller.addCommand

the whole "addCommands: function()" block gets invoked when the
current Controller gets mapped (when the application gets
boostrapped). This should really be drawn out, but I'll give it a
shot:

1) Browser interprets SiteMap.js
2) Iterate through each item in the SiteMap and map controllers
according to their specified context
3) When instantiating a Controller, we add specific Commands that the
Controller will be using (addCommands())
4) After adding commands to the Controller, we apply its business
logic (addObservers() + addIntercepts())
5) After all Controllers are mapped, the application is ready for the
User to interact with the application

Diving deeper into the architecture of Mojo, the relationship between
commands/behaviors (behaviors are just commands except they are
defined by manipulating the UI instead of consuming a data provider)
and controllers are:

1) Controllers can use multiple Commands (Command, Behavior, Rule --
These are all types of Commands)
2) Commands can be associated to multiple Controllers (By parameterization)
3) Controllers and Commands are reusable in that everything can be
parameterized (FilmStripController, TweenBehavior,
GenericServiceCommand)

Going back to the example I wrote and clarifying on the point of
chaining or observing command instances, "EnterKey" is just a
reference as I believe that Controllers have a Hash map of all
commands in its registry. You could actually name it anything you
want:

this.addCommand("HelloThereBehavior", "stdlib.behavior.EnterKeyBehavior");

and then reference it in:

this.addObserver(this.getContextElement, "onkeyup", "HelloThereBehavior");

Hope this helps,
Jaime

PS: I think I'm going to get yelled at for saying "registry" in this
email, as that's a very Windows-like term, but provides the best
illustration of the idea.

Reply all
Reply to author
Forward
0 new messages