Skip to content

Commit

Permalink
chore(rule-engine): create add option.dataSourceKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
whatwewant committed Nov 2, 2023
1 parent 51496ac commit f4f0060
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/rule-engine/src/core/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export function create<DataSource>(

// real runner
async function run(dataSource: Partial<DataSource>) {
const dataSourceKeys = options?.dataSourceKeys || Object.keys(dataSource);

let shows: IShowData<DataSource> = {} as any;

const allRuleKeys: Record<string, boolean> = {};
Expand All @@ -48,7 +50,7 @@ export function create<DataSource>(
function initializeShows() {
traverse(rules);

shows = Object.keys(dataSource).reduce((all, key) => {
shows = dataSourceKeys.reduce((all, key) => {
// 所有未参与的 key 都应该是 true
if (!allRuleKeys[key]) {
all[key] = true;
Expand Down
4 changes: 3 additions & 1 deletion packages/rule-engine/src/core/sync/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export function create<DataSource>(

// real runner
function run(dataSource: Partial<DataSource>) {
const dataSourceKeys = options?.dataSourceKeys || Object.keys(dataSource);

let shows: IShowData<DataSource> = {} as any;

const allRuleKeys: Record<string, boolean> = {};
Expand All @@ -46,7 +48,7 @@ export function create<DataSource>(
function initializeShows() {
traverse(rules);

shows = Object.keys(dataSource).reduce((all, key) => {
shows = dataSourceKeys.reduce((all, key) => {
// 所有未参与的 key 都应该是 true
if (!allRuleKeys[key]) {
all[key] = true;
Expand Down
2 changes: 2 additions & 0 deletions packages/rule-engine/src/core/sync/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ export type IOnHitAttr<DataSource> = (
export interface Options<DataSource> {
defaultOnScaleTo?: IOnScaleTo<DataSource>;
defaultOnHitAttr?: IOnHitAttr<DataSource>;
//
dataSourceKeys?: string[];
}
1 change: 1 addition & 0 deletions packages/rule-engine/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@ export type IOnHitAttr<DataSource> = (
export interface Options<DataSource> {
defaultOnScaleTo?: IOnScaleTo<DataSource>;
defaultOnHitAttr?: IOnHitAttr<DataSource>;
dataSourceKeys?: string[];
}

0 comments on commit f4f0060

Please sign in to comment.