Re: Interfacing Cljs with external libs.

2011-08-06 Thread Alen Ribic
Looking at the this line closely from "Advanced Compilation and
Externs" [1]:
"Closure Compiler compilation never changes string literals in your
code, no matter what compilation level you use...
Whenever possible, use dot-syntax property names rather than quoted
strings. Use quoted string property names only when you don't want
Closure Compiler to rename a property at all."

Considering in this case that I don't want the compiler to rename the
property `makeHtml`, I changed the code from dot notation to bracket
notation [2] using the `aget` macro [3].

Dot notation ref

(. (js/Showdown.converter.) makeHtml arg1 arg2)

-> (new q.Showdown.converter).Fb(...)

Bracket notation ref (working)

((aget (js/Showdown.converter.) "makeHtml") arg1 arg2)

-> (new q.Showdown.converter).makeHtml.call(...)


@Michael Fogus: considering that the docs[1] advise the use the dot
notation over bracket notation whenever possible, would you agree that
it would be a better approach to add external libraries to :externs
option [4] specifically when compiled code makes many different
references to external code?
Additionally, IMHO, the dot notation is more concise and idiomatic,
i.e. there is no need to explicitly *get* the property.

-Alen

[1] http://code.google.com/closure/compiler/docs/api-tutorial3.html
[2] ECMA 262 Section 11.2.1 Property Accessors -
http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
[3] The `aget` macro produces a bracket notation based JS call like
so: (new q.Showdown.converter)["makeHtml"]
[4] This ticket will solve this: http://dev.clojure.org/jira/browse/CLJS-10


