Created
June 9, 2017 09:27
-
-
Save thenoseman/ad2d92d79b547e3f3617107adac1197e to your computer and use it in GitHub Desktop.
Form-O-Fill example : Using multiple context.findHtml() calls in before functions
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
var rules = [{ | |
"name": "Fetching multiple thing from the content page with context.findHtml", | |
"url": "https://scotch.io/tutorials/javascript-promises-for-dummies", | |
"before": function(resolve, context) { | |
// Lets fetch two headlines from the page | |
// 1. Generate an array of Promises. | |
var promises = [ | |
context.findHtml("#toc-understanding-promises"), | |
context.findHtml("#toc-creating-a-promise") | |
]; | |
// Promise.all will resolve when ALL promises in the argument are resolved | |
// You'll get an array in the .then() function containing one element per promise. | |
Promise.all(promises).then(function(dataFromAllPromises) { | |
// dataFromAllPromises[0] = result of context.findHtml("#toc-understanding-promises") | |
// dataFromAllPromises[1] = result of context.findHtml("#toc-creating-a-promise") | |
// Now transform the data (eg. remove tags) and resolve the "before" function to | |
// make the data available in value functions. | |
resolve(dataFromAllPromises); | |
}); | |
}, | |
"fields": [{ | |
"selector": "#aa-search-input", | |
"value": function($domElement, dataFrombeforeFunction) { | |
return "#toc-understanding-promises : " + dataFrombeforeFunction[0] + " #toc-creating-a-promise : " + dataFrombeforeFunction[1]; | |
} | |
}] | |
} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment