<div class="gmail_quote">On Fri, Aug 21, 2009 at 6:37 AM, Patrick Mueller <span dir="ltr"><<a href="mailto:pmuellr@muellerware.org">pmuellr@muellerware.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Patrick Mueller wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Time to work on some examples. This would relatively easy to prototype in something like Rhino (or my nitro_pie python wrapper for JavaScriptCore), at least API wise, so we could see what the user-land code would look like, and see it run.<br>
</blockquote>
<br>
I developed a simulator for this yesterday. My big take away is that the current shape leaves users in a batteries-not-included state.<br>
<br>
Here's the kind of code I had to write to arrange to create a new scope and load a single script in it from multiple windows. Each window would run this code in it's own context.<br>
<br>
function loadLibrary(scopeName, script, callback) {<br>
var scope = getSharedScope(scopeName);<br>
<br>
// script already loaded in the scope<br>
if (scope.__loaded) {<br>
callback(scope, scope.__callback_data);<br>
}<br>
<br>
// script not yet done loading<br>
else if (scope.__loading) {<br>
scope.__onLoadedListeners.push(callback);<br>
}<br>
<br>
// first one in! much work to do ...<br>
else {<br>
scope.__loading = true;<br>
scope.__onLoadedListeners = [];<br>
<br>
function handler(callback_data) {<br>
<br>
scope.__loaded = true;<br>
scope.__loading = false;<br>
scope.__callback_data = callback_data;<br>
<br>
callback(scope, callback_data);<br>
for (var i=0; i<scope.__onLoadedListeners.length; i++) {<br>
scope.__onLoadedListeners[i](scope, callback_data);<br>
}<br>
}<br>
<br>
scope.runScript(script, {handler: handler});<br>
}<br>
<br>
return scope;<br>
}<br>
<br>
I changed the GlobalScript() constructor to a getSharedScope() function (at the top), and the load() function to a runScript() function which takes parameters including a callback function.<br>
<br>
I'm of two minds here.<br>
<br>
One is that the SharedScope proposal is really only appropriate for pages with lots of JavaScript that could be shared, or special use cases where you want (eventually) easy sharing between windows. As such, s smallish amount of JS framework-y-ness like this isn't a show stopper. In fact, as spec'd, separating out the scope and script loading, will let folks build mini-frameworks for themselves fairly easily, customized to their own needs.<br>
<br>
On the other hand, I wonder about the potential benefits of letting more people play in the space easier. The securable module work in the serverjs projects it a bit easier to use out of the box. I'm not sure they have an async story though, and async loading of scripts is where this stuff quickly gets complicated.</blockquote>
<div><br></div><div>For a feature of this scope, I think it's much better to keep the API surface area as low as is possible for the first version. If, out of the frameworks, emerges a clear winner, then we should talk about expanding the API. Until then, I worry we'll just be speculating/bike-shedding.</div>
<div><br></div><div>Thanks for doing this, btw!</div><div><br></div><div>J</div></div>