@bokeh/bokehjs
Version:
Interactive, novel data visualization
65 lines • 2.04 kB
JavaScript
import { HasProps } from "../../core/has_props";
import { Expression } from "./expression";
import { GeneratorFunction } from "../../core/types";
import { repeat } from "../../core/util/array";
import { keys, values } from "../../core/util/object";
import { use_strict } from "../../core/util/string";
import { isArray, isTypedArray, isIterable } from "../../core/util/types";
export class CustomJSExpr extends Expression {
static __name__ = "CustomJSExpr";
constructor(attrs) {
super(attrs);
}
static {
this.define(({ Unknown, Str, Dict }) => ({
args: [Dict(Unknown), {}],
code: [Str, ""],
}));
}
connect_signals() {
super.connect_signals();
for (const value of values(this.args)) {
if (value instanceof HasProps) {
value.change.connect(() => {
this._result.clear();
this.change.emit();
});
}
}
}
get names() {
return keys(this.args);
}
get values() {
return values(this.args);
}
get func() {
const code = use_strict(this.code);
return new GeneratorFunction(...this.names, code);
}
_v_compute(source) {
const generator = this.func.apply(source, this.values);
let result = generator.next();
if ((result.done ?? false) && result.value !== undefined) {
const { value } = result;
if (isArray(value) || isTypedArray(value)) {
return value;
}
else if (isIterable(value)) {
return [...value];
}
else {
return repeat(value, source.length);
}
}
else {
const array = [];
do {
array.push(result.value);
result = generator.next();
} while (!(result.done ?? false));
return array;
}
}
}
//# sourceMappingURL=customjs_expr.js.map