MCPcopy Create free account
hub / github.com/Easy-Editor/EasyEditor / extend

Function extend

packages/core/src/plugin/plugin-extend.ts:65–94  ·  view source on GitHub ↗
(
  extendMap: Record<T, PluginExtendClass[T]>,
  extendClass: T,
  properties: Record<PropertyKey, any> | (PropertyDescriptorMap & ThisType<InstanceType<PluginExtendClass[T]>>),
)

Source from the content-addressed store, hash-verified

63 * @param properties 扩展属性
64 */
65export 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}

Callers 1

extendMethod · 0.90

Calls 2

isMobxExtendPropertyFunction · 0.90
addMobxExtendPropertyFunction · 0.90

Tested by

no test coverage detected