Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | 33x 33x 25x 25x 6x 2x 6x 6x 2x 6x 6x 2x 6x 7x 1x 1x 7x 8x 9x 8x 8x | /* eslint-disable default-case */
import { DM_DERIVATIVES } from '../constants';
/**
* iterate the children and call the callback for each
*
* @param {DataModel} datamodel
* @param {function} callback
* @param {DM_DERIVATIVES} operation
*/
function childIterator (datamodel, callback, operation) {
const children = datamodel._children;
children.forEach((child) => {
Eif (child._derivation
&& child._derivation.length === 1) {
switch (operation) {
case DM_DERIVATIVES.SELECT:
if (child._derivation[0].op === DM_DERIVATIVES.SELECT) {
callback(child, child._derivation[0].criteria);
}
break;
case DM_DERIVATIVES.PROJECT:
if (child._derivation[0].op === DM_DERIVATIVES.PROJECT) {
callback(child, child._derivation[0].meta.actualProjField);
}
break;
case DM_DERIVATIVES.GROUPBY:
if (child._derivation[0].op === DM_DERIVATIVES.GROUPBY) {
callback(child,
{ groupByString: child._derivation[0].meta.groupByString,
reducer: child._derivation[0].criteria });
}
break;
case DM_DERIVATIVES.CAL_VAR:
if (child._derivation[0].op === DM_DERIVATIVES.CAL_VAR) {
let params = [child._derivation[0].meta.config, [child._derivation[0].meta.fields,
child._derivation[0].criteria]];
callback(child, ...params);
}
break;
}
}
});
}
/**
* Invokes a callback for every child created by a selection operation on a DataModel.
*
* @param {DataModel} datamodel - The input DataModel instance.
* @param {Function} callback - The callback to be invoked on each child. The parameters
* provided to the callback are the child DataModel instance and the selection
* function used to create it.
*/
export function selectIterator (datamodel, callback) {
childIterator(datamodel, callback, DM_DERIVATIVES.SELECT);
}
/**
* Invokes a callback for every measure child of a DataModel.
*
* @param {DataModel} datamodel - The input DataModel instance.
* @param {Function} callback - The callback to be invoked on each measure child. The parameters
* provided to the callback are the child DataModel instance and the child params.
*/
export function calculatedVariableIterator (datamodel, callback) {
childIterator(datamodel, callback, DM_DERIVATIVES.CAL_VAR);
}
/**
* Invokes a callback for every projected child of a DataModel.
*
* @param {DataModel} datamodel - The input DataModel instance.
* @param {Function} callback - The callback to be invoked on each projected child. The parameters
* provided to the callback are the child DataModel instance and the
* projection string.
*/
export function projectIterator (datamodel, callback) {
childIterator(datamodel, callback, DM_DERIVATIVES.PROJECT);
}
/**
* Invokes a callback over the children created by a groupBy
* operation on a DataModel.
*
* @param {DataModel} datamodel - The input DataModel instance.
* @param {Function} callback - The callback to be invoked. The parameters
* provided to the callback are the child DataModel instance and the groupBy string used to create it.
*/
export function groupByIterator (datamodel, callback) {
childIterator(datamodel, callback, DM_DERIVATIVES.GROUPBY);
}
|