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 <[EMAIL PROTECTED]> 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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---