update plugin promise docs

This commit is contained in:
guybedford 2013-12-29 18:34:12 +02:00
parent e8b34920af
commit 1bbdec33e7
2 changed files with 25 additions and 18 deletions

View File

@ -392,16 +392,19 @@ js/css.js:
```javascript
exports.fetch = function(load) {
// return a thenable for fetching (as per specification)
return new Promise(function(resolve, reject) {
var cssFile = load.address;
// alternatively return new Promise(function(resolve, reject))
return {
then: function(resolve, reject) {
var cssFile = load.address;
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = cssFile;
link.onload = resolve;
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = cssFile;
link.onload = resolve;
document.head.appendChild(link);
});
document.head.appendChild(link);
}
};
}
```

View File

@ -1,17 +1,21 @@
exports.locate = function(load) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve('custom fetch');
}, 20);
});
return {
then: function(resolve, reject) {
setTimeout(function() {
resolve('custom fetch');
}, 20);
}
};
}
exports.fetch = function(load) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(load.address);
}, 20);
});
return {
then: function(resolve, reject) {
setTimeout(function() {
resolve(load.address);
}, 20);
}
}
}
exports.translate = function(load) {