Clojurescript re-mount module, that takes care of setting up IPFS instance for working with re-frame-ipfs-fx.
Add
into your project.clj
Include [district.ui.ipfs]
in your CLJS file, where you use mount/start
Warning: district0x modules are still in early stages, therefore API can change in a future.
This namespace contains ipfs mount module. Once you start mount, it'll take care of ipfs initialisation and will put results into re-frame db.
You can pass following args to initiate this module:
:host
IPFS host that will be used for IPFS calls.:endpoint
Endpoint at host for IPFS calls(ns my-district.core
(:require [mount.core :as mount]
[re-frame.core :refer [reg-event-fx dispatch trim-v]]
[district.ui.ipfs]))
(-> (mount/with-args
{:ipfs {:host "https://ipfs.io" :endpoint "/api/v0"}})
(mount/start))
(reg-event-fx
::list-files
[trim-v]
(fn [_ [url]]
{:ipfs/call {:func "ls"
:args [url]
:on-success [::on-list-files-success]
:on-error [::error]}}))
(dispatch [::list-files "/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/"])
re-frame subscriptions provided by this module:
::ipfs
Returns IPFS configuration.
(ns my-district.home-page
(:require [district.ui.ipfs.subs :as ipfs-subs]
[re-frame.core :refer [subscribe]]))
(defn home-page []
(let [ipfs (subscribe [::ipfs-subs/ipfs])]
(fn []
[:div "Using IPFS host: " (:host @ipfs) " endpoint: " (:endpoint @ipfs)])))
re-frame events provided by this module:
::start [opts]
Initiates IPFS instance. Same as passing config options to mount.
DB queries provided by this module:
You should use them in your events, instead of trying to get this module's
data directly with get-in
into re-frame db.
ipfs [db]
Returns IPFS configuration.
(ns my-district.events
(:require [district.ui.ipfs.queries :as ipfs-queries]
[re-frame.core :refer [reg-event-fx]]))
(reg-event-fx
::my-event
(fn [{:keys [:db]}]
(if (= "http://127.0.0.1:5001" (:host (ipfs-queries/ipfs db))
{:dispatch [::do-something]}
{:dispatch [::do-other-thing]}))))
lein deps
# To run tests and rerun on changes
lein doo chrome tests
Can you improve this documentation? These fine people already did:
Filip Bielejec & madvasEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close