Skip to content

Commit

Permalink
Fix params getting changed when decorator used multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
repalash committed Dec 21, 2023
1 parent fb7fdd2 commit e2ca5bc
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uiconfig.js",
"version": "0.0.8",
"version": "0.0.9",
"description": "A framework for building user interface layouts with JSON configuration.",
"main": "src/index.ts",
"module": "dist/index.mjs",
Expand Down
2 changes: 1 addition & 1 deletion src/UiConfigMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class UiConfigMethods {
const binding = this.getBinding(config)
const tar = binding[0] ?? config
const key = binding[1] || 'onClick'
const action = tar[key] as Fof<any>
const action = (tar[key] ?? tar.value) as Fof<any>
if (typeof action === 'function') {
action.call(tar, ...options?.args ?? [])
} else if (action) {
Expand Down
9 changes: 5 additions & 4 deletions src/decorator_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class UiConfigTypeMap {
static Map = new Map<ObjectConstructor, any[]>()
}

function generateValueConfig(obj: any, key: string | number, label?: string, val?: any) {
export function generateValueConfig(obj: any, key: string | number, label?: string, val?: any) {
val = val ?? obj[key]
const config = val?.uiConfig
let result: UiObjectConfig|undefined = undefined
Expand Down Expand Up @@ -66,12 +66,13 @@ export function generateUiConfig(obj: any): UiObjectConfig[] {
}
if (params) {
const extraParams = typeof params.params === 'function' ? params.params(obj) : params.params || {}
delete params.params
const params1 = {...params}
delete params1.params
if (typeof config === 'function') {
const c1: Fof<any, any> = config
config = ()=>Object.assign(c1(), {...params, ...extraParams})
config = ()=>Object.assign(c1(), {...params1, ...extraParams})
}
Object.assign(config, {...params, ...extraParams})
Object.assign(config, {...params1, ...extraParams})
}
result.push(config)

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
uiToggle,
uiVector,
} from './decorator_alias'
import {generateUiConfig, generateUiFolder, UiConfigTypeMap} from './decorator_utils'
import {generateUiConfig, generateUiFolder, generateValueConfig, UiConfigTypeMap} from './decorator_utils'
import {
ChangeArgs,
ChangeEvent,
Expand All @@ -37,6 +37,6 @@ export {
uiColor, uiImage, uiToggle, uiNumber,
}
export {uiPanelContainer, uiFolderContainer}
export {generateUiConfig, generateUiFolder, UiConfigTypeMap}
export {generateUiConfig, generateUiFolder, generateValueConfig, UiConfigTypeMap}
export type {TParams}

0 comments on commit e2ca5bc

Please sign in to comment.