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