Introduced separate pluto-web project

This commit is contained in:
jeluard 2019-01-03 12:23:32 +01:00 committed by Julien Eluard
parent 6b89dbced6
commit 28cdda47b2
19 changed files with 187 additions and 89 deletions

8
Makefile Normal file
View File

@ -0,0 +1,8 @@
.PHONY = tests
dev:
clojure -A:examples
tests:
clojure -A:test-clj
clojure -A:test-cljs

View File

@ -5,7 +5,7 @@
Development requires [Deps and CLI](https://clojure.org/guides/getting_started) tooling installed. Development requires [Deps and CLI](https://clojure.org/guides/getting_started) tooling installed.
Run figwheel using `clojure -A:figwheel`. Run dev mode using `make dev`.
### Tests ### Tests

View File

@ -1,15 +1,14 @@
{:deps {org.clojure/clojure {:mvn/version "1.9.0"} {:deps {org.clojure/clojure {:mvn/version "1.10.0"}
org.clojure/clojurescript {:mvn/version "1.10.439"} org.clojure/clojurescript {:mvn/version "1.10.439"}
org.clojure/tools.reader {:mvn/version "1.3.0"} org.clojure/tools.reader {:mvn/version "1.3.2"}
reagent {:mvn/version "0.8.1"} reagent {:mvn/version "0.8.1"}
re-frame {:mvn/version "0.10.6"}} re-frame {:mvn/version "0.10.6"}}
:paths ["src"] :paths ["src"]
:aliases {:examples {:extra-paths ["examples/src"]} :aliases {:examples {:extra-paths ["pluto-web/src" "target" "test" "examples/src" "examples/resources"]
:figwheel {:extra-paths ["target" "test" "examples/src" "figwheel/resources" "figwheel/src"] :extra-deps {com.bhauman/figwheel-main {:mvn/version "0.2.0"}
:extra-deps {com.bhauman/figwheel-main {:mvn/version "0.1.9"}
com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"} com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}
binaryage/devtools {:mvn/version "0.9.10"}} binaryage/devtools {:mvn/version "0.9.10"}}
:main-opts ["-m" "figwheel.main" "-b" "figwheel/dev" "-r"]} :main-opts ["-m" "figwheel.main" "-b" "examples/dev" "-r"]}
:test-clj {:extra-paths ["test"] :test-clj {:extra-paths ["test"]
:extra-deps {eftest {:mvn/version "0.5.2"}} :extra-deps {eftest {:mvn/version "0.5.2"}}
:main-opts ["-e" "(require,'[eftest.runner,:refer,[find-tests,run-tests]]),(run-tests,(find-tests,\"test\"))"]} :main-opts ["-e" "(require,'[eftest.runner,:refer,[find-tests,run-tests]]),(run-tests,(find-tests,\"test\"))"]}

5
examples/dev.cljs.edn Normal file
View File

@ -0,0 +1,5 @@
^{:watch-dirs ["src" "pluto-web/src" "examples/src"]
:log-file "figwheel-main.log"
:log-level :info}
{:main pluto.figwheel}

View File

@ -1,7 +1,7 @@
(ns pluto.examples (ns pluto.examples
(:require [clojure.string :as string] (:require [pluto.web.components :as components]
[pluto.components.html :as html] pluto.web.events
[pluto.js :as js] pluto.web.queries
[pluto.reader :as reader] [pluto.reader :as reader]
[pluto.reader.hooks :as hooks] [pluto.reader.hooks :as hooks]
[pluto.storages :as storages] [pluto.storages :as storages]
@ -18,38 +18,6 @@
(= "re-frame: overwriting" (first args)) nil (= "re-frame: overwriting" (first args)) nil
:else (apply warn args)))}) :else (apply warn args)))})
(defonce do-timer (js/setInterval #(re-frame/dispatch [:random (zero? (rand-int 2))]) 1000))
(re-frame/reg-event-db
:random
(fn [db [_ b]]
(assoc db :random {:cond? b})))
(re-frame/reg-fx
::alert
(fn [value] (js/alert value)))
(re-frame/reg-event-fx
:alert
(fn [cofx [_ env {:keys [value]}]]
{::alert (str "id = " (:id env) " value = " value)}))
(re-frame/reg-fx
::identity
(fn [{:keys [cb]}] (re-frame/dispatch (cb {:value "Yeahhh"}))))
(re-frame/reg-event-fx
:identity
(fn [cofx [_ env m]]
{::identity m}))
(re-frame/reg-sub
:random-boolean
:random)
(re-frame/reg-sub :extensions/identity
(fn [_ [_ _ {:keys [value]}]] value))
(defn render [h el] (defn render [h el]
(reagent/render (h {:name "Test Extension" (reagent/render (h {:name "Test Extension"
:users [{:nm "Jane"} :users [{:nm "Jane"}
@ -71,7 +39,7 @@
(defn parse [m] (defn parse [m]
(reader/parse {:env {:id "Extension ID"} (reader/parse {:env {:id "Extension ID"}
:capacities {:components html/components :capacities {:components components/all
:queries {'random-boolean :queries {'random-boolean
{:value :random-boolean} {:value :random-boolean}
'identity 'identity

View File

@ -1,6 +0,0 @@
^{:watch-dirs ["src" "figwheel/src" "examples/src"]
;:auto-testing true
:log-file "figwheel-main.log"
:log-level :info}
{:main pluto.figwheel}

5
pluto-web/deps.edn Normal file
View File

@ -0,0 +1,5 @@
{:deps {org.clojure/clojure {:mvn/version "1.10.0"}
org.clojure/clojurescript {:mvn/version "1.10.439"}
reagent {:mvn/version "0.8.1"}
re-frame {:mvn/version "0.10.6"}}
:paths ["src"]}

9
pluto-web/project.clj Normal file
View File

@ -0,0 +1,9 @@
(defproject status-im/pluto-web "0.1.0"
:dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.10.439"]
[org.clojure/tools.reader "1.2.1"]
[reagent "0.8.0"]
[re-frame "0.10.5"]
[binaryage/devtools "0.9.10"]
[day8.re-frame/re-frame-10x "0.3.2"]]
:source-paths ["src"])

View File

@ -0,0 +1,22 @@
(ns pluto.web.components
(:require [re-frame.core :as re-frame]))
(defn view [props & content]
(into [:div props] content))
(defn button [{:keys [on-click]} & content]
(into [:button {:on-click #(re-frame/dispatch (on-click {}))}] content))
(defn text [props & content]
(into [:span props] content))
(def all {'view {:properties {}
:value view
:description ""
:examples []}
'button {:properties {:on-click :event}
:value button
:examples []}
'text {:properties {}
:value text
:examples []}})

View File

@ -0,0 +1,72 @@
(ns pluto.web.core
(:require [reagent.core :as reagent]
[pluto.reader :as reader]
[pluto.reader.hooks :as hooks]
pluto.reader.views
[pluto.web.components :as components]
pluto.web.events
pluto.web.queries))
(defn render [h el]
(reagent/render (h {:name "Test Extension"
:users [{:nm "Jane"}
{:nm "Sue"}]}) el))
(defn errors-list [v]
(fn []
[:div
[:div "Errors"]
(into [:ul]
(for [{:keys [type] :as m} v]
[:li
[:span [:b (str type)] (pr-str (dissoc m :type))]]))]))
(def hook
(reify hooks/Hook
(hook-in [_ id env {:keys [description scope parameters preview short-preview]} cofx])
(unhook [_ id env {:keys [scope]} {:keys [db] :as cofx}])))
(defn parse [m]
(reader/parse {:env {:id "Extension ID"}
:capacities {:components
{'view {:properties {}
:value components/view
:description ""
:examples []}
'button {:properties {:on-click :event}
:value components/button
:examples []}
'text {:properties {}
:value components/text
:examples []}}
:queries {'random-boolean
{:value :random-boolean}
'identity
{:value :extensions/identity :arguments {:value :map}}}
:hooks {:main
{:hook hook
:properties {:view :view}}}
:events {'identity
{:permissions [:read]
:value :identity
:arguments {:cb :event}}
'alert
{:permissions [:read]
:value :alert
:arguments {:value :string}}}}}
m))
(defn render-extension [m el el-errors]
(let [{:keys [data errors]} (parse m)]
(when errors
(render (errors-list errors) el-errors))
(render (get-in data [:hooks :main :demo :parsed :view]) el)))
(defn read-extension [o el el-errors]
(let [{:keys [data errors]} (reader/read (:content o))]
(render-extension data el el-errors)))
(defn render-result [{:keys [type value]} el el-errors]
(case type
:error (set! (.-innerHTML el-errors) value)
(read-extension value el el-errors)))

View File

@ -0,0 +1,18 @@
(ns pluto.web.dev
(:require [reagent.dom :as dom]
[re-frame.loggers :as loggers]
[pluto.storages :as storages]))
(def warn (js/console.warn.bind js/console))
(loggers/set-loggers!
{:warn (fn [& args]
(cond
(= "re-frame: overwriting" (first args)) nil
:else (apply warn args)))})
#_
(defn ^:export load-and-render
[s el el-errors]
(dom/unmount-component-at-node el)
(dom/unmount-component-at-node el-errors)
(storages/fetch s #(render-result % el el-errors)))

View File

@ -0,0 +1,20 @@
(ns pluto.web.events
(:require [re-frame.core :as re-frame]))
(re-frame/reg-fx
::alert
(fn [value] (js/alert value)))
(re-frame/reg-event-fx
:alert
(fn [_ [_ env {:keys [value]}]]
{::alert (str "id = " (:id env) " value = " value)}))
(re-frame/reg-fx
::identity
(fn [{:keys [cb]}] (re-frame/dispatch (cb {}))))
(re-frame/reg-event-fx
:identity
(fn [_ [_ _ m]]
{::identity m}))

View File

@ -0,0 +1,16 @@
(ns pluto.web.queries
(:require [re-frame.core :as re-frame]))
(defonce do-timer (js/setInterval #(re-frame/dispatch [:random (zero? (rand-int 2))]) 1000))
(re-frame/reg-event-db
:random
(fn [db [_ b]]
(assoc db :random {:cond? b})))
(re-frame/reg-sub
:random-boolean
:random)
(re-frame/reg-sub :extensions/identity
(fn [_ [_ _ {:keys [value]}]] value))

View File

@ -1,24 +1,9 @@
(defproject status-im/pluto "iteration-4-7-SNAPSHOT" (defproject status-im/pluto "iteration-4-7-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.9.0"] :dependencies [[org.clojure/clojure "1.9.0"]
[org.clojure/clojurescript "1.10.238"] [org.clojure/clojurescript "1.10.439"]
[org.clojure/tools.reader "1.2.1"] [org.clojure/tools.reader "1.2.1"]
[reagent "0.8.0"] [reagent "0.8.0"]
[re-frame "0.10.5"] [re-frame "0.10.5"]
[binaryage/devtools "0.9.10"] [binaryage/devtools "0.9.10"]
[day8.re-frame/re-frame-10x "0.3.2"]] [day8.re-frame/re-frame-10x "0.3.2"]]
:source-paths ["src"])
:plugins [[lein-cljsbuild "1.1.7"]
[lein-doo "0.1.10"]]
:source-paths ["src"]
:deploy-repositories [["releases" :clojars]
["snapshots" :clojars]]
:cljsbuild {:builds [{:id "tests"
:source-paths ["src" "test"]
:compiler {:output-to "target/testable.js"
:optimizations :none
:cache-analysis false
:target :nodejs
:main "pluto.demo"
:pretty-print true}}]})

View File

@ -1,23 +0,0 @@
(ns pluto.components.html
(:require [re-frame.core :as re-frame]))
(defn view [props & content]
;;(println "VVVVV" content)
(into [:div props] content))
(defn button [{:keys [on-click]} & content]
(into [:button {:on-click #(re-frame/dispatch (on-click {:value "ON CLICK"}))}] content))
(defn text [props & content]
(into [:span props] content))
(def components {'view {:properties {}
:value view
:description ""
:examples []}
'button {:properties {:on-click :event}
:value button
:examples []}
'text {:properties {}
:value text
:examples []}})