Compiler now accepts precompiled instances.
This commit is contained in:
parent
22dffc8fda
commit
df28a1c96b
3 changed files with 60 additions and 23 deletions
|
@ -1,4 +1,4 @@
|
||||||
(ns clojurefx.clojurefx
|
1(ns clojurefx.clojurefx
|
||||||
(:refer-clojure :exclude [atom doseq let fn defn ref dotimes defprotocol loop for send meta with-meta])
|
(:refer-clojure :exclude [atom doseq let fn defn ref dotimes defprotocol loop for send meta with-meta])
|
||||||
(:require [clojure.core.typed :refer :all]
|
(:require [clojure.core.typed :refer :all]
|
||||||
[clojure.core.typed.unsafe :refer [ignore-with-unchecked-cast]]
|
[clojure.core.typed.unsafe :refer [ignore-with-unchecked-cast]]
|
||||||
|
|
|
@ -77,21 +77,24 @@
|
||||||
eval)
|
eval)
|
||||||
(apply dissoc props mandatory))))
|
(apply dissoc props mandatory))))
|
||||||
|
|
||||||
(ann resolv-o-matic [(U String Keyword Symbol Class) -> Class])
|
;; (ann resolv-o-matic [(U String Keyword Symbol Class) -> Class])
|
||||||
(defn resolv-o-matic [thing]
|
;; (defn resolv-o-matic [thing]
|
||||||
(cond
|
;; (cond
|
||||||
(symbol? thing) (ns-resolve (the-ns 'clojurefx.clojurefx) thing)
|
;; (symbol? thing) (ns-resolve (the-ns 'clojurefx.clojurefx) thing)
|
||||||
(keyword? thing) (recur (name thing))
|
;; (keyword? thing) (recur (name thing))
|
||||||
(string? thing) (recur (symbol thing))
|
;; (string? thing) (recur (symbol thing))
|
||||||
:else thing))
|
;; :else thing))
|
||||||
|
|
||||||
(ann compile [(Vec Any) -> Any])
|
(ann compile [(Vec Any) -> Any])
|
||||||
(defn compile [[obj params & other]]
|
(defn compile
|
||||||
(assert (map? params))
|
([args] (compile args []))
|
||||||
(let [obj (build-node (resolv-o-matic obj) params)]
|
([[obj & other] accu]
|
||||||
(if (empty? other)
|
(cond
|
||||||
obj
|
(nil? obj) accu
|
||||||
(flatten (conj (list obj) (compile other))))))
|
(and (empty? other) (empty? accu)) obj
|
||||||
|
(and (empty? (rest other)) (empty? accu)) (build-node obj (first other))
|
||||||
|
(class? obj) (recur (rest other) (conj accu (build-node obj (first other))))
|
||||||
|
:else (recur other (conj accu obj)))))
|
||||||
|
|
||||||
(ann compile-o-matic [Any -> Any])
|
(ann compile-o-matic [Any -> Any])
|
||||||
(defn compile-o-matic [thing]
|
(defn compile-o-matic [thing]
|
||||||
|
@ -101,3 +104,23 @@
|
||||||
thing)
|
thing)
|
||||||
thing))
|
thing))
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(import (javafx.scene.layout VBox)
|
||||||
|
(javafx.scene.control Button ScrollPane Label))
|
||||||
|
|
||||||
|
(def example-graph
|
||||||
|
[VBox {:id "topBox"
|
||||||
|
:children [Button {:id "button"
|
||||||
|
:text "Close"}
|
||||||
|
ScrollPane {:content [Label {:id "label"
|
||||||
|
:text "This rocks."}]}]}])
|
||||||
|
|
||||||
|
(def example-graph2
|
||||||
|
[VBox {:id "topBox"
|
||||||
|
:children [Button {:id "button"
|
||||||
|
:text "Close"}
|
||||||
|
(new javafx.scene.control.Label "Precompiled")
|
||||||
|
Button {:id "button2"
|
||||||
|
:text "OK"}
|
||||||
|
ScrollPane {:content [Label {:id "label"
|
||||||
|
:text "This rocks."}]}]}]))
|
||||||
|
|
|
@ -21,11 +21,25 @@
|
||||||
ScrollPane {:content [Label {:id "label"
|
ScrollPane {:content [Label {:id "label"
|
||||||
:text "This rocks."}]}]}])
|
:text "This rocks."}]}]}])
|
||||||
|
|
||||||
|
(def example-graph2
|
||||||
|
[VBox {:id "topBox"
|
||||||
|
:children [Button {:id "button"
|
||||||
|
:text "Close"}
|
||||||
|
(new javafx.scene.control.Label "Precompiled")
|
||||||
|
Button {:id "button2"
|
||||||
|
:text "OK"}
|
||||||
|
ScrollPane {:content [Label {:id "label"
|
||||||
|
:text "This rocks."}]}]}])
|
||||||
|
|
||||||
(def scene-graph (atom nil))
|
(def scene-graph (atom nil))
|
||||||
|
|
||||||
(facts "Vector compilation"
|
(facts "Vector compilation"
|
||||||
(fact "Simple element"
|
(fact "Simple element"
|
||||||
(type (compile [Label {:text "Hello ClojureFX"}])) => javafx.scene.control.Label)
|
(type (compile [Label {:text "Hello ClojureFX"}])) => javafx.scene.control.Label)
|
||||||
|
(fact "Simple precompiled element"
|
||||||
|
(type (compile [(new Label "Hello Precompiled")])) => javafx.scene.control.Label)
|
||||||
(fact "Nested structure"
|
(fact "Nested structure"
|
||||||
(type (reset! scene-graph (compile example-graph))) => javafx.scene.layout.VBox
|
(type (reset! scene-graph (compile example-graph))) => javafx.scene.layout.VBox
|
||||||
(get-id @scene-graph) => "topBox"))
|
(get-id @scene-graph) => "topBox")
|
||||||
|
(fact "Partially precompiled nested structure"
|
||||||
|
(type (reset! scene-graph (compile example-graph2))) => javafx.scene.layout.VBox))
|
||||||
|
|
Loading…
Reference in a new issue