Created
April 28, 2013 18:01
-
-
Save dlongley/5477752 to your computer and use it in GitHub Desktop.
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
/* Begin node.js Style */ | |
playground.performAction = function(input, callback) { | |
var processor = new jsonld.JsonLdProcessor(); | |
if(playground.activeTab === 'tab-compacted') { | |
processor.compact(input, function(err, compacted) { | |
if(err) { | |
return callback(err); | |
} | |
// TODO: update UI with 'compacted output | |
callback(); | |
} | |
} | |
else ... | |
}; | |
playground.performAction({}, function(err) { | |
if(err) { | |
// TODO: display errors | |
return; | |
} | |
// TODO: update UI, etc. | |
}); | |
/* End node.js Style */ | |
/* Begin Futures Style */ | |
playground.performAction = function(input) { | |
return new Future(function(resolver) { | |
var processor = new jsonld.JsonLdProcessor(); | |
if(playground.activeTab === 'tab-compacted') { | |
processor.compact(input).done(function(compacted) { | |
// TODO: update UI with 'compacted' output | |
resolver.resolve(); | |
}, resolver.reject); | |
} | |
else ... | |
}; | |
}; | |
playground.performAction({}).done( | |
function() { | |
// TODO: update UI, etc. | |
}, | |
function(err) { | |
// TODO: display errors | |
} | |
}); | |
/* End Futures Style */ | |
/* Begin ES6 "Thenables" Style */ | |
playground.performAction = function(input) { | |
return {then: function(success) { | |
var processor = new jsonld.JsonLdProcessor(); | |
if(playground.activeTab === 'tab-compacted') { | |
var compacted = yield processor.compact(input); | |
// TODO: update UI with 'compacted' output | |
success(); | |
} | |
else ... | |
}; | |
}; | |
try { | |
yield playground.performAction({}); | |
// TODO: update UI, etc. | |
} | |
catch(e) { | |
// TODO: display errors | |
} | |
/* End ES6 "Thenables" Style */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment