本文整理匯總了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;
};