Skip to content

Commit ca3d142

Browse files
committed
multi custom decorators on one field
1 parent ea951fd commit ca3d142

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ function buildComponent(cons: Cons, arg: ComponentOption, extend?: any): any {
129129
const map = slot.getMap('customDecorator')
130130
if (map && map.size > 0) {
131131
map.forEach((v) => {
132-
v.creator.apply({}, [option, v.key])
132+
v.forEach(ite=>ite.creator.apply({}, [option, ite.key]))
133+
133134
})
134135
}
135136

src/custom/custom.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ export function createDecorator(creator: Creator, opt?: {
1313
return compatibleMemberDecorator(function (proto: any, key: string) {
1414
const slot = obtainSlot(proto)
1515
const map = slot.obtainMap('customDecorator')
16-
map.set(key, {
16+
if(!map.has(key)){
17+
map.set(key,[])
18+
}
19+
const arr = map.get(key)!
20+
arr.push({
1721
key,
1822
creator,
1923
preserve: !!opt?.preserve
2024
})
25+
2126
})
2227
}
2328

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type SlotMapTypes = {
2727
watch: Map<string, WatchConfig | WatchConfig[]>
2828
ref: Map<string, RefConfig>
2929
setup: Map<string, SetupConfig>
30-
customDecorator: Map<string, CustomDecoratorRecord>
30+
customDecorator: Map<string, CustomDecoratorRecord[]>
3131
}
3232

3333
class Slot {
@@ -127,7 +127,7 @@ export function excludeNames(names: string[], slot: Slot, filter?: (mapName: str
127127
if (mapName === 'customDecorator') {
128128
const map = currSlot.obtainMap('customDecorator')
129129
if (map.has(name)) {
130-
if (!map.get(name)!.preserve) {
130+
if (map.get(name)!.every(ite=>!ite.preserve)) {
131131
return false
132132
} else {
133133
continue

0 commit comments

Comments
 (0)