是否不断轮询Aurelia变更检测的工作方式? [英] Is constant polling the way Aurelia's change detection is working?

查看:68
本文介绍了是否不断轮询Aurelia变更检测的工作方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照此问题的建议使用了if.bind来工作div:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