Skip to content

Instantly share code, notes, and snippets.

@matthewrobb
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewrobb/98bac8c935e606e1a7a5 to your computer and use it in GitHub Desktop.
Save matthewrobb/98bac8c935e606e1a7a5 to your computer and use it in GitHub Desktop.
Proposal for a more performant es5 target for es6 module transpilers
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
}
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