Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set an "ENV" variable in EmberJS?

Tags:

ember.js

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.

like image 740
Seth Avatar asked May 31 '12 18:05

Seth


1 Answers

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>

like image 63
pangratz Avatar answered Oct 13 '22 05:10

pangratz