Last active
June 27, 2016 14:59
-
-
Save baumandm/7f339a4064ef59b17c9fba5da9bc073b to your computer and use it in GitHub Desktop.
Revisions
-
baumandm revised this gist
Jun 27, 2016 . 1 changed file with 2 additions and 0 deletions.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 @@ -1,3 +1,5 @@ # Cyclotron: JavaScript Data Source to execute and merge two Data Sources together This is a JavaScript Data Source which executes two other data sources, and merges their results together based on some key. Since Widgets can only use a single Data Source at once, this is the solution for combining Data Sources. Note: both datasource0 and datasource1 need to have "preload": true and "deferred": true, so that .execute() can be called. -
baumandm revised this gist
Jun 27, 2016 . 1 changed file with 32 additions and 32 deletions.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 @@ -3,36 +3,36 @@ This is a JavaScript Data Source which executes two other data sources, and merg Note: both datasource0 and datasource1 need to have "preload": true and "deferred": true, so that .execute() can be called. Processor: p = function (promise) { /* Execute two data sources simultaneously */ var p1 = Cyclotron.dataSources['datasource0'].execute(true); var p2 = Cyclotron.dataSources['datasource1'].execute(true); /* Wait for the first data source to complete */ p1.then(function (result) { var r1 = result['0'].data; /* Wait for the second data source to complete */ p2.then(function (result) { var r2 = result['0'].data; /* Join on shared key */ var merged = _.map(r1, function(row1) { var row2 = _.find(r2, { key: row1.key }); return _.merge(_.clone(row1), row2); }); /* Resolve promise with merged row */ promise.resolve(merged); }); }); /* Catch errors and reject promise, so errors appear in the Widget */ p1.catch(function (err) { promise.reject(err); }); p2.catch(function (err) { promise.reject(err); }); /* Return nothing, so Cyclotron will wait for promise to resolve */ } -
baumandm renamed this gist
Jun 27, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
baumandm created this gist
Jun 27, 2016 .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,38 @@ This is a JavaScript Data Source which executes two other data sources, and merges their results together based on some key. Since Widgets can only use a single Data Source at once, this is the solution for combining Data Sources. Note: both datasource0 and datasource1 need to have "preload": true and "deferred": true, so that .execute() can be called. Processor: p = function (promise) { /* Execute two data sources simultaneously */ var p1 = Cyclotron.dataSources['datasource0'].execute(true); var p2 = Cyclotron.dataSources['datasource1'].execute(true); /* Wait for the first data source to complete */ p1.then(function (result) { var r1 = result['0'].data; /* Wait for the second data source to complete */ p2.then(function (result) { var r2 = result['0'].data; /* Join on shared key */ var merged = _.map(r1, function(row1) { var row2 = _.find(r2, { key: row1.key }); return _.merge(_.clone(row1), row2); }); /* Resolve promise with merged row */ promise.resolve(merged); }); }); /* Catch errors and reject promise, so errors appear in the Widget */ p1.catch(function (err) { promise.reject(err); }); p2.catch(function (err) { promise.reject(err); }); /* Return nothing, so Cyclotron will wait for promise to resolve */ }