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

Function executeLifeCycleMethod

packages/react-renderer/src/base.tsx:37–63  ·  view source on GitHub ↗
(context: any, schema: RootSchema, method: string, args: any)

Source from the content-addressed store, hash-verified

35 * execute method in schema.lifeCycles with context
36 */
37export function executeLifeCycleMethod(context: any, schema: RootSchema, method: string, args: any): any {
38 if (!context || !isSchema(schema) || !method) {
39 return
40 }
41 const lifeCycleMethods = getValue(schema, 'lifeCycles', {})
42 let fn = lifeCycleMethods[method]
43
44 if (!fn) {
45 return
46 }
47
48 // TODO: cache
49 if (isJSExpression(fn) || isJSFunction(fn)) {
50 fn = parseExpression(fn, context, true)
51 }
52
53 if (typeof fn !== 'function') {
54 logger.error(`生命周期${method}类型不符`, fn)
55 return
56 }
57
58 try {
59 return fn.apply(context, args)
60 } catch (e) {
61 logger.error(`[${schema.componentName}]生命周期${method}出错`, e)
62 }
63}
64
65/**
66 * get children from a node schema

Callers 2

BaseRendererClass · 0.85

Calls 6

isSchemaFunction · 0.90
getValueFunction · 0.90
isJSExpressionFunction · 0.90
isJSFunctionFunction · 0.90
parseExpressionFunction · 0.90
errorMethod · 0.45

Tested by

no test coverage detected