1 | import {Operator} from 'vega-dataflow';
|
2 | import {array, field, inherits, isArray} from 'vega-util';
|
3 |
|
4 | /**
|
5 | * Generates one or more field accessor functions.
|
6 | * If the 'name' parameter is an array, an array of field accessors
|
7 | * will be created and the 'as' parameter will be ignored.
|
8 | * @constructor
|
9 | * @param {object} params - The parameters for this operator.
|
10 | * @param {string} params.name - The field name(s) to access.
|
11 | * @param {string} params.as - The accessor function name.
|
12 | */
|
13 | export default function Field(params) {
|
14 | Operator.call(this, null, update, params);
|
15 | }
|
16 |
|
17 | inherits(Field, Operator);
|
18 |
|
19 | function update(_) {
|
20 | return (this.value && !_.modified()) ? this.value
|
21 | : isArray(_.name) ? array(_.name).map(function(f) { return field(f); })
|
22 | : field(_.name, _.as);
|
23 | }
|