Last active
August 29, 2015 14:02
-
-
Save matthewrobb/98bac8c935e606e1a7a5 to your computer and use it in GitHub Desktop.
Proposal for a more performant es5 target for es6 module transpilers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { readFile, readDir } from "fs"; | |
export function mkdir() { | |
// do stuff with readFile & readDir | |
} | |
export var count; | |
for(count = 0; count < 100;) { | |
console.log(count++); // 0...99 | |
} | |
for(count = 0; count < 100;) { | |
console.log(++count); // 1...100 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
System.register("shelly", [ "fs" ], function(bindings) { | |
// import identifiers and non-function/non-class export identifiers gets hoisted | |
var readFile, readDir, count; | |
// Get live updates for the imported value | |
bindings.import("readFile", function(newVal) { readFile = newVal }); | |
// note: need to do a pull for the initial value when this is called | |
bindings.import("readDir", function(newVal) { readDir = newVal }); | |
// For functions and classes things just work... | |
bindings.export("mkdir", function() { return mkdir }); | |
function mkdir() {} | |
// initial export is immediately called to push out to any subscribers | |
bindings.export("count", function() { return count }); | |
for(count = 0; count < 100;) { | |
// push out the changes and return the second argument | |
console.log(bindings.push("count", count++)); // 0...99 | |
} | |
for(count = 0; count < 100;) { | |
// by returning the second argument you get expected semantics | |
console.log(bindings.push("count", ++count)); // 1...100 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment