Skip to content

Instantly share code, notes, and snippets.

@jensarps
jensarps / promise.js
Created February 4, 2010 23:53
Micro Promise implementation
dojox.Promise = function(){
return {
emit: function(data){ // stub function
},
then: function(doneHandler,errHandler){
var promise = new dojox.Promise();
dojo.connect(this, 'emit', function(data){
if(doneHandler && !(data instanceof Error)){
@jensarps
jensarps / embedjs-nodecreation.js
Created September 16, 2011 08:55
EmbedJS code examples
// DOM node creation quick'n'easy:
var containerNode = embed.create('div', {
className: 'container box',
innerHTML: '<span>Huh, a container!</span>',
style: {
border: 'solid red 1px'
}
}, parentNode);
@jensarps
jensarps / requiring_features.js
Created October 1, 2011 10:13
Using features
define(['feature!async-promise'],function(embed){
// Now you have embed.Promise available!
})
// All features return the same object, so that you
// can do the following:
define(['feature!async-promise', 'feature!html-element'], function(embed){
// All methods provided by the html-element feature are now
// available in the object returned by the async-promise feature,
@jensarps
jensarps / requirejs_config.html
Created October 1, 2011 12:00
Including and configuring RequireJS
<script>
var require = {
baseUrl: 'src/', // all other paths are now relative to this one
paths: {
'implementations': 'platforms/unknown'
}
};
</script>
<script type="text/javascript" src="src/require.js"></script>
@jensarps
jensarps / index.html
Created November 24, 2011 14:13
IDBWrapper tutorial, step 1
<!DOCTYPE html>
<html>
<head>
<title>IDBWrapper Tutorial, Step 1</title>
</head>
<body>
<script type="text/javascript" src="IDBStore.js"></script>
<script type="text/javascript" src="tutorial.js"></script>
</body>
</html>
@jensarps
jensarps / turorial.js
Created November 24, 2011 14:41
IDBWrapper tutorial, step 2
var dude = {
firstname: 'John',
lastname: 'Doe',
age: 52,
emails: [
'[email protected]',
'[email protected]'
]
};
@jensarps
jensarps / tutorial.js
Created November 24, 2011 14:54
IDBWrapper tutorial, step 3
var id = 1; // Or whatever you got returned.
var onsuccess = function(data){
console.log('here is our dude:', data);
}
var onerror = function(error){
console.log('Oh noes, sth went wrong!', error);
}
customers.get(id, onsuccess, onerror);
@jensarps
jensarps / turorial.js
Created November 25, 2011 10:28
IDBWrapper tutorial, step 4
var updatedDude = {
id: 1, // or whatever id our dude has
firstname: 'John',
lastname: 'Doe',
age: 53, // dude is now a year older
emails: [
'[email protected]',
'[email protected]'
]
};
@jensarps
jensarps / tutorial.js
Created November 25, 2011 10:53
IDBWrapper tutorial, step 5
var onsuccess = function(data){
console.log('Here is what we have in store ('+data.length+' items in total):');
data.forEach(function(item){
console.log(item);
});
}
var onerror = function(error){
console.log('Oh noes, sth went wrong!', error);
}
@jensarps
jensarps / tutorial.js
Created November 25, 2011 11:06
IDBWrapper tutorial, step 6
var id = 1;
var onsuccess = function(result){
if(result !== false){
console.log('deletion successful!');
}
}
var onerror = function(error){
console.log('Oh noes, sth went wrong!', error);
}