简体   繁体   English

如何检查是否使用脏检查?

[英]How to check if dirty checking is use?

I have some complex screen in my Aurelia app and I would like to check easily if some bindings are dirty checked . 我的Aurelia应用程序中有一些复杂的屏幕,我想轻松检查一些绑定是否脏了 I can add console.log in all my property getter and check when it is called but it's not easy. 我可以在我的所有属性getter中添加console.log并检查它何时被调用,但这并不容易。

Ideally I would like to get in the console the observer strategy used by each binding, but I didn't find where to plug to add this log. 理想情况下,我想在控制台中获取每个绑定使用的观察者策略,但我没有找到插入位置以添加此日志。

Thanks 谢谢

You can override DirtyCheckProperty 's subscribe method to add logging: 您可以覆盖DirtyCheckProperty的subscribe方法来添加日志记录:

import {DirtyCheckProperty} from 'aurelia-binding';
import * as LogManager from 'aurelia-logging';

const logger = LogManager.getLogger('my-app');

DirtyCheckProperty.prototype.standardSubscribe = DirtyCheckProperty.prototype.subscribe;
DirtyCheckProperty.prototype.subscribe = function(context, callable) {
  this.standardSubscribe(context, callable);

  logger.warn(`'${this.obj.constructor.name}.${this.propertyName}' is being dirty checked`, this.obj);
}

The messages would look like this in the console: 消息在控制台中看起来像这样:

安慰

Here's a running example app: 这是一个运行示例应用程序:

https://gist.run/?id=2c863d48a2a711b8c5f93df2bb7c4a3b https://gist.run/?id=2c863d48a2a711b8c5f93df2bb7c4a3b

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM