gpt4 book ai didi

javascript - Batarang 正则拦截表达式

转载 作者:行者123 更新时间:2023-12-02 20:24:03 26 4
gpt4 key购买 nike

我最近一直在摆弄 Batarang 插件来分析一些性能。我注意到在每个日志的顶部都有一个专门用于称为“regularInterceptedExpression”的部分。任何人都可以解释这意味着什么以及提高性能的方法是什么。我在某处读到可能来自在指令中使用“=”属性。如果其他人也看到过这个,有解决办法吗?

最佳答案

如果你深入研究 AngularJS 代码,你可以看到函数 regularInterceptedExpression(scope, locals, allocate, input) 定义在函数 addInterceptor(parsedExpression, InterceptorFn) 内。唯一使用函数 addInterceptor(parsedExpression, InterceptorFn) 的地方是函数 $parse(exp, InterceptorFn, CheapChecks)。这是字符串和其他监视被转换为函数的地方。您需要将 angular.js 文件更新为

1) 增强$parse(exp,interceptorFn,expandedChecks)函数以保留解析的来源:

通过将 $$source 设置为 addInterceptor 函数的第一个参数来查找方法的结尾和每个 switch case 结束更新。

      parsedExpression.$$source = exp; // keep the source expression handy
return addInterceptor(parsedExpression, interceptorFn);

case 'function':
exp.$$source = exp; // keep the source expression handy
return addInterceptor(exp, interceptorFn);

default:
noop.$$source = exp; // keep the source expression handy
return addInterceptor(noop, interceptorFn);

2) 在regularInterceptedExpression函数内收集以下统计信息调用该函数:

 var fn = regularWatch ? function regularInterceptedExpression(scope, locals, assign, inputs) {
var value = useInputs && inputs ? inputs[0] : parsedExpression(scope, locals, assign, inputs);
window.$$rieStats = window.$$rieStats || {};
window.$$rieStats[parsedExpression.$$source] = (window.$$rieStats[parsedExpression.$$source] ? window.$$rieStats[parsedExpression.$$source] : 0) + 1;
return interceptorFn(value, scope, locals);

3) 运行您的应用程序并检查统计信息,即打开开发工具并将 $$rieStats 写入 JavaScript 控制台。您应该看到 regularInterceptedExpression 函数调用的观察者数量。

Object.keys($$rieStats).sort(function(a,b){return $$rieStats[a]-$$rieStats[b]}).reverse().forEach(function(item){ console.log(item, $$rieStats[item])})

提示:您还可以将 $$rieStats 计数添加到另一个分支函数 oneTimeInterceptedExpression 来跟踪一次绑定(bind)。

关于javascript - Batarang 正则拦截表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37399363/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com