是否不断轮询Aurelia变更检测的工作方式? [英] Is constant polling the way Aurelia's change detection is working?
问题描述
I got div with if.bind working as was suggested in this question: Using literal JavaScript values in an Aurelia view. But then I noticed that showTemplate on viewModel is being constantly checked by framework, about 10 times per second. The stack is following:
execute._prototypeProperties.visible.get (welcome.js:29)
getValue (dirty-checking.js:93)
isDirty (dirty-checking.js:127)
check (dirty-checking.js:63)
(anonymous function) (dirty-checking.js:49)
应该是这样吗?似乎不是很资源友好.
Is it supposed to be like this? Seems to be not very resource-friendly.
最诚挚的问候,尤金.
推荐答案
Aurelia将Object.observe
用于简单的Javascript属性.如果showTemplate
是函数或getter/setter,则Aurelia当前将恢复为脏检查.可以通过声明函数的依赖项将其删除.此处概述: https://github.com/aurelia/binding/pull/41
Aurelia uses Object.observe
for simple Javascript properties. If showTemplate
is a function or a getter/setter, then Aurelia currently reverts to dirty checking. This can be removed by declaring the dependencies of the function. This is outlined here: https://github.com/aurelia/binding/pull/41
我已经创建了实现此目标的Aurelia骨架项目版本: https://github.com/ashleygrant/skeleton-navigation/tree/declare_dependencies
I have created a version of the Aurelia Skeleton project that implements this: https://github.com/ashleygrant/skeleton-navigation/tree/declare_dependencies
要实现此目的,必须切换为使用aurelia-main
属性.添加main.js
文件:
To implement this, you must switch to using the aurelia-main
attribute. Add a main.js
file:
import {LogManager} from 'aurelia-framework';
import {ConsoleAppender} from 'aurelia-logging-console';
import {ComputedObservationAdapter, ObjectObservationAdapter} from 'aurelia-framework';
LogManager.addAppender(new ConsoleAppender());
LogManager.setLevel(LogManager.levels.debug);
export function configure(aurelia) {
aurelia.use
.defaultBindingLanguage()
.defaultResources()
.router()
.eventAggregator();
aurelia.container
.registerSingleton(ObjectObservationAdapter, ComputedObservationAdapter);
aurelia.start().then(a => a.setRoot('app', document.body));
}
然后在welcome.js
中添加以下导入语句:
Then, in welcome.js
, add the following import statement:
import {declarePropertyDependencies} from 'aurelia-framework';
,然后在Welcome
类之外,添加以下方法调用:
and then outside the Welcome
class, add the following method call:
declarePropertyDependencies(Welcome, 'fullName', ['firstName', 'lastName']);
这篇关于是否不断轮询Aurelia变更检测的工作方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!