How do I set an “ENV” variable in EmberJS?

懵懂的女人 提交于 2019-12-22 04:25:11

问题


After updating to EmberJS 0.9.8.1 I now get two warnings:

WARNING: Computed properties will soon be cacheable by default. To enable this
in your app, set `ENV.CP_DEFAULT_CACHEABLE = true`. 

And:

WARNING: The way that the {{view}} helper affects templates is about to change.
...SNIP...  by setting `ENV.VIEW_PRESERVES_CONTEXT = true`.

This may seem like a stupid question, but how do I set these ENV variables? I've tried setting them a few different ways, and none make the WARNING message go away, and nothing in my App breaks either. Does that mean I'm in the clear? Or does it mean I'm not setting the ENV variables correctly?

  1. window.ENV does not exist, so literally doing 'ENV.CP_DEFAULT_CACHEABLE = true' doesn't work
  2. Ember.ENV exists, but is an empty object, and has no Ember.ENV.set method. So I tried doing Ember.ENV.CP_DEFAULT_CACHEABLE = true. Is this the correct way to set an ENV? It, however has no effect on Ember.CP_DEFAULT_CACHEABLE, so that doesn't seem right.
  3. Ember.CP_DEFAULT_CACHEABLE exists, so I've tried doing Ember.CP_DEFAULT_CACHEABLE = true, but this has no effect on Ember.ENV.CP_DEFAULT_CACHEABLE.
  4. I've also tried doing Ember.set('CP_DEFAULT_CACHEABLE', true).

Which (if any) of these is the right way to respond to these warnings? Do they not just do away when you set things based on their pleas? The warnings should probably document this better, or provide feedback that you set them.


回答1:


You have to make sure that the ENV variable is set, before Ember.js is loaded (defined in ember-metal/lib/core.js), see http://jsfiddle.net/pangratz666/jweyf/:

<!doctype html>
<body>
    <script type="text/javascript" >
        ENV = {
            CP_DEFAULT_CACHEABLE: true,
            VIEW_PRESERVES_CONTEXT: true
        };
    </script>
    <script src="http://code.jquery.com/jquery-1.7.2.js"></script>
    <script src="https://github.com/downloads/emberjs/ember.js/ember-0.9.8.1.js"></script>
    ...
</body>



来源:https://stackoverflow.com/questions/10839458/how-do-i-set-an-env-variable-in-emberjs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!