( extendMap: Record<T, PluginExtendClass[T]>, extendClass: T, properties: Record<PropertyKey, any> | (PropertyDescriptorMap & ThisType<InstanceType<PluginExtendClass[T]>>), )
| 63 | * @param properties 扩展属性 |
| 64 | */ |
| 65 | export const extend = <T extends keyof PluginExtendClass>( |
| 66 | extendMap: Record<T, PluginExtendClass[T]>, |
| 67 | extendClass: T, |
| 68 | properties: Record<PropertyKey, any> | (PropertyDescriptorMap & ThisType<InstanceType<PluginExtendClass[T]>>), |
| 69 | ) => { |
| 70 | const newProperties: PropertyDescriptorMap & ThisType<InstanceType<PluginExtendClass[T]>> = {} |
| 71 | const prototype = extendMap[extendClass].prototype |
| 72 | let hasMobXProperties = false |
| 73 | |
| 74 | for (const key in properties) { |
| 75 | const property = properties[key] |
| 76 | |
| 77 | // 检查是否为 MobX 扩展属性 |
| 78 | if (isMobxExtendProperty(property)) { |
| 79 | addMobxExtendProperty(prototype, key, property.config) |
| 80 | hasMobXProperties = true |
| 81 | continue |
| 82 | } |
| 83 | |
| 84 | if (typeof property === 'function') { |
| 85 | newProperties[key] = { |
| 86 | value: property, |
| 87 | } |
| 88 | } else { |
| 89 | newProperties[key] = property |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | Object.defineProperties(prototype, newProperties) |
| 94 | } |
no test coverage detected