Skip to content

Commit efa450e

Browse files
committed
feat(loki): add 'dataOptions' to eqJoin (#33)
Add additional 'dataOptions' parameter to Resultset eqjoin and transform eqJoin step operations to allow removing meta from both left and right sides. This is meant for easier grafting into single object to be inserted into the eqJoin (temporary) collection. (from techfort/LokiJS#618)
1 parent 745e025 commit efa450e

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

packages/loki/src/resultset.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ export class Resultset {
445445
rs = rs.map(step.value);
446446
break;
447447
case "eqJoin":
448-
rs = rs.eqJoin(step.joinData, step.leftJoinKey, step.rightJoinKey, step.mapFun);
448+
rs = rs.eqJoin(step.joinData, step.leftJoinKey, step.rightJoinKey, step.mapFun, step.dataOptions);
449449
break;
450450
// following cases break chain by returning array data so make any of these last in transform steps
451451
case "mapReduce":
@@ -1125,13 +1125,14 @@ export class Resultset {
11251125
/**
11261126
* eqJoin() - Left joining two sets of data. Join keys can be defined or calculated properties
11271127
* eqJoin expects the right join key values to be unique. Otherwise left data will be joined on the last joinData object with that key
1128-
* @param {Array} joinData - Data array to join to.
1128+
* @param {Array|Resultset|Collection} joinData - Data array to join to.
11291129
* @param {(string|function)} leftJoinKey - Property name in this result set to join on or a function to produce a value to join on
11301130
* @param {(string|function)} rightJoinKey - Property name in the joinData to join on or a function to produce a value to join on
11311131
* @param {function} [mapFun=] - a function that receives each matching pair and maps them into output objects - function(left,right){return joinedObject}
1132+
* @param {object} dataOptions - optional options to apply to data() calls for left and right sides
11321133
* @returns {Resultset} A resultset with data in the format [{left: leftObj, right: rightObj}]
11331134
*/
1134-
eqJoin(joinData, leftJoinKey, rightJoinKey, mapFun) {
1135+
eqJoin(joinData, leftJoinKey, rightJoinKey, mapFun, dataOptions) {
11351136
let leftData = [];
11361137
let leftDataLength;
11371138
let rightData = [];
@@ -1143,12 +1144,14 @@ export class Resultset {
11431144
let joinMap = {};
11441145

11451146
//get the left data
1146-
leftData = this.data();
1147+
leftData = this.data(dataOptions);
11471148
leftDataLength = leftData.length;
11481149

11491150
//get the right data
1150-
if (joinData instanceof Resultset) {
1151-
rightData = joinData.data();
1151+
if (joinData instanceof Collection) {
1152+
rightData = joinData.chain().data(dataOptions);
1153+
} else if (joinData instanceof Resultset) {
1154+
rightData = joinData.data(dataOptions);
11521155
} else if (Array.isArray(joinData)) {
11531156
rightData = joinData;
11541157
} else {

0 commit comments

Comments
 (0)