jdorn / json-editor

JSON Schema Based Editor
MIT License
5.81k stars 1.08k forks source link

CommonJS Module #309

Open adius opened 9 years ago

adius commented 9 years ago

It would be cool if json-editor was available as a CommonJS module so that you can require it and use it with browserify.js. Any chance this is going to happen?

rhalff commented 9 years ago

I can confirm the patch of @brettz9 just works, which is great.

Also note that although the package is on npm right now, it does not actually work, it will just return an empty object.

oleics commented 9 years ago

The patch does not work when you want to use json-editor in isomorphic applications as window is hardcoded everywhere in json-editors source and it is impossible to defer access to window to a later point after requireing json-editor.

Something like

var jsonEditorGlobalScope;
if(typeof window !== 'undefined') jsonEditorGlobalScope = window; // browser
elseif(typeof global !== 'undefined') jsonEditorGlobalScope = global; // nodejs / iojs / web worker

and make everything else in json-editor operate on jsonEditorGlobalScope after that can solve this. There are other ways too, for example access window only after a call to JSONEditor().

ATM I'm doing

var JSONEditor;
try {
  require('json-editor');
  JSONEditor = window.JSONEditor;
} catch(ex) {
}

in components using json-editor.

TroyLDay commented 8 years ago

Thanks for the work around!

xvaara commented 8 years ago

Is there any plans on implementing this? It would be nice not to have a customized version in the build process.