Hi, playing around and reading examples from web about Controller functionallity I've found that there are multiple ways to initialize event listeners, so I would like to know what is the RECOMMENDED way of doing this.
In my opinion this seems....ugly. And I have to use another code pile to use Event Domains, which is extra:
2.) Use config->control option:
In my opinion this seems much prettier - more readable and less code pile, BUT again to use Event Domains we need to use previous example or listen config (see next example).
This seems like the most logical solution, because we have a CONSISTENT way of defining event listeners for components and Event Domains. If we wouldn't use Event Domains, then the 2nd example would probably be better, because of less code, but anyway this is a more consistent way in case we use them later.
This seems really logical, because it craetes a consisten way of doing something and will make less confusions between developers. I know its harder to be done in Javascript, but it would be awesome if in official documentation there was a RECOMMENDED flag.
1.) In official documentation seems like this way is used all the time:
Code:
init: function() {
this.control({
'viewport > panel': {
render: this.onPanelRendered
}
});
}
In my opinion this seems....ugly. And I have to use another code pile to use Event Domains, which is extra:
Code:
this.listen({
controller: {
'#foo': {
bar: this.onFooBar
}
}
});
2.) Use config->control option:
Code:
config : {
control: {
'viewport > panel': {
render: this.onPanelRendered
}
}
},
In my opinion this seems much prettier - more readable and less code pile, BUT again to use Event Domains we need to use previous example or listen config (see next example).
3.) Use config->listen option:
Code:
config : {
listen : {
component: {
'viewport > panel': {
render: this.onPanelRendered
}
},
controller : {
'#foo': {
bar: this.onFooBar
}
}
}
},
This seems like the most logical solution, because we have a CONSISTENT way of defining event listeners for components and Event Domains. If we wouldn't use Event Domains, then the 2nd example would probably be better, because of less code, but anyway this is a more consistent way in case we use them later.
So the main question is - which is the most recommended way of defining event listeners. For me it seems like 3rd solution, but in documentation the 1st one is used. Does it give a better abstraction?
I am also Python programmer and one of their main Zen is:
There should be one-- and preferably only one --obvious way to do it.
This seems really logical, because it craetes a consisten way of doing something and will make less confusions between developers. I know its harder to be done in Javascript, but it would be awesome if in official documentation there was a RECOMMENDED flag.
Aucun commentaire:
Enregistrer un commentaire