协助将JS翻译成CLJS

时间:2013-11-19 22:19:49

标签: javascript clojurescript

我在JS中开发了一个简单的节拍器作为JS练习,也是不需要的。可在此处找到:https://github.com/Greduan/js-metronome/blob/master/js/main.js

我已将其翻译成CLJS:

(ns mies-2.core
  (:use 'createjs.Sound))

(def assetsPath "assets/")
(def manifest [{:src "Click1.ogg|Click1.mp3" :id 1} {:src "Click2.ogg|Click2.mp3" :id 2}])

(.registerManifest createjs/Sound [manifest assetsPath])

(defn stop []
  ((js/clearInterva(intervalID))
   (.stop createjs/Sound [])
   (.log js/console "Stopped sound(s).")))

(defn playSound [target]
  ;                                           v FIX
  ((def instance (.play createjs/Sound [target.id (.INTERRUPT_NONE createjs/Sound []) 0 0 false 1]))
  ;                                 v FIX
  (or (== instance nil) (== instance.playState (.PLAY_FAILED createjs/Sound)) nil)
  (.log js/console ["Played sound ID:" target.id])))

(defn soundLoop [soundID]
  ;                                                             v FIX
  ((def bpmInput (.querySelector js/document ["[name=\"bpm\"]"] .value))
   (def bpm (/ 60000 bpmInput))
   (.log js/console ["Input:" bpmInput "Delay:" bpm])
   (def intervalID (js/setInterval [fn [] (playSound [soundID]) bpm]))))

我在评论FIX时指出了我需要帮助的内容。 :)

基本上是thing.function.value或类似的系统,特别是将document.querySelector('[name="bpm"]').value翻译成CLJS。

变量,有一个variable.value系统,我怎么能用CLJS实现呢?

指出我正确的方向是绰绰有余,非常感激。 :)

1 个答案:

答案 0 :(得分:1)

我已将您的js应用转换为cljs并创建了一个存储库:https://github.com/edbond/cljs-metronome 如果它不适合你,请告诉我。