Created
June 9, 2017 09:27
-
-
Save thenoseman/ad2d92d79b547e3f3617107adac1197e to your computer and use it in GitHub Desktop.
Revisions
-
thenoseman created this gist
Jun 9, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ 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]; } }] } ];