Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export const referenceDecorate = (node) => {
if (type !== null && type !== undefined) {
observable.type = type;
}

node.page.notifySubNodeObserver(node.id, observableId);
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ TreeNode.propTypes = {
form: PropTypes.object,
shape: PropTypes.object,
showDescription: PropTypes.bool,
treeData: PropTypes.object,
treeData: PropTypes.array,
output: PropTypes.object,
};

Expand Down
54 changes: 53 additions & 1 deletion framework/elsa/fit-elsa-react/src/flow/jadeFlowPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*--------------------------------------------------------------------------------------------*/

import {copyPasteHelper, ElsaCopyHandler, page, PAGE_OPERATION_MODE, shapeDataHelper, sleep, uuid} from '@fit-elsa/elsa-core';
import {SYSTEM_ACTION, VIRTUAL_CONTEXT_NODE} from '@/common/Consts.js';
import {OBSERVER_STATUS, SYSTEM_ACTION, VIRTUAL_CONTEXT_NODE} from '@/common/Consts.js';
import {conditionRunner, inactiveNodeRunner, standardRunner} from '@/flow/runners.js';
import {message} from 'antd';

Expand Down Expand Up @@ -151,6 +151,17 @@ export const jadeFlowPage = (div, graph, name, id) => {
return self.observableStore.getObservable(nodeId, observableId);
};

/**
* 通知该节点所有树上子节点的observable.
*
* @param nodeId 所属节点的id.
* @param notifyTreeNodeId 通知的树上的id.
* @return {*|null}
*/
self.notifySubNodeObserver = (nodeId, notifyTreeNodeId) => {
return self.observableStore.notifySubNodeObserver(nodeId, notifyTreeNodeId);
};

/**
* 清空时,同时清空observableStore.
*
Expand Down Expand Up @@ -828,6 +839,47 @@ const ObservableStore = () => {
return observableMap ? observableMap.get(observableId) : null;
};

/**
* 通知节点上所有对应的子节点.
*
* @param nodeId 被监听节点的id.
* @param notifyTopTreeNodeId 通知的子节点对应的顶层父节点的id.
* @return {*|null}
*/
self.notifySubNodeObserver = (nodeId, notifyTopTreeNodeId) => {
const observableMap = self.store.get(nodeId);
const adjacencyList = buildAdjacencyList(observableMap);

const queue = adjacencyList.get(notifyTopTreeNodeId) || [];

while (queue.length > 0) {
const currentObservable = queue.shift();

currentObservable.observers.forEach(o => {
if (o.status === OBSERVER_STATUS.ENABLE) {
o.notify({
value: currentObservable.value,
type: currentObservable.type
});
}
});

const children = adjacencyList.get(currentObservable.observableId) || [];
queue.push(...children);
}
};

const buildAdjacencyList = (observableMap) => {
const adjacencyList = new Map();
for (const observable of observableMap.values()) {
if (!adjacencyList.has(observable.parentId)) {
adjacencyList.set(observable.parentId, []);
}
adjacencyList.get(observable.parentId).push(observable);
}
return adjacencyList;
};

/**
* 清空.
*/
Expand Down