madge icon indicating copy to clipboard operation
madge copied to clipboard

Feature request: sup set result data.

Open shenghou opened this issue 3 years ago • 1 comments

sup child in tree and other value, such as path、child and extname.

  convertTree(depTree, tree, pathCache) {
    const keys = Object.keys(depTree);
    keys.forEach((key) => {
      const processPath = this.processPath(key, pathCache);
      if (!tree[processPath]) {
        tree[processPath] = this.setResultData(key, processPath);
      }

      if (this.isEmptyObject(depTree[key])) {
        tree[processPath].child.push(this.setResultData(key, processPath));
      } else {
        tree[processPath].child.push(
          this.convertTree(depTree[key], {}, pathCache)
        );
      }
    });

    return tree;
  }

set result data


 setResultData(key, path) {
    // set default result data
    const baseResultData = {
      name: key,
      path,
      child: [],
    };

    if (
      this.config.detectiveCallArray &&
      Array.isArray(this.config.detectiveCallArray) &&
      this.config.detectiveCallArray.length > 0
    ) {
      this.config.detectiveCallArray.forEach((item) => {
        const callKey = item.key;
        const callValue = item.callback(path);
        baseResultData[callKey] = callValue;
      });
    }
    return baseResultData;
  }

add detectiveCallArray in config for sup callback function


function callFunc(path) {
  return 'hello word';
}

function callFuncddd(pathName) {
  return path.extname(pathName);
}


const config = {
   ...
   detectiveCallArray: [   // set detectiveCall
    { key: 'words', callback: callFunc },
    { key: 'ext', callback: callFuncddd },
  ],

}

shenghou avatar Oct 02 '21 13:10 shenghou

@shenghou Is this a PR? I'm confused about what sup means.

PabloLION avatar Jan 29 '23 19:01 PabloLION