Skip to content

Instantly share code, notes, and snippets.

View lukehoban's full-sized avatar

Luke Hoban lukehoban

View GitHub Profile
// Spawn function inspired by Q.async at http://wiki.ecmascript.org/doku.php?id=strawman:async_functions#reference_implementation
// Takes an ES6 generator function and produces a WinJS.Promise
function spawn(generatorFunc) {
return new WinJS.Promise(function (c, e) {
var generator = generatorFunc();
var callback = continuer.bind(void 0, 'send');
var errback = continuer.bind(void 0, 'throw');
function continuer(verb, valueOrErr) {
var promisedValue;
@lukehoban
lukehoban / gist:4093199
Created November 17, 2012 04:06
Creating a Blob from a Windows IBuffer or RandomAccesStream
// If you are starting with a file from a picker, something like this should work:
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.fileTypeFilter.replaceAll(['.jpg', '.jpeg']);
picker.pickSingleFileAsync().then(function (file) {
return file.openAsync(Windows.Storage.FileAccessMode.read);
}).done(function (ras) {
var blob = MSApp.createBlobFromRandomAccessStream('image/jpeg', ras);
@lukehoban
lukehoban / gist:3900992
Created October 16, 2012 18:11
ES6 module syntax alternatives
Things I want to be able to do:
a) Bind a name to a remote module
b) Alias a name for a module
c) Alias a name for a member of a remote module
d) Put all names from inside a module in lexical scope
e) Put all names from inside a remote module in lexical scope
f) Put a few names from inside a module in lexical scope
g) Define a local module
h) Export names from lexical scope
i) Re-export names from other modules
@lukehoban
lukehoban / gist:3137947
Created July 18, 2012 18:33
const questions
//#1
// Current spec would suggest that this is an early error during compilation of the main code.
// However, dynamically, the "x=20" will write to the "var x" declared inside g.
// This is a case where the early error for assignments to const variables appears to overreach, flagging an error which will not actually occur if the code were allowed to run.
function f() {
const x = 5;
function g() {
eval(“var x = 10”);
x = 20;
}
@lukehoban
lukehoban / gist:2246758
Created March 30, 2012 05:17
ES6 module loader API polyfill experiment
(function (global) {
// TODO: Delegate to parent loader in various places
// TODO: Canonicalization
// TODO: Can we do better for 'eval'?
/// Module loader constructor
function Loader(parent, options) {
// Initialization of loader state from options
@lukehoban
lukehoban / gist:1625486
Created January 17, 2012 07:40
AMD using ES6 module loaders
/*
// The default system module loader exposed by ES6 on the
// global object.
Object.system = {
load: function(name, callback, errback) {
// ...
},
loaded: {}
}
*/