arohner / scriptjure

a Clojure library for generating javascript
187 stars 15 forks source link

LazySeqs in clj blocks #2

Closed purcell closed 14 years ago

purcell commented 14 years ago

Hi Allen. Thanks so much for scriptjure; it's proving very useful to me.

One of the first things I tried to do was expand data into json in-place using 'clj', and this breaks when the data is in lazy-seqs, as illustrated by the following test.

(deftest test-lazy-seq-expands-to-array-inside-clj
  (let [vals (range 20)]
    (is (= (js (clj vals)) "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]"))))

I see you've commented out the defmethod which fixes this case inside scriptjure.clj -- is there a fundamental danger to this approach? I'd hate to have to use calls to "vec" every time I splice possibly-lazy data into my js, but maybe I'm missing something.

-Steve

purcell commented 14 years ago

FWIW, I've added the above test and uncommented the LazySeq defmethod inside my fork: http://github.com/purcell/scriptjure

arohner commented 14 years ago

Thanks for the report and test!

purcell commented 14 years ago

Thanks for merging! Is there a SNAPSHOT jar somewhere? I saw only 0.1.9 on Clojars.

(So happy to get rid of raw javascript in my app...)

arohner commented 14 years ago

I just pushed 0.1.10 containing the fix. Enjoy.

Edit: I pushed to clojars

purcell commented 14 years ago

Terrific, thanks!

purcell commented 14 years ago

Hey Allen; in fact, I think the jar for 0.1.10 contains the old version of scripture.clj -- the method is still commented out there. Perhaps you did a "lein pom" and then pushed without an intermediate "lein jar"?

arohner commented 14 years ago

Sigh. Sorry, I thought I did do a lein jar. Anyways, I pushed 0.1.11 to clojars, which definitely has the method uncommented.

purcell commented 14 years ago

Needless to say, that worked perfectly. Thanks so much.