redo mode

To show the effect of the redo mode, change a little the scripts already used in the Basic Example.

test it now

script:

Goon( "goon/1.1/redo/", "script.js",
{
	scr1: "script1.js",
	scr2: { file: "script2.js", mode: "exec" }
},
function() { 
	alert( "script" );

	var a = this.scr1.value;
	var b = this.scr2.value;
	var c = b - a;

	return { n1: a, n2: b, diff: c };
} );

main:

Goon( "goon/1.1/redo/", "main.js",
{ 
	scr: {file:"script.js", mode:"redo"}
}, 
function() { 
	alert( "main" );

	var msg = 'lap( ' 
		+ this.scr.n1.valueOf() + ', ' 
		+ this.scr.n2.valueOf() + ' ) = ' 
		+ this.scr.diff;

	return {msg: msg};
} );

page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title> redo test </title>
<script type="text/javascript" src="goon-1.1.pack.js?base=http://noteslog.com/personal/projects/" id="g8n"></script>
<script type="text/javascript" src="redo/script.js"></script>
<script type="text/javascript" src="redo/main.js"></script>
</head>
<body>
<p><a href="javascript:alert( 
goon['http://noteslog.com/personal/projects/goon/1.1/redo/main.js']
.exported.msg 
);">test goon</a></p>
<p><a href="javascript:alert( 
goony.msg
);">test goony</a></p>
</body>
</html>

If you open the above page in a browser, you’ll see an alert when each local script is being executed. The expected sequence is “script1”, “script2”, “script”, “script2”, “script”, “main”.

Here the first script hierarchy is alerted because it’s directly loaded into the page, the second “script2” on the other hand is alerted because it’s required by script, which is required by main, which is directly loaded into the page.

redo.png

redo2.png

As you see, script has been loaded twice because it’s required in redo mode by main, and its children are exporting times according to their respective modes: for script1 the mode is link (default), and for script2 it is exec. So, both script1‘s entries in the goon repository export the same time, while script2‘s entries export different times.

Priorities

An interesting observation about the above picture: in the first script entry, exported.diff is negative. This is not the result of a bug, because script requires script1 and script2 “in parallel”, so script1 will be executed before script2 mostly (because it is declared before), but not always.

In Goon 1.0, to guarantee that script1 is executed always before script2, the setup must be different: main( script( script2( script1() ) ) ) instead of main( script( script1(), script2() ) ), thus making script2 require script1, even if script2 does not need script1 to work…

With priorities implemented, it will be possible to specify something like the above expression, right where it belongs, i.e. inside script. Goon will support priorities in the future.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.