我还可以将 PromiseProxyMixin 与 Ember.Controller 一起使用吗?

Can I still use PromiseProxyMixin with Ember.Controller?

Ember 文档将 PromiseProxyMixin 描述为:

A low level mixin making ObjectProxy, ObjectController or ArrayControllers promise-aware.

(注意没有提到Controller。)

我一直在 ModalController 中使用 PromiseProxyMixin,它最初是从 Ember.ObjectController 扩展而来的。

现在 ObjectController 已弃用 (Ember 1.11),我已将此控制器转换为扩展 Ember.Controller,它不再按预期工作。

具体来说,返回到 promise 属性 的对象的属性不会在 Controller 中自动设置(就像在 ObjectController 中一样)。

我的 isFulfilled 观察者仍在触发,但未设置应该从返回的对象中合并的属性。

文档还指出:

As the controller is an ObjectController, and the json now its content, all the json properties will be available directly from the controller.

所以我想从现在开始我只需要手动设置这些属性?

PromiseProxyMixin 尚未弃用,并在其他上下文中使用。 git 上的 current API docs 没有提到控制器。你看的措辞已经改变,我认为继续使用是安全的。

As the proxy is an ObjectProxy, and the json now its content, all the json properties will be available directly from the proxy.

// Assuming the following json:
{
  firstName: 'Stefan',
  lastName: 'Penner'
}
// both properties will accessible on the proxy
proxy.get('firstName') //=> 'Stefan'
proxy.get('lastName')  //=> 'Penner'

因为 Promise 返回的属性合并不再自动发生,我的选择似乎是:

  1. Controller转换回ObjectController(方向错误)
  2. 手动合并 Promise 返回的对象的属性(如果我在通用 MyProxyMixin 或类似的情况下这样做可能有意义)
  3. Controller 转换为 ObjectProxy(不确定)
  4. 使用Ember的ProxyMixin

我更喜欢#4,但是围绕这个 mixin 有一些波动(它作为 Ember.FEATURE 启用了一段时间,但似乎又被设为私有了。)

最终我选择了#2。 (我刚刚更新了我的代码以将我需要的属性复制到 Controller。)