Commit 519d7866 authored by rockyl's avatar rockyl

处理循环依赖的逻辑

parent 7e2446b6
...@@ -44,7 +44,7 @@ async function packData(data, {getProcesses, getScripts}) { ...@@ -44,7 +44,7 @@ async function packData(data, {getProcesses, getScripts}) {
} }
//console.log('scriptIDs:', scriptIDs); //console.log('scriptIDs:', scriptIDs);
let scriptsContainer = newData.scripts = {}; let scriptsContainer = newData.scripts = {};
if(scriptIDs.length > 0){ if (scriptIDs.length > 0) {
const scripts = await getScripts(scriptIDs); const scripts = await getScripts(scriptIDs);
for (let scriptData of scripts) { for (let scriptData of scripts) {
let {id, code} = JSON.parse(scriptData); let {id, code} = JSON.parse(scriptData);
...@@ -54,26 +54,57 @@ async function packData(data, {getProcesses, getScripts}) { ...@@ -54,26 +54,57 @@ async function packData(data, {getProcesses, getScripts}) {
} }
let processIDs = []; let processIDs = [];
for (let process of newData.processes) { findDepPidsBat(processIDs, newData.processes);
//console.log('processIDs:', processIDs);
let builtinProcesses = newData.builtinProcesses = [];
let bProcessIDs = processIDs;
while (true) {
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getProcesses);
bProcessIDs = [];
for (let id of newPids) {
if (!processIDs.includes(id)) {
bProcessIDs.push(id);
processIDs.push(id);
}
}
if (bProcessIDs.length === 0) {
break;
}
}
return JSON.stringify(newData);
}
function findDepPids(list, process) {
if(process.sub){
for (let key in process.sub) { for (let key in process.sub) {
let p = process.sub[key]; let p = process.sub[key];
if (!processIDs.includes(p.meta)) { if (!list.includes(p.meta)) {
processIDs.push(p.meta); list.push(p.meta);
} }
} }
} }
//console.log('processIDs:', processIDs); }
let builtinProcesses = newData.builtinProcesses = [];
if(processIDs.length > 0){ function findDepPidsBat(list, processes) {
let processes = await getProcesses(processIDs); for (let process of processes) {
findDepPids(list, process);
}
}
async function addBuiltinProcesses(list, ids, getProcesses) {
let newPids = [];
if (ids.length > 0) {
let processes = await getProcesses(ids);
for (let processData of processes) { for (let processData of processes) {
let process = JSON.parse(processData); let process = JSON.parse(processData);
builtinProcesses.push(process); list.push(process);
findDepPids(newPids, process);
} }
//console.log('processes:', data.processes); //console.log('processes:', data.processes);
} }
return newPids;
return JSON.stringify(newData);
} }
async function pageTemplate(data, options, version) { async function pageTemplate(data, options, version) {
......
This diff is collapsed.
...@@ -48,7 +48,7 @@ async function packData(data, {getProcesses, getScripts}) { ...@@ -48,7 +48,7 @@ async function packData(data, {getProcesses, getScripts}) {
} }
//console.log('scriptIDs:', scriptIDs); //console.log('scriptIDs:', scriptIDs);
let scriptsContainer = newData.scripts = {}; let scriptsContainer = newData.scripts = {};
if(scriptIDs.length > 0){ if (scriptIDs.length > 0) {
const scripts = await getScripts(scriptIDs); const scripts = await getScripts(scriptIDs);
for (let scriptData of scripts) { for (let scriptData of scripts) {
let {id, code} = JSON.parse(scriptData); let {id, code} = JSON.parse(scriptData);
...@@ -58,26 +58,57 @@ async function packData(data, {getProcesses, getScripts}) { ...@@ -58,26 +58,57 @@ async function packData(data, {getProcesses, getScripts}) {
} }
let processIDs = []; let processIDs = [];
for (let process of newData.processes) { findDepPidsBat(processIDs, newData.processes);
//console.log('processIDs:', processIDs);
let builtinProcesses = newData.builtinProcesses = [];
let bProcessIDs = processIDs;
while (true) {
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getProcesses);
bProcessIDs = [];
for (let id of newPids) {
if (!processIDs.includes(id)) {
bProcessIDs.push(id);
processIDs.push(id);
}
}
if (bProcessIDs.length === 0) {
break;
}
}
return JSON.stringify(newData);
}
function findDepPids(list, process) {
if(process.sub){
for (let key in process.sub) { for (let key in process.sub) {
let p = process.sub[key]; let p = process.sub[key];
if (!processIDs.includes(p.meta)) { if (!list.includes(p.meta)) {
processIDs.push(p.meta); list.push(p.meta);
} }
} }
} }
//console.log('processIDs:', processIDs); }
let builtinProcesses = newData.builtinProcesses = [];
if(processIDs.length > 0){ function findDepPidsBat(list, processes) {
let processes = await getProcesses(processIDs); for (let process of processes) {
findDepPids(list, process);
}
}
async function addBuiltinProcesses(list, ids, getProcesses) {
let newPids = [];
if (ids.length > 0) {
let processes = await getProcesses(ids);
for (let processData of processes) { for (let processData of processes) {
let process = JSON.parse(processData); let process = JSON.parse(processData);
builtinProcesses.push(process); list.push(process);
findDepPids(newPids, process);
} }
//console.log('processes:', data.processes); //console.log('processes:', data.processes);
} }
return newPids;
return JSON.stringify(newData);
} }
async function pageTemplate(data, options, version) { async function pageTemplate(data, options, version) {
......
This diff is collapsed.
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
} }
//console.log('scriptIDs:', scriptIDs); //console.log('scriptIDs:', scriptIDs);
let scriptsContainer = newData.scripts = {}; let scriptsContainer = newData.scripts = {};
if(scriptIDs.length > 0){ if (scriptIDs.length > 0) {
const scripts = await getScripts(scriptIDs); const scripts = await getScripts(scriptIDs);
for (let scriptData of scripts) { for (let scriptData of scripts) {
let {id, code} = JSON.parse(scriptData); let {id, code} = JSON.parse(scriptData);
...@@ -60,26 +60,57 @@ ...@@ -60,26 +60,57 @@
} }
let processIDs = []; let processIDs = [];
for (let process of newData.processes) { findDepPidsBat(processIDs, newData.processes);
//console.log('processIDs:', processIDs);
let builtinProcesses = newData.builtinProcesses = [];
let bProcessIDs = processIDs;
while (true) {
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getProcesses);
bProcessIDs = [];
for (let id of newPids) {
if (!processIDs.includes(id)) {
bProcessIDs.push(id);
processIDs.push(id);
}
}
if (bProcessIDs.length === 0) {
break;
}
}
return JSON.stringify(newData);
}
function findDepPids(list, process) {
if(process.sub){
for (let key in process.sub) { for (let key in process.sub) {
let p = process.sub[key]; let p = process.sub[key];
if (!processIDs.includes(p.meta)) { if (!list.includes(p.meta)) {
processIDs.push(p.meta); list.push(p.meta);
} }
} }
} }
//console.log('processIDs:', processIDs); }
let builtinProcesses = newData.builtinProcesses = [];
if(processIDs.length > 0){ function findDepPidsBat(list, processes) {
let processes = await getProcesses(processIDs); for (let process of processes) {
findDepPids(list, process);
}
}
async function addBuiltinProcesses(list, ids, getProcesses) {
let newPids = [];
if (ids.length > 0) {
let processes = await getProcesses(ids);
for (let processData of processes) { for (let processData of processes) {
let process = JSON.parse(processData); let process = JSON.parse(processData);
builtinProcesses.push(process); list.push(process);
findDepPids(newPids, process);
} }
//console.log('processes:', data.processes); //console.log('processes:', data.processes);
} }
return newPids;
return JSON.stringify(newData);
} }
async function pageTemplate(data, options, version) { async function pageTemplate(data, options, version) {
......
This diff is collapsed.
...@@ -44,7 +44,7 @@ async function packData(data, {getProcesses, getScripts}) { ...@@ -44,7 +44,7 @@ async function packData(data, {getProcesses, getScripts}) {
} }
//console.log('scriptIDs:', scriptIDs); //console.log('scriptIDs:', scriptIDs);
let scriptsContainer = newData.scripts = {}; let scriptsContainer = newData.scripts = {};
if(scriptIDs.length > 0){ if (scriptIDs.length > 0) {
const scripts = await getScripts(scriptIDs); const scripts = await getScripts(scriptIDs);
for (let scriptData of scripts) { for (let scriptData of scripts) {
let {id, code} = JSON.parse(scriptData); let {id, code} = JSON.parse(scriptData);
...@@ -54,26 +54,57 @@ async function packData(data, {getProcesses, getScripts}) { ...@@ -54,26 +54,57 @@ async function packData(data, {getProcesses, getScripts}) {
} }
let processIDs = []; let processIDs = [];
for (let process of newData.processes) { findDepPidsBat(processIDs, newData.processes);
//console.log('processIDs:', processIDs);
let builtinProcesses = newData.builtinProcesses = [];
let bProcessIDs = processIDs;
while (true) {
let newPids = await addBuiltinProcesses(builtinProcesses, bProcessIDs, getProcesses);
bProcessIDs = [];
for (let id of newPids) {
if (!processIDs.includes(id)) {
bProcessIDs.push(id);
processIDs.push(id);
}
}
if (bProcessIDs.length === 0) {
break;
}
}
return JSON.stringify(newData);
}
function findDepPids(list, process) {
if(process.sub){
for (let key in process.sub) { for (let key in process.sub) {
let p = process.sub[key]; let p = process.sub[key];
if (!processIDs.includes(p.meta)) { if (!list.includes(p.meta)) {
processIDs.push(p.meta); list.push(p.meta);
} }
} }
} }
//console.log('processIDs:', processIDs); }
let builtinProcesses = newData.builtinProcesses = [];
if(processIDs.length > 0){ function findDepPidsBat(list, processes) {
let processes = await getProcesses(processIDs); for (let process of processes) {
findDepPids(list, process);
}
}
async function addBuiltinProcesses(list, ids, getProcesses) {
let newPids = [];
if (ids.length > 0) {
let processes = await getProcesses(ids);
for (let processData of processes) { for (let processData of processes) {
let process = JSON.parse(processData); let process = JSON.parse(processData);
builtinProcesses.push(process); list.push(process);
findDepPids(newPids, process);
} }
//console.log('processes:', data.processes); //console.log('processes:', data.processes);
} }
return newPids;
return JSON.stringify(newData);
} }
async function pageTemplate(data, options, version) { async function pageTemplate(data, options, version) {
......
...@@ -284,6 +284,10 @@ content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, u ...@@ -284,6 +284,10 @@ content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, u
y: 100, y: 100,
}, },
}, },
a3: {
uuid: 'a3',
meta: 'ddd'
}
} }
}, },
{ {
......
...@@ -26,6 +26,22 @@ function getProcesses(ids) { ...@@ -26,6 +26,22 @@ function getProcesses(ids) {
script: "resolve({type: 'success', payload: args});", script: "resolve({type: 'success', payload: args});",
output: ['success'], output: ['success'],
}), }),
JSON.stringify({
id: 'ddd',
name: 'DDD',
props: {},
sub: {
1: {
uuid: 1,
meta: 'eee',
}
}
}),
JSON.stringify({
id: 'eee',
name: 'EEE',
props: {},
}),
] ]
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment