1
votes

I am developing a Single Page Application in Clojurescript, and I want to use TinyMCE as a WYSIWYG editor for certain fields. For space efficiency, I want to eventually minify the project using the google clojure compiler in advanced mode. Since the tinymce dev javascript files seems to be unsuitable for use as an extern file, I'm forced to write my own.

There is one particular function call that I can't get to work. In clojurescript, I call:

(.setContent (.get js/tinymce id) cont)

which I'd imagine would compile to something like:

tinymce.get(id).setContent(cont);

I have tried many different function definitions in my externs, yet I keep getting an error:

TypeError: tinymce.get(...).Tl is not a function

Which tells me setContent gets obscured away by the compiler. My current extern file looks like this:

//all seems to be well here...
var tinymce;
tinymce.get = function(name){};
tinymce.remove = function(node){};
tinymce.init = function(editor){};
tinymce.on = function(name, callback, prepend, extra){};


//tinymce setContent attempts
var tinymce.Editor;
tinymce.Editor.prototype.setContent = function(content){};
tinymce.Editor.setContent = function(content){};
tinymce.get(name).setContent = function(content){};
tinymce.get(name).prototype.setContent = function(content){};

var Editor;
Editor.prototype.setContent = function(content){};
Editor.setContent = function(content){};

Which currently is kind of a throw-everything-against-the-wall-and-see-what-sticks attempt. The object get(name) returns should be in the namespace tinymce.Editor.

Is there a proper way of writing an externs to catch these chained function calls? Or is there a way to rewrite the first code snippet so my externs properly preserve the function names? Thanks in advanced.

1

1 Answers

0
votes

This line:

var tinymce.Editor;

is not syntactically correct in JS:

SyntaxError: missing ; before statement

Remove it and leave this line:

tinymce.Editor.prototype.setContent = function(content){};

This should work fine.

Also you may always fall back to accessing properties via string literals which will never be renamed:

(require '[goog.object :as gobj])
(gobj/get your-object "i-wont-be-renamed")