Skip to content

Commit

Permalink
return typed arrays as lists (#10204)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryevdv committed Jun 20, 2020
1 parent 6172cda commit d0cda21
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions bokehjs/src/lib/core/has_props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Property} from "./properties"
import {uniqueId} from "./util/string"
import {max, copy} from "./util/array"
import {entries, clone, extend, isEmpty} from "./util/object"
import {isPlainObject, isObject, isArray, isString, isFunction} from "./util/types"
import {isPlainObject, isObject, isArray, isTypedArray, isString, isFunction} from "./util/types"
import {isEqual} from './util/eq'
import {ColumnarDataSource} from "models/sources/columnar_data_source"
import {Document, DocumentEvent, DocumentEventBatch, ModelChangedEvent} from "../document"
Expand Down Expand Up @@ -435,11 +435,12 @@ export abstract class HasProps extends Signalable() {
return value.ref()
else if (is_NDArray(value))
return encode_NDArray(value)
else if (isArray(value)) {
const ref_array: unknown[] = []
for (let i = 0; i < value.length; i++) {
else if (isArray(value) || isTypedArray(value)) {
const n = value.length
const ref_array: unknown[] = new Array(n)
for (let i = 0; i < n; i++) {
const v = value[i]
ref_array.push(HasProps._value_to_json(v))
ref_array[i] = HasProps._value_to_json(v)
}
return ref_array
} else if (isPlainObject(value)) {
Expand Down
2 changes: 1 addition & 1 deletion bokehjs/src/lib/core/util/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function isArrayableOf<T>(arr: Arrayable, predicate: (item: unknown) => i
}

export function isTypedArray(obj: unknown): obj is TypedArray {
return obj != null && (obj as any).buffer instanceof ArrayBuffer
return ArrayBuffer.isView(obj) && !(obj instanceof DataView)
}

export function isObject(obj: unknown): obj is object {
Expand Down

0 comments on commit d0cda21

Please sign in to comment.