-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a7dc91
commit 43c8f61
Showing
3 changed files
with
129 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { GIAssets, GIConfig } from '../typing'; | ||
import { filterByTopRule } from './filterByRules'; | ||
|
||
/** | ||
* | ||
* @param elementType 元素类型:node or edge | ||
* @param data 数据 | ||
* @param config GISDK配置 | ||
* @param ElementAssets 元素资产 | ||
* @param reset 是否重置transform | ||
* @returns nodes or edges | ||
*/ | ||
|
||
export const getMapperByCfg = ( | ||
config: Partial<GIConfig['edges']> | Partial<GIConfig['nodes']>, | ||
ElementAssets: GIAssets['elements'], | ||
reset?: boolean, | ||
) => { | ||
/** 默认的Mapper */ | ||
const dumpMapper = item => item; | ||
if (!config) { | ||
return dumpMapper; | ||
} | ||
console.log('start Mapper.....', config); | ||
const mapper = item => { | ||
// [ruleA,ruleB,ruleC] RuleC 的优先级最高 | ||
const reverseCfg = [...config].reverse(); | ||
for (const cfg of reverseCfg) { | ||
if (!cfg) { | ||
return; | ||
} | ||
const { id, expressions, logic } = cfg; | ||
|
||
if (!ElementAssets) { | ||
console.error('ElementAssets not available'); | ||
return []; | ||
} | ||
const Element = ElementAssets[id]; | ||
//@ts-ignore | ||
const isMatch = filterByTopRule(item.data, { logic, expressions }); | ||
|
||
if (isMatch) { | ||
// console.log(id, cfg, item); | ||
//@ts-ignore | ||
const mapper = Element.registerTransform(cfg, reset); | ||
//@ts-ignore | ||
const formateNode = mapper(item); | ||
// console.log(id, formateNode, 'isMatch', isMatch, expressions?.length, item); | ||
//@ts-ignore | ||
return formateNode; | ||
} | ||
} | ||
}; | ||
return mapper; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters