1 | import {Operator} from 'vega-dataflow';
|
2 | import {inherits, key} from 'vega-util';
|
3 |
|
4 | /**
|
5 | * Generates a key function.
|
6 | * @constructor
|
7 | * @param {object} params - The parameters for this operator.
|
8 | * @param {Array<string>} params.fields - The field name(s) for the key function.
|
9 | * @param {boolean} params.flat - A boolean flag indicating if the field names
|
10 | * should be treated as flat property names, side-stepping nested field
|
11 | * lookups normally indicated by dot or bracket notation.
|
12 | */
|
13 | export default function Key(params) {
|
14 | Operator.call(this, null, update, params);
|
15 | }
|
16 |
|
17 | inherits(Key, Operator);
|
18 |
|
19 | function update(_) {
|
20 | return (this.value && !_.modified()) ? this.value : key(_.fields, _.flat);
|
21 | }
|