@@ -31,12 +31,13 @@ export type SlotMapTypes = {
31
31
setup : Map < string , SetupConfig >
32
32
customDecorator : Map < string , CustomDecoratorRecord [ ] >
33
33
}
34
+ type SlotMapNames = keyof SlotMapTypes
34
35
class Slot {
35
36
master : any
36
37
constructor ( master : any ) {
37
38
this . master = master
38
39
}
39
- names : Map < string , SlotMapTypes [ keyof SlotMapTypes ] > = new Map ( )
40
+ names : Map < keyof SlotMapTypes , SlotMapTypes [ keyof SlotMapTypes ] > = new Map ( )
40
41
obtainMap < T extends keyof SlotMapTypes > ( name : T ) : SlotMapTypes [ T ] {
41
42
let map = this . getMap ( name )
42
43
if ( ! map ) {
@@ -112,26 +113,25 @@ export function getSuperSlot(obj: any) {
112
113
}
113
114
114
115
/**
115
- * Exclude decorated names by a filter
116
+ * Filter decorated names
116
117
*/
117
- export function excludeNames ( names : string [ ] , slot : Slot , filter ?: ( mapName : string ) => boolean ) {
118
+ export function filterNames ( names : string [ ] , slot : Slot , mapNames ?: SlotMapNames [ ] ) {
118
119
return names . filter ( name => {
119
120
let currSlot : Slot | null = slot
120
121
while ( currSlot != null ) {
121
122
for ( const mapName of currSlot . names . keys ( ) ) {
122
- if ( filter && ! filter ( mapName ) ) {
123
- continue
124
- }
125
123
if ( mapName === 'customDecorator' ) {
126
124
const map = currSlot . obtainMap ( 'customDecorator' )
127
125
if ( map . has ( name ) ) {
128
126
if ( map . get ( name ) ! . every ( ite => ! ite . preserve ) ) {
129
127
return false
130
- } else {
131
- continue
132
128
}
133
129
}
134
130
}
131
+ if ( mapNames && mapNames . includes ( mapName ) ) {
132
+ continue
133
+ }
134
+
135
135
const map = currSlot . names . get ( mapName ) !
136
136
if ( map . has ( name ) ) {
137
137
return false
@@ -145,13 +145,22 @@ export function excludeNames(names: string[], slot: Slot, filter?: (mapName: str
145
145
}
146
146
147
147
/**
148
- * Get own properties by a filter
148
+ * Get own propertie name by a filter
149
149
*/
150
- export function getValidNames ( obj : any , filter : ( des : PropertyDescriptor , name : string ) => boolean ) {
150
+ export function getValidOwnPropertyNames ( obj : any , filter : ( des : PropertyDescriptor , name : string ) => boolean ) {
151
151
const descriptors = Object . getOwnPropertyDescriptors ( obj )
152
152
return Object . keys ( descriptors ) . filter ( name => filter ( descriptors [ name ] , name ) )
153
153
}
154
154
155
+
156
+ /**
157
+ * Transform provide into function.
158
+ */
159
+ export function getProviderFunction ( provide : any ) : ( ) => { } {
160
+ if ( typeof provide === 'function' ) return provide
161
+ return function ( ) { return provide || { } }
162
+ }
163
+
155
164
export function optionNullableMemberDecorator < T > ( handler : { ( proto : any , name : string , option ?: T ) : any } ) {
156
165
function decorator ( ) : any
157
166
function decorator ( option : T ) : any //option
@@ -197,7 +206,3 @@ export function optionNullableClassDecorator<T>(handler: { (cons: VueCons, optio
197
206
return decorator
198
207
}
199
208
200
- export function getProviderFunction ( provide : any ) : ( ) => { } {
201
- if ( typeof provide === 'function' ) return provide
202
- return function ( ) { return provide || { } }
203
- }
0 commit comments