You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: this is about the methods beforeBinding, onBinding and afterBinding.
During daily use of Terrific I often found it somewhat tedious to have to write some patterns over and over again. I'm talking about the following: var self = this and $(selector, this.$ctx)
The first is needed to access the module instance inside closures (callbacks) that have a different scope than the surrounding method. The second pattern is used for efficiency in order to query only the module contents instead of the whole document.
I'm proposing changing the signature of those methods like this:
beforeBinding: function(self,$$,callback){callback();},onBinding: function(self,$$){// Examples...var$nav=$$('nav');// shortcut for $('nav').find('nav') OR $('nav', this.$ctx);$nav.find('li').each(function(){// In here 'this' is a li. Without 'self' we have no reference to the Module (unless we stored it in a var).// (I don't like 'that').self.doSomethingWithNavLi(this);});},doSomethingWithNavLi: function(li){// doing somethingreturntrue;},afterBinding: function(self,$$){}
I'm aware that this disturbs the beauty of the API, eg. when using JS skins , but in my experience the convenience of not having to repeat my self all the time trumps the aesthetic consideration.
About self... It's certainly not beautiful to pass the Module instance into the method as a param, but it makes the subsequent coding inside jQuery closures hassle-free. I chose self because it reminds me of the way we can reference a static class in PHP, and because I never liked that. But If you dont want to implement this I won't cry. :)
The second param $$ is more important to me... It would just be so handy to have this. We have to select some child of a module so often, that I think this really makes sense.
I'll say again that this is a very pragmatic proposal, more geared towards daily use than aesthetics. But I really think it has some merit! (And so do my co-workers.) I have the necessary changes to Tc.module.js in a local branch that I can push if you like...
The text was updated successfully, but these errors were encountered:
I really thought long about your proposal above. Although I agree that it would add convenience for some of us, the disturbing of the beauty of the API weights heavier – at least in my opinion. Especially when it comes to Skins and the call of parent methods.
Due to this, I tried to solve your proposal by using a form of currying that does disturb the API. Unfortunately without success – at least so far :-(
Therefore I suggest to postpone this task in favor of aesthetics and implement it as soon we come up with a 'less immersive' solution.
What do you think?
btw: your explanation above has lead me to change that to self in the core and the examples ;-)
Note: this is about the methods beforeBinding, onBinding and afterBinding.
During daily use of Terrific I often found it somewhat tedious to have to write some patterns over and over again. I'm talking about the following:
var self = this
and$(selector, this.$ctx)
The first is needed to access the module instance inside closures (callbacks) that have a different scope than the surrounding method. The second pattern is used for efficiency in order to query only the module contents instead of the whole document.
I'm proposing changing the signature of those methods like this:
I'm aware that this disturbs the beauty of the API, eg. when using JS skins , but in my experience the convenience of not having to repeat my self all the time trumps the aesthetic consideration.
About
self
... It's certainly not beautiful to pass the Module instance into the method as a param, but it makes the subsequent coding inside jQuery closures hassle-free. I choseself
because it reminds me of the way we can reference a static class in PHP, and because I never likedthat
. But If you dont want to implement this I won't cry. :)The second param
$$
is more important to me... It would just be so handy to have this. We have to select some child of a module so often, that I think this really makes sense.I'll say again that this is a very pragmatic proposal, more geared towards daily use than aesthetics. But I really think it has some merit! (And so do my co-workers.) I have the necessary changes to Tc.module.js in a local branch that I can push if you like...
The text was updated successfully, but these errors were encountered: