Skip to content

Commit 6c5a958

Browse files
authored
feat(data): allow custom DataSet/View implementations (#1108)
This tests that the methods and properties are implemented instead of checking the prototype. Thanks to this it is now possible to use a different DataSet or DataView without extending the Vis one. This also removes some interoperability issues of the standalone build when used toghether with other Vis family libraries.
1 parent c130c57 commit 6c5a958

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/network/modules/EdgesHandler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { deepExtend, forEach } from "vis-util/esnext";
2-
import { DataSet, DataView } from "vis-data/esnext";
2+
import { DataSet, isDataViewLike } from "vis-data/esnext";
33
import Edge from "./components/Edge";
44

55
/**
@@ -248,13 +248,13 @@ class EdgesHandler {
248248
* Load edges by reading the data table
249249
*
250250
* @param {Array | DataSet | DataView} edges The data containing the edges.
251-
* @param {boolean} [doNotEmit=false]
251+
* @param {boolean} [doNotEmit=false] - Suppress data changed event.
252252
* @private
253253
*/
254254
setData(edges, doNotEmit = false) {
255255
const oldEdgesData = this.body.data.edges;
256256

257-
if (edges instanceof DataSet || edges instanceof DataView) {
257+
if (isDataViewLike("id", edges)) {
258258
this.body.data.edges = edges;
259259
} else if (Array.isArray(edges)) {
260260
this.body.data.edges = new DataSet();

lib/network/modules/NodesHandler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { bridgeObject, forEach } from "vis-util/esnext";
2-
import { DataSet, DataView } from "vis-data/esnext";
2+
import { DataSet, isDataViewLike } from "vis-data/esnext";
33
import Node from "./components/Node";
44

55
/**
@@ -245,13 +245,13 @@ class NodesHandler {
245245
* Set a data set with nodes for the network
246246
*
247247
* @param {Array | DataSet | DataView} nodes The data containing the nodes.
248-
* @param {boolean} [doNotEmit=false]
248+
* @param {boolean} [doNotEmit=false] - Suppress data changed event.
249249
* @private
250250
*/
251251
setData(nodes, doNotEmit = false) {
252252
const oldNodesData = this.body.data.nodes;
253253

254-
if (nodes instanceof DataSet || nodes instanceof DataView) {
254+
if (isDataViewLike("id", nodes)) {
255255
this.body.data.nodes = nodes;
256256
} else if (Array.isArray(nodes)) {
257257
this.body.data.nodes = new DataSet();

0 commit comments

Comments
 (0)