diff --git a/packages/rule-engine/src/core/create.ts b/packages/rule-engine/src/core/create.ts index 3eada62a..e7ee7878 100644 --- a/packages/rule-engine/src/core/create.ts +++ b/packages/rule-engine/src/core/create.ts @@ -23,6 +23,8 @@ export function create( // real runner async function run(dataSource: Partial) { + const dataSourceKeys = options?.dataSourceKeys || Object.keys(dataSource); + let shows: IShowData = {} as any; const allRuleKeys: Record = {}; @@ -48,7 +50,7 @@ export function create( function initializeShows() { traverse(rules); - shows = Object.keys(dataSource).reduce((all, key) => { + shows = dataSourceKeys.reduce((all, key) => { // 所有未参与的 key 都应该是 true if (!allRuleKeys[key]) { all[key] = true; diff --git a/packages/rule-engine/src/core/sync/create.ts b/packages/rule-engine/src/core/sync/create.ts index 76b314d0..423c6acd 100644 --- a/packages/rule-engine/src/core/sync/create.ts +++ b/packages/rule-engine/src/core/sync/create.ts @@ -21,6 +21,8 @@ export function create( // real runner function run(dataSource: Partial) { + const dataSourceKeys = options?.dataSourceKeys || Object.keys(dataSource); + let shows: IShowData = {} as any; const allRuleKeys: Record = {}; @@ -46,7 +48,7 @@ export function create( function initializeShows() { traverse(rules); - shows = Object.keys(dataSource).reduce((all, key) => { + shows = dataSourceKeys.reduce((all, key) => { // 所有未参与的 key 都应该是 true if (!allRuleKeys[key]) { all[key] = true; diff --git a/packages/rule-engine/src/core/sync/types.ts b/packages/rule-engine/src/core/sync/types.ts index ff3877c2..734d42ff 100644 --- a/packages/rule-engine/src/core/sync/types.ts +++ b/packages/rule-engine/src/core/sync/types.ts @@ -110,4 +110,6 @@ export type IOnHitAttr = ( export interface Options { defaultOnScaleTo?: IOnScaleTo; defaultOnHitAttr?: IOnHitAttr; + // + dataSourceKeys?: string[]; } diff --git a/packages/rule-engine/src/core/types.ts b/packages/rule-engine/src/core/types.ts index 5cdc3560..1cc5fb13 100644 --- a/packages/rule-engine/src/core/types.ts +++ b/packages/rule-engine/src/core/types.ts @@ -110,4 +110,5 @@ export type IOnHitAttr = ( export interface Options { defaultOnScaleTo?: IOnScaleTo; defaultOnHitAttr?: IOnHitAttr; + dataSourceKeys?: string[]; }