How do I use uncompressed files in Dojo 1.7?

匿名 (未验证) 提交于 2019-12-03 08:56:10

问题:

I've created a Dojo module which depends on dojox/data/JsonRestStore like this:

define("my/MyRestStore",      ["dojo/_base/declare", "dojox/data/JsonRestStore"],      function(declare, JsonRestStore) {  var x = new JsonRestStore({     target: '/items',     identifier: 'id' });  ... 

which is fine. But now I want to have the the uncompressed version of the JsonRestStore code loaded so that I can debug it. I can't find any documentation on how to do this, but since there is a file called 'JsonRestStore.js.uncompressed.js' I changed my code to:

define("my/MyRestStore",      ["dojo/_base/declare", "dojox/data/JsonRestStore.js.uncompressed"],      function(declare, JsonRestStore) { ... 

thinking that might work.

I can see the JsonRestStore.js.uncompressed.js file being loaded in FireBug, but I get an error when trying to do new JsonRestStore:

JsonRestStore is not a constructor 

Should this work?

Is there a way of configuring Dojo to use uncompressed versions of all modules? That's what I really want, but will settle for doing it on a per dependency basis if that's the only way.

Update

I've found a way to achieve what I want to do: rename the JsonRestStore.js.uncompressed.js file to JsonRestStore.js.

However, this seems a bit like a hacky workaround so I'd still be keen to know if there is a better way (e.g. via configuration).

回答1:

You have two options

1) Create a custom build. The custom build will output a single uncompressed file that you can use for debugging. Think the dojo.js.uncompressed.js but it includes all the extra modules that you use.

OR

2) For a development environment, use the dojo source code. This means downloading the Dojo Toolkit SDK and referencing dojo.js from that in the development environment.

For the projects I work on, I do both. I set up the Dojo configuration so that it can be dynamic and I can change which configuration that I want using a query string parameter.

When I am debugging a problem, I will use the first option just to let me step through code and see what is going on. I use the second option when I am writing some significant js and don't want the overhead of the custom build to see my changes.

I describe this a bit more at

http://swingingcode.blogspot.com/2012/03/dojo-configurations.html



回答2:

I think the reason for this is due to the fact that the loader declares its class-loads (modules), by the file conventions used. The 1.7 loader is not too robust just yet, ive had similar problems until realizing how to separate the '.' and '/' chars.

Its only a qualified guess; but i believe it has to do with the interpretation of '.' character in the class-name which signifies as a sub-namespace and not module name.

The 'define(/ * BLANK * / [ / * DEPENDENCIES * / ], ...)' - where no first string parameter is given - gets loaded by the filename (basename). The returned declare also has a saying though. So, for your example with jsonrest, its split/parsed as such:

toplevel = dojox mid = data modulename = JsonRestStore.js.uncompressed 

(Fail.. Module renders as dojox.data.JsonRestStore.js.uncompressed, not dojox.data.JsonRestStore as should).

So, three options;

  1. Load uncomressed classes through <script src="{{dataUrl}}/dojox/data/JsonRestStore.js.uncompressed.js"></script> and work them on dojo.ready
  2. I think modifying the define([], function(){}) in uncompressed.js to define("JsonRestStore", [], function() {}) would do the trick (uncomfirmed)
  3. Use the dojo/text loader, see below

Text filler needed :)

define("my/MyRestStore",      ["dojo/_base/declare", "dojo/text!dojox/data/JsonRestStore.js.uncompressed.js"],      function(declare, JsonRestStore) { ...         JsonRestStore = eval(JsonRestStore);         // not 100% sure 'define' returns reference to actual class,          // if above renders invalid, try access through global reference, such as         // dojox.dat... 


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