On Aug 5, 11:00 pm, Michael Fogus  wrote:
> Well, Showdown is not really a namespace right?  It's an object in the
> global environment.  You should be able to grab it via js/Showdown and do
> all kinds of interopey things to it.
>
>  On Aug 5, 2011 4:27 PM, "Alen Ribic"  wrote:
>
>
>
>
>
>
>
> > Thanks Fogus for clearing that up.
>
> > Would a call to a constructor function in a namespace of a third-party
> > library be an exception for the time being? (I can't seem to see a
> > clear way you can express that via `js` namespace.)
>
> > Example:
> >> new Showdown.converter().makeHtml(~{b-txt},~{safe})
> > Showdown is the namespace and the converter function is the
> > constructor.
>
> > -Al
>
> > On Aug 5, 8:57 pm, Fogus  wrote:
> >> To access global JavaScript interop thingies (a technical term) you
> >> should use the `js` namespace.  The use of `js*` should be considered
> >> a bad idea.  It's used in core, but only for very low-level
> >> operations.  It should be considered undocumented and therefore off-
> >> limits (we're working to eliminate its need).
>
> >> Look at code at the following link to see a very simple way to access
> >> global js functions:
>
> >>https://gist.github.com/1127895
>
> >> Let us know if that helps.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Interfacing Cljs with external libs.

2011-08-05 Thread Alen Ribic
> Well, Showdown is not really a namespace right?  It's an object in the
> global environment.  You should be able to grab it via js/Showdown and do
> all kinds of interopey things to it.

Right, I totally agree. Where the problem occurs though in this
particular scenario is when :optimizations is set to `advanced`.

Code:
(. (js/Showdown.converter.) makeHtml b-txt safe)


Code with optimizations set to `simple`:

goog.dom.htmlToDocumentFragment.call(null,(new
goog.global.Showdown.converter).makeHtml(a,"false")
-> working


Code with optimizations set to `advanced`:

vd.call(i,(new q.Showdown.converter).Fb(b,"false")
-> TypeError: Object [object Object] has no method 'Fb'

The makeHtml got renamed to `Fb`.

Isn't this what the Google Closure `externs`[1] compiler flag is meant
to solve? (Also see `load-externs` function in clj/cljs/closure.clj)

-Al

[1] http://code.google.com/closure/compiler/docs/api-tutorial3.html#comptoex


On Aug 5, 11:00 pm, Michael Fogus  wrote:
> Well, Showdown is not really a namespace right?  It's an object in the
> global environment.  You should be able to grab it via js/Showdown and do
> all kinds of interopey things to it.
>
>  On Aug 5, 2011 4:27 PM, "Alen Ribic"  wrote:
>
>
>
>
>
>
>
> > Thanks Fogus for clearing that up.
>
> > Would a call to a constructor function in a namespace of a third-party
> > library be an exception for the time being? (I can't seem to see a
> > clear way you can express that via `js` namespace.)
>
> > Example:
> >> new Showdown.converter().makeHtml(~{b-txt},~{safe})
> > Showdown is the namespace and the converter function is the
> > constructor.
>
> > -Al
>
> > On Aug 5, 8:57 pm, Fogus  wrote:
> >> To access global JavaScript interop thingies (a technical term) you
> >> should use the `js` namespace.  The use of `js*` should be considered
> >> a bad idea.  It's used in core, but only for very low-level
> >> operations.  It should be considered undocumented and therefore off-
> >> limits (we're working to eliminate its need).
>
> >> Look at code at the following link to see a very simple way to access
> >> global js functions:
>
> >>https://gist.github.com/1127895
>
> >> Let us know if that helps.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with
> your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Interfacing Cljs with external libs.

2011-08-05 Thread Michael Fogus
Well, Showdown is not really a namespace right?  It's an object in the
global environment.  You should be able to grab it via js/Showdown and do
all kinds of interopey things to it.

 On Aug 5, 2011 4:27 PM, "Alen Ribic"  wrote:
> Thanks Fogus for clearing that up.
>
> Would a call to a constructor function in a namespace of a third-party
> library be an exception for the time being? (I can't seem to see a
> clear way you can express that via `js` namespace.)
>
> Example:
>> new Showdown.converter().makeHtml(~{b-txt},~{safe})
> Showdown is the namespace and the converter function is the
> constructor.
>
> -Al
>
>
> On Aug 5, 8:57 pm, Fogus  wrote:
>> To access global JavaScript interop thingies (a technical term) you
>> should use the `js` namespace.  The use of `js*` should be considered
>> a bad idea.  It's used in core, but only for very low-level
>> operations.  It should be considered undocumented and therefore off-
>> limits (we're working to eliminate its need).
>>
>> Look at code at the following link to see a very simple way to access
>> global js functions:
>>
>> https://gist.github.com/1127895
>>
>> Let us know if that helps.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Interfacing Cljs with external libs.

2011-08-05 Thread Alen Ribic
Thanks Fogus for clearing that up.

Would a call to a constructor function in a namespace of a third-party
library be an exception for the time being? (I can't seem to see a
clear way you can express that via `js` namespace.)

Example:
> new Showdown.converter().makeHtml(~{b-txt},~{safe})
Showdown is the namespace and the converter function is the
constructor.

-Al


On Aug 5, 8:57 pm, Fogus  wrote:
> To access global JavaScript interop thingies (a technical term) you
> should use the `js` namespace.  The use of `js*` should be considered
> a bad idea.  It's used in core, but only for very low-level
> operations.  It should be considered undocumented and therefore off-
> limits (we're working to eliminate its need).
>
> Look at code at the following link to see a very simple way to access
> global js functions:
>
> https://gist.github.com/1127895
>
> Let us know if that helps.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Interfacing Cljs with external libs.

2011-08-05 Thread Fogus
To access global JavaScript interop thingies (a technical term) you
should use the `js` namespace.  The use of `js*` should be considered
a bad idea.  It's used in core, but only for very low-level
operations.  It should be considered undocumented and therefore off-
limits (we're working to eliminate its need).

Look at code at the following link to see a very simple way to access
global js functions:

https://gist.github.com/1127895

Let us know if that helps.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Interfacing Cljs with external libs.

2011-08-05 Thread Alen Ribic
Currently, you can wrap the JS call in js* like so (js*
"MyLib.doSomething(arg1,arg2)").
So this will pass the compile time without resolving the external lib
calls.

It is worth noting that you may come across an interesting problem
that I did in similar scenario to yours.
If you set the optimizations flag to advanced, the compiler will most
probably rename the external lib function name calls and you'll get an
"... undefined" error at runtime.

In a nutshell, Google Closure Compiler has support for "externs"
option that can be passed in to the compiler/optimizer.
The "externs" option presents the list of JS files to be excluded
during the optimization process, hence no renaming will take places
for those external library members.
An enhancement ticket has been opened for this and I am currently
working on the patch.

Refer to my post here for more detail on this:
http://groups.google.com/group/clojure/browse_thread/thread/2b760a0acb2cbc1e/5e890da90e2bc771

-Alen

--
Science is what you know, philosophy is what you don't know.
-- Bertrand Russell

On Aug 5, 3:00 am, Timothy Baldridge  wrote:
> I'm looking into using clojurescript on our website. However, we have
> several external js libraries that we need to access from
> ClojureScript. Is there a way to execute javascript code from
> ClojureScript and not have the function names resolved at compile
> time?
>
> Basically I want to do:
>
> (foo "test" 1 2)
>
> where foo is a global js function that isn't visible to the
> clojurescript compiler, but will be when the code is loaded in the
> browser.
>
> Timothy
>
> --
> “One of the main causes of the fall of the Roman Empire was
> that–lacking zero–they had no way to indicate successful termination
> of their C programs.”
> (Robert Firth)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Interfacing Cljs with external libs.

2011-08-04 Thread Timothy Baldridge
I'm looking into using clojurescript on our website. However, we have
several external js libraries that we need to access from
ClojureScript. Is there a way to execute javascript code from
ClojureScript and not have the function names resolved at compile
time?

Basically I want to do:

(foo "test" 1 2)

where foo is a global js function that isn't visible to the
clojurescript compiler, but will be when the code is loaded in the
browser.

Timothy

-- 
“One of the main causes of the fall of the Roman Empire was
that–lacking zero–they had no way to indicate successful termination
of their C programs.”
(Robert Firth)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en