Skip to content

Commit

Permalink
hackfixing initial DataFlow node #702
Browse files Browse the repository at this point in the history
  • Loading branch information
Domiii committed Mar 19, 2022
1 parent 0061273 commit d6f5fc4
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 9 deletions.
17 changes: 16 additions & 1 deletion dbux-code/src/dataFlowView/DataFlowNodeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,21 @@ export default class DataFlowNodeProvider extends BaseTreeViewNodeProvider {
}

// apply filters
const { accessId, valueId } = dataNode;
const { accessId, valueId, refId } = dataNode;
/**
* @type {DataNode[]}
*/
let dataNodes;
let firstNode = null;
if (DataFlowSearchModeType.is.ByAccessId(this.controller.searchMode)) {
dataNodes = dp.indexes.dataNodes.byAccessId.get(accessId);
}
else if (DataFlowSearchModeType.is.ByValueId(this.controller.searchMode)) {
dataNodes = dp.indexes.dataNodes.byValueId.get(valueId);

if (refId) {
firstNode = dp.util.getAnyFirstNodeByRefId(dataNode.refId);
}
}

if (DataFlowFilterModeType.is.ReadOnly(this.controller.filterMode)) {
Expand All @@ -92,6 +100,13 @@ export default class DataFlowNodeProvider extends BaseTreeViewNodeProvider {
}

const dataTraceIds = new Set();

if (firstNode && dataNodes?.[0]?.nodeId !== firstNode.nodeId) {
// manually add first trace
// see https://github.com/Domiii/dbux/issues/702
dataNodes.unshift(firstNode);
}

return dataNodes?.map((node) => {
const dataTrace = dp.collections.traces.getById(node.traceId);
if (dataTraceIds.has(dataTrace.traceId)) {
Expand Down
2 changes: 2 additions & 0 deletions dbux-data/src/collections/DataNodeCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default class DataNodeCollection extends Collection {

if (dataNode.refId) {
const firstRef = this.dp.indexes.dataNodes.byRefId.getFirst(dataNode.refId);
// const firstNodeId = this.dp.util.getAnyFirstNodeIdByRefId(dataNode.refId);
// return Math.min(firstNodeId, firstRef.nodeId);
return firstRef.nodeId;
}
else {
Expand Down
34 changes: 34 additions & 0 deletions dbux-data/src/dataProviderUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,14 +941,48 @@ export default {
return null;
},

/** @param {DataProvider} dp */
getDataNodesByRefId(dp, refId) {
return dp.indexes.dataNodes.byRefId.get(refId);
},

/** @param {DataProvider} dp */
getFirstDataNodeByRefId(dp, refId) {
return dp.indexes.dataNodes.byRefId.getFirst(refId);
},

/**
* Get first DataNode by refId, even if it does NOT OWN it.
*
* @param {DataProvider} dp
*/
getAnyFirstNodeIdByRefId(dp, refId) {
const ref = dp.collections.values.getById(refId);
const { nodeId } = ref;
// const { traceId } = dp.collections.dataNodes.getById(nodeId);
// return traceId;
return nodeId;
},

/**
* Get first DataNode by refId, even if it does NOT OWN it.
*
* @param {DataProvider} dp
*/
getAnyFirstNodeByRefId(dp, refId) {
const nodeId = dp.util.getAnyFirstNodeIdByRefId(refId);
return nodeId && dp.collections.dataNodes.getById(nodeId);
},

/**
* @param {DataProvider} dp
*/
getFirstTraceIdByNodeId(dp, nodeId) {
const { traceId } = dp.collections.dataNodes.getById(nodeId);
return traceId;
},

/** @param {DataProvider} dp */
getFirstTraceIdByRefId(dp, refId) {
const dataNode = dp.indexes.dataNodes.byRefId.getFirst(refId);
return dataNode?.traceId;
Expand Down
22 changes: 18 additions & 4 deletions dbux-runtime/src/data/dataNodeCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,18 @@ export class DataNodeCollection extends Collection {
return writeNode;
}

createDataNode(value, traceId, type, varAccess, inputs, meta = null) {
createRefDataNode(value, parentNodeId, propValue, refId) {
const { traceId } = this.getById(parentNodeId);
const type = DataNodeType.Write;
const varAccess = {
objectNodeId: parentNodeId,
prop: propValue
};
const inputs = null, meta = null;
return this.createDataNode(value, traceId, type, varAccess, inputs, meta, refId);
}

createDataNode(value, traceId, type, varAccess, inputs, meta = null, refId = null) {
const dataNode = pools.dataNodes.allocate();

dataNode.nodeId = this._all.length;
Expand All @@ -98,10 +109,13 @@ export class DataNodeCollection extends Collection {

this.push(dataNode);

// valueRef
const valueRef = valueCollection.registerValueMaybe(value, dataNode, meta);
if (!refId) {
// valueRef
const valueRef = valueCollection.registerValueMaybe(value, dataNode, meta);
refId = valueRef?.refId || 0;
}

dataNode.refId = valueRef?.refId || 0;
dataNode.refId = refId;
dataNode.varAccess = varAccess;

if (Verbose) {
Expand Down
7 changes: 3 additions & 4 deletions dbux-runtime/src/data/valueCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,6 @@ class ValueCollection extends Collection {
* @return {ValueRef}
*/
_serialize(value, nodeId, depth = 1, category = null, meta = null) {
// let serialized = serialize(category, value, serializationLimits);
let serialized;
let pruneState = ValuePruneState.Normal;
let typeName = '';
Expand Down Expand Up @@ -669,10 +668,10 @@ class ValueCollection extends Collection {
// start serializing
serialized = {};

const builtInSerializer = this.getBuiltInSerializer(value);
if (builtInSerializer) {
const serialize = this.getBuiltInSerializer(value);
if (serialize) {
// serialize built-in types - especially: RegExp, Map, Set
builtInSerializer(value, nodeId, depth, serialized, valueRef, meta);
serialize(value, nodeId, depth, serialized, valueRef, meta);
}
else {
// serialize object (default)
Expand Down
7 changes: 7 additions & 0 deletions samples/__samplesInput__/json-parse1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var a = JSON.parse('[{ "x": 1 }, { "x": 2 }]');

var b = a[0];
var c = a[1];

console.log(a[0], b, a);
console.log(c);

0 comments on commit d6f5fc4

Please sign in to comment.