(context: any, schema: RootSchema, method: string, args: any)
| 35 | * execute method in schema.lifeCycles with context |
| 36 | */ |
| 37 | export 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 |
no test coverage detected