本文整理汇总了TypeScript中@kbn/interpreter/common.fromExpression函数的典型用法代码示例。如果您正苦于以下问题:TypeScript fromExpression函数的具体用法?TypeScript fromExpression怎么用?TypeScript fromExpression使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromExpression函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: syncFilterExpression
export function syncFilterExpression(
config: Record<string, any>,
filterExpression: string,
fields: string[] = []
) {
let changed = false;
const filterAst = fromExpression(filterExpression);
const newAst = fields.reduce((ast, field) => {
const val = get(ast, `chain[0].arguments.${field}[0]`);
if (val !== config[field]) {
changed = true;
if (!config[field]) {
// remove value if not in expression
return del(ast, `chain.0.arguments.${field}`);
}
return set(ast, `chain.0.arguments.${field}.0`, config[field]);
}
return ast;
}, filterAst);
return { changed, newAst };
}
示例2: async
): ExpressionRunner => async (expressionOrAst, { element, context, getInitialContext }) => {
// TODO: make interpreter initialization synchronous to avoid this
const interpreter = await interpreterPromise;
const ast =
typeof expressionOrAst === 'string' ? fromExpression(expressionOrAst) : expressionOrAst;
const response = await interpreter.interpretAst(ast, context || { type: 'null' }, {
getInitialContext: getInitialContext || (() => ({})),
inspectorAdapters: {
// TODO connect real adapters
requests: new RequestAdapter(),
data: new DataAdapter(),
},
});
if (element) {
if (response.type === 'render' && response.as) {
renderersRegistry.get(response.as).render(element, response.value, {
onDestroy: fn => {
// TODO implement
},
done: () => {
// TODO implement
},
});
} else {
// eslint-disable-next-line no-console
console.log('Unexpected result of expression', response);
}
}
return response;
};
示例3: async
export const runPipeline = async (
expression: string,
context: object,
handlers: RunPipelineHandlers
) => {
const ast = fromExpression(expression);
const { interpreter } = await getInterpreter();
const pipelineResponse = await interpreter.interpretAst(ast, context, handlers);
return pipelineResponse;
};
示例4: async
export const runPipeline = async (expression: string, context: any, handlers: any) => {
const ast = fromExpression(expression);
const pipelineResponse = await interpretAst(ast, context, handlers);
return pipelineResponse;
};