hi all.
I''m currently writing an article about the crawling the aculo.us
codes, especially about effects.js.
I wonder why the following codes of Effect.Base needs a dynamic
evaluation.
function codeForEvent(options,eventName){
return (
(options[eventName+''Internal''] ?
''this.options.''+eventName
+''Internal(this);'' : '''') +
(options[eventName] ?
''this.options.''+eventName+''(this);'' :
'''')
);
}
eval(''this.render = function(pos){ ''+
''if
(this.state=="idle"){this.state="running";''+
codeForEvent(this.options,''beforeSetup'')+
(this.setup ? ''this.setup();'':'''')+
codeForEvent(this.options,''afterSetup'')+
''};if (this.state=="running"){''+
''pos=this.options.transition(pos)*''+this.fromToDelta
+''+''+this.options.from+'';''+
''this.position=pos;''+
codeForEvent(this.options,''beforeUpdate'')+
(this.update ? ''this.update(pos);'':'''')+
codeForEvent(this.options,''afterUpdate'')+
''}}'');
Why it can''t be replaced to the followings? I saw that unit and
functinal tests are the all-green.
this.render = function(pos){
if (this.state=="idle"){
this.state="running";
this.event(''beforeSetup'');
if (this.setup) this.setup();
this.event(''afterSetup'');
};
if (this.state=="running"){
pos=this.options.transition(pos)* this.fromToDelta +
this.options.from;
this.position=pos;
this.event(''beforeUpdate'');
if (this.update) this.update(pos);
this.event(''afterUpdate'');
}
};
The codeForEvent and eval was firstly introduced at rev 6236.
http://dev.rubyonrails.org/changeset/6236/spinoffs/scriptaculous/src/effects.js
Its log message is "Various effects engine optimizations", but it is
not clear why this eval was used.
Any help will be appreciated.
Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---
Tobie Langel
2008-Feb-15 01:01 UTC
Re: please explain about effects.js''s codeForEvent and eval
Hi, That was for speed optimization. Basically the idea is that by trading the cost of one call to eval upon instanciation, you save the cost of a number of if clauses on each frame update which turns out to be a serious perf boost. Hope this helps. Best, Tobie On Feb 15, 1:14 am, Gemma <teruakige...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi all. > I''m currently writing an article about the crawling the aculo.us > codes, especially about effects.js. > I wonder why the following codes of Effect.Base needs a dynamic > evaluation. > > function codeForEvent(options,eventName){ > return ( > (options[eventName+''Internal''] ? ''this.options.''+eventName > +''Internal(this);'' : '''') + > (options[eventName] ? ''this.options.''+eventName+''(this);'' : '''') > );} > > eval(''this.render = function(pos){ ''+ > ''if (this.state=="idle"){this.state="running";''+ > codeForEvent(this.options,''beforeSetup'')+ > (this.setup ? ''this.setup();'':'''')+ > codeForEvent(this.options,''afterSetup'')+ > ''};if (this.state=="running"){''+ > ''pos=this.options.transition(pos)*''+this.fromToDelta > +''+''+this.options.from+'';''+ > ''this.position=pos;''+ > codeForEvent(this.options,''beforeUpdate'')+ > (this.update ? ''this.update(pos);'':'''')+ > codeForEvent(this.options,''afterUpdate'')+ > ''}}''); > > Why it can''t be replaced to the followings? I saw that unit and > functinal tests are the all-green. > > this.render = function(pos){ > if (this.state=="idle"){ > this.state="running"; > this.event(''beforeSetup''); > if (this.setup) this.setup(); > this.event(''afterSetup''); > }; > if (this.state=="running"){ > pos=this.options.transition(pos)* this.fromToDelta + > this.options.from; > this.position=pos; > this.event(''beforeUpdate''); > if (this.update) this.update(pos); > this.event(''afterUpdate''); > } > }; > > The codeForEvent and eval was firstly introduced at rev 6236.http://dev.rubyonrails.org/changeset/6236/spinoffs/scriptaculous/src/... > Its log message is "Various effects engine optimizations", but it is > not clear why this eval was used. > > Any help will be appreciated. > Thanks.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you for replying to my question so quickly. And now I think I understand what the codes meant by that. I very much appreciate this answer. Best regards, Gemma --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---