LightTable使用clojurescript来生成js,而后使用 来处理UIjavascript
clojurescript很是适合作抽象程度很高的页面和编辑逻辑结构设计,html
最近会对总体进行分析整理一个大题的结构图java
程序的入口在lt.objs.app@initnode
能够看到init作了几件事情进行初始化git
(defn init [] (object/raise app :deploy) (object/raise app :pre-init) (object/raise app :init) (object/raise app :post-init) (object/raise app :show))
而操做的对象,app的初始化在: github
(object/object* ::app :tags #{:app :window} :delays 0 :init (fn [this] (ctx/in! :app this))) (def app (object/create ::app))
app是object/object*和object/create一块儿生成的web
(defn object* [name & r] (-> (apply make-object* name r) (store-object*) (handle-redef)))
(defn make-object* [name & r] (let [obj (merge {:behaviors #{} :tags #{} :triggers [] :listeners {} ::type name :children {}} (apply hash-map r))] obj)) (defn store-object* [obj] (add obj) obj)
(defn add [obj] (swap! object-defs assoc (::type obj) obj))
(defn create [obj-name & args] (let [obj (if (keyword? obj-name) (@object-defs obj-name) obj-name) id (or (::id obj) (swap! obj-id inc)) inst (atom (assoc (dissoc obj :init) ::id id :args args :behaviors (set (:behaviors obj)) :tags (set (conj (:tags obj) :object)))) inst (store-inst inst) _ (merge! inst (update-listeners inst)) content (when (:init obj) (apply (:init obj) inst args)) content (if (vector? content) (crate/html content) content) final (merge! inst {:content content})] (add-watch inst ::change (fn [_ _ _ _] (raise inst :object.change))) (raise* inst (trigger->behaviors :object.instant (:tags @inst)) nil) (raise inst :init) inst))
object/object*生成了一个hash-map的对象,对象包含了behavior,tag之类的属性,每一个object对应一个惟一的名字,存在object-defs这个atom对象里,这个object-defs用于记录全部的类对象的定义app
object/create中,先是经过(@object-defs obj-name)来获取object,而后对object作一些建立的工做,ide
inst是instance的缩写,采用了相似javascript里的clone的方式来建立一个object的instancepost