防止breeze.js在数组对象上创建observables属性 [英] Preventing breeze.js from creating observables properties on array objects

查看:86
本文介绍了防止breeze.js在数组对象上创建observables属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我肯定想念一些简单的东西,但无法弄清楚.我将在1个Web API调用中检索一堆查找表.

I must be missing something simple, but can't figure it out. I'm retrieving a bunch of lookup tables in 1 Web API call.

return EntityQuery.from('Lookups')
       .noTracking(true)
       .using(manager).execute()
       .then(processLookups);

在processLookups中,我为返回的每个数组调用getLocal.示例:状态表

In processLookups I'm calling getLocal for each array that was returned. Example: State table

 datacontext.lookups = {
     state: getLocal('States', orderBy.state, true),
     ....
 }

function getLocal(resource, ordering, includeNullos) {

    var query = EntityQuery.from(resource)
        .orderBy(ordering)
        .noTracking(true);

    if (!includeNullos) {
        query = query.where('id', '!=', 0);
    }
    return manager.executeQueryLocally(query);
}

数组是不可观察的,但是数组对象中的每个属性都是可观察的函数.这只是我不需要的开销,因为这些不会改变.

The arrays are not observable, but each property in the array objects are observable functions. This is just overhead I don't need since these will not be changing.

如何防止对象属性可见?

How can I prevent the object properties from being observable?

谢谢

推荐答案

您可以在查询的成功回调中直接使用原始查询.没有理由看缓存...即使它们在那里(Jay并没有说明).

The raw lookups are available to you right there in the success callback from the query. No reason to look at cache ... even if they were there (which they are not as Jay makes clear).

但是您将如何处理这些查询?大概您希望它们(通过Breeze导航路径)与真实实体相关联.例如,您希望session.room返回相关的房间对象.但是,如果房间是您的查找之一而不是实体,则session.room导航属性将不会返回它;导航属性始终返回实体.

But what would you DO with these lookups? Presumably you want them to be related (by Breeze navigation paths) to real entities. For example, you'd like session.room to return the related room object. But if the room is one of your lookups and is NOT an entity, then the session.room navigation property won't return it; nav properties always return entities.

我可以考虑解决此问题的方法.但这只是更多的工作和更多的诡计.

I can think of ways around this. But it's just more work and more trickery.

让我们停一会儿,问一个最重要的问题:为什么?

Let's stop for a moment and ask the most important question: Why?

为什么您要关心查找是否是具有可观察属性的实体?可能是"不需要的开销".但是高昂的费用会伤害到您吗?你怎么疼?你测量了吗?

Why do you care if the lookups are entities with observable properties? It may be "overhead you don't need". But is it overhead that hurts you? Hurts you how? Have you measured it?

请原谅我,但我认为过早的优化可能会分散您对更有价值的追求的注意力.很高兴被证明是错误的.

Forgive me but I sense premature optimizations that could be distracting you from more worthy pursuits. Happy to be proven wrong.

这篇关于防止breeze.js在数组对象上创建observables属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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