jsonix icon indicating copy to clipboard operation
jsonix copied to clipboard

Using Jsonix with Dojo

Open erotavlas opened this issue 8 years ago • 0 comments

How do I use this as a module in Dojo? I tried to define a package in my dojoConfig, but realized it will not load anything because it requires a main.js file which is not present in the jsonix library.

packages: [
...
{ name: 'jsonix', location: 'myproject/third_party/jsonix', main:'??' }
...
]

I also tried just to include the script in my page (without require) after loading dojo.js like this

<script src="aimwebforms/third_party/TESTING/Jsonix-min.js"></script>

But I got a multiple define error.

EDIT: I got it to work simply in the browser (no require) after the call to dojo.js by removing all the code below from the end of jsonix-all.js

```

// If the require function exists ...
if (typeof require === 'function') {
	// ... but the define function does not exists
	if (typeof define !== 'function') {
		// Load the define function via amdefine
		var define = require('amdefine')(module);
		// If we're not in browser
		if (typeof window === 'undefined')
		{
			// Require xmldom, xmlhttprequest and fs
			define(["xmldom", "xmlhttprequest", "fs"], _jsonix_factory);
		}
		else
		{
			// We're probably in browser, maybe browserify
			// Do not require xmldom, xmlhttprequest as they'r provided by the browser
			// Do not require fs since file system is not available anyway
			define([], _jsonix_factory);
		}
	}
	else {
		// Otherwise assume we're in the browser/RequireJS environment
		// Load the module without xmldom and xmlhttprequests dependencies
		define([], _jsonix_factory);
	}
}
// If the require function does not exists, we're not in Node.js and therefore in browser environment
else
{
	// Just call the factory and set Jsonix as global.
	var Jsonix = _jsonix_factory().Jsonix;
}

and leaving just this variale at the end

var Jsonix = _jsonix_factory().Jsonix;

However if I wanted to make it work with the module loader of dojo, maybe have to create my own main.js file for Jsonix that returns the object _jsonix_factory().Jsonix;

erotavlas avatar Jul 31 '17 17:07 erotavlas