mirror of
https://github.com/status-im/pluto.git
synced 2025-02-24 16:38:16 +00:00
Simplify storages usage
This commit is contained in:
parent
82df4f6308
commit
83c9755d32
@ -4,27 +4,27 @@
|
|||||||
:documentation "..."}
|
:documentation "..."}
|
||||||
|
|
||||||
lifecycle
|
lifecycle
|
||||||
{:on-activated [@events/fetch-all-posts]}
|
{:on-activated [fetch-all-posts]}
|
||||||
|
|
||||||
events/fetch-all-posts
|
events/fetch-all-posts
|
||||||
[@events/ethereum.logs {:address "0xfa28ec7198028438514b49a3cf353bca5541ce1d"
|
[ethereum.logs {:address "0xfa28ec7198028438514b49a3cf353bca5541ce1d"
|
||||||
:topics ["PeepEth()"]
|
:topics ["PeepEth()"]
|
||||||
:inputs [{:name :hash :type :string}] ;; Allows to decode transaction data
|
:inputs [{:name :hash :type :string}] ;; Allows to decode transaction data
|
||||||
:on-log [@events/fetch-ipfs]}] ;; A map of decoded data will be injected
|
:on-log [@events/fetch-ipfs]}] ;; A map of decoded data will be injected
|
||||||
|
|
||||||
events/fetch-ipfs
|
events/fetch-ipfs
|
||||||
(let [{:keys [hash]} @properties]
|
(let [{hash :hash} properties]
|
||||||
[@queries/ipfs.get {:hash hash
|
[ipfs.get {:hash hash
|
||||||
:on-success [@events/db.append {:path [:all-posts]}]}])
|
:on-success [db.append {:path [:all-posts]}]}])
|
||||||
|
|
||||||
queries/all-posts
|
queries/all-posts
|
||||||
[@queries/db.get {:path [:all-posts]
|
[db.get {:path [:all-posts]
|
||||||
:limit 20}]
|
:limit 20}]
|
||||||
|
|
||||||
views/post
|
views/post
|
||||||
;; TODO get account details
|
;; TODO get account details
|
||||||
;; handle threads
|
;; handle threads
|
||||||
(let [{content :content address :untrustedAddress timestamp :untrustedTimestamp} @properties]
|
(let [{content :content address :untrustedAddress timestamp :untrustedTimestamp} properties]
|
||||||
[view {}
|
[view {}
|
||||||
[view {}
|
[view {}
|
||||||
[text {}
|
[text {}
|
||||||
@ -35,13 +35,13 @@
|
|||||||
content]])
|
content]])
|
||||||
|
|
||||||
views/main
|
views/main
|
||||||
[screen {:style @styles/screen}
|
[screen {:style screen}
|
||||||
[toolbar {}
|
[toolbar {}
|
||||||
[text {}
|
[text {}
|
||||||
[@i18n/title {}]]]
|
[@i18n/title {}]]]
|
||||||
(let [posts @queries/all-posts]
|
(let [posts @queries/all-posts]
|
||||||
[list {:data posts
|
[list {:data posts
|
||||||
:template [@views/post]}])]
|
:template [post]}])]
|
||||||
|
|
||||||
styles/screen
|
styles/screen
|
||||||
{:background-color #?(:android :green
|
{:background-color #?(:android :green
|
||||||
@ -52,5 +52,5 @@
|
|||||||
{:en "Peepeth !!"}
|
{:en "Peepeth !!"}
|
||||||
|
|
||||||
hooks/main.pipelette
|
hooks/main.pipelette
|
||||||
{:view @views/main}}
|
{:view main}}
|
||||||
|
|
||||||
|
@ -3,10 +3,7 @@
|
|||||||
[pluto.components.html :as html]
|
[pluto.components.html :as html]
|
||||||
[pluto.reader :as reader]
|
[pluto.reader :as reader]
|
||||||
[pluto.host :as host]
|
[pluto.host :as host]
|
||||||
[pluto.storage :as storage]
|
[pluto.storages :as storages]
|
||||||
[pluto.storage.http :as http]
|
|
||||||
[pluto.storage.gist :as gist]
|
|
||||||
[pluto.storage.ipfs :as ipfs]
|
|
||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]
|
||||||
[reagent.dom :as dom]
|
[reagent.dom :as dom]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
@ -42,18 +39,6 @@
|
|||||||
[:li
|
[:li
|
||||||
[:span [:b (str type)] (pr-str (dissoc m :type))]]))]))
|
[:span [:b (str type)] (pr-str (dissoc m :type))]]))]))
|
||||||
|
|
||||||
(defn storage-for [type]
|
|
||||||
(condp = type
|
|
||||||
"url" (http/HTTPStorage.)
|
|
||||||
"gist" (gist/GistStorage.)
|
|
||||||
"ipfs" (ipfs/IPFSStorage. "https://cors.io/?https://gateway.ipfs.io")))
|
|
||||||
|
|
||||||
(defn fetch [uri cb]
|
|
||||||
(let [[type id] (string/split uri "@")]
|
|
||||||
(storage/fetch
|
|
||||||
(storage-for type)
|
|
||||||
{:value id} cb)))
|
|
||||||
|
|
||||||
(def hook
|
(def hook
|
||||||
(reify host/AppHook
|
(reify host/AppHook
|
||||||
(id [_] :main)
|
(id [_] :main)
|
||||||
@ -86,4 +71,4 @@
|
|||||||
[s el el-errors]
|
[s el el-errors]
|
||||||
(dom/unmount-component-at-node el)
|
(dom/unmount-component-at-node el)
|
||||||
(dom/unmount-component-at-node el-errors)
|
(dom/unmount-component-at-node el-errors)
|
||||||
(fetch s #(render-result % el el-errors)))
|
(storages/fetch s #(render-result % el el-errors)))
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
<main>
|
<main>
|
||||||
<div id="selection">
|
<div id="selection">
|
||||||
Load demo extension from
|
Load demo extension from
|
||||||
<button disabled onclick="load('ipfs@QmSKP6f2uUsFq4mk1Afe4ZktxwQifrLb4xRQYNE1LxidKz')">IPFS</button>
|
<button onclick="load('ipfs@QmSKP6f2uUsFq4mk1Afe4ZktxwQifrLb4xRQYNE1LxidKz')">IPFS</button>
|
||||||
<button onclick="load('url@assets/extensions/demo')">HTTP</button>
|
<button onclick="load('url@assets/extensions/demo')">HTTP</button>
|
||||||
<button onclick="load('gist@jeluard/1b41c8194c1658e1b6fc0bde4aa6db95')">Gist</button>
|
<button onclick="load('gist@jeluard/1b41c8194c1658e1b6fc0bde4aa6db95')">Gist</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
clojure -A:examples -m cljs.main -O advanced -d website/static/js -o website/static/js/pluto.js -c pluto.examples
|
clojure -A:examples -m cljs.main -O advanced -d website/static/js -o website/static/js/pluto.js -c pluto.examples
|
||||||
cp -R examples/resources/extensions website/static
|
cp -R examples/resources/extensions website/static
|
||||||
|
cp figwheel/resources/public/index.html website/pages/examples.html
|
||||||
cd website
|
cd website
|
||||||
GIT_USER=jeluard\
|
GIT_USER=jeluard\
|
||||||
CURRENT_BRANCH=#2 \
|
CURRENT_BRANCH=#2 \
|
||||||
|
19
src/pluto/storages.cljc
Normal file
19
src/pluto/storages.cljc
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
(ns pluto.storages
|
||||||
|
(:require [clojure.string :as string]
|
||||||
|
[pluto.storage :as storage]
|
||||||
|
[pluto.storage.http :as http]
|
||||||
|
[pluto.storage.gist :as gist]
|
||||||
|
[pluto.storage.ipfs :as ipfs]))
|
||||||
|
|
||||||
|
(def all
|
||||||
|
{"url" (http/HTTPStorage.)
|
||||||
|
"gist" (gist/GistStorage.)
|
||||||
|
"ipfs" (ipfs/IPFSStorage. "https://gateway.ipfs.io")})
|
||||||
|
|
||||||
|
(defn fetch [uri cb]
|
||||||
|
(when (and uri cb))
|
||||||
|
(let [[type id] (string/split uri "@")]
|
||||||
|
(when-let [s (get all type)]
|
||||||
|
(storage/fetch
|
||||||
|
s
|
||||||
|
{:value id} cb))))
|
@ -31,21 +31,24 @@
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
function load(urn) {
|
function load(urn) {
|
||||||
pluto.examples.load_and_render(urn, document.getElementById("frame").contentWindow.document.body.firstChild, document.getElementById("errors"));
|
pluto.examples.load_and_render(urn, document.getElementById("frame").contentWindow.document.body.firstChild, document.getElementById("errors"));
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<main>
|
<main>
|
||||||
<div id="selection">
|
<div id="selection">
|
||||||
Load demo extension from
|
Load demo extension from
|
||||||
<button disabled onclick="load('ipfs:QmSKP6f2uUsFq4mk1Afe4ZktxwQifrLb4xRQYNE1LxidKz')">IPFS</button>
|
<button onclick="load('ipfs@QmSKP6f2uUsFq4mk1Afe4ZktxwQifrLb4xRQYNE1LxidKz')">IPFS</button>
|
||||||
<button onclick="load('url:extensions/demo')">HTTP</button>
|
<button onclick="load('url@assets/extensions/demo')">HTTP</button>
|
||||||
</div>
|
<button onclick="load('gist@jeluard/1b41c8194c1658e1b6fc0bde4aa6db95')">Gist</button>
|
||||||
<div id="extension">
|
</div>
|
||||||
<iframe id="frame" srcdoc="<body><main></main></body>"></iframe>
|
<div id="extension">
|
||||||
</div>
|
<iframe id="frame" srcdoc="<body><main></main></body>"></iframe>
|
||||||
<div id="errors"></div>
|
</div>
|
||||||
</main>
|
<div id="errors"></div>
|
||||||
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
<script src="cljs-out/figwheel/dev-main.js"></script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user