[#6736] support multi-extensions store
Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
parent
bc44df32cb
commit
624130e440
2
deps.edn
2
deps.edn
|
@ -11,7 +11,7 @@
|
|||
com.taoensso/timbre {:mvn/version "4.10.0"}
|
||||
hickory {:mvn/version "0.7.1"}
|
||||
com.cognitect/transit-cljs {:mvn/version "0.8.248"}
|
||||
status-im/pluto {:mvn/version "iteration-4-1"}
|
||||
status-im/pluto {:mvn/version "iteration-4-2"}
|
||||
mvxcvi/alphabase {:mvn/version "1.0.0"}
|
||||
rasom/cljs-react-navigation {:mvn/version "0.1.4"}}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:alert
|
||||
(fn [_ [_ {:keys [value]}]]
|
||||
(fn [_ [_ _ {:keys [value]}]]
|
||||
{::alert value}))
|
||||
|
||||
(re-frame/reg-fx
|
||||
|
@ -31,21 +31,23 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:log
|
||||
(fn [_ [_ {:keys [value]}]]
|
||||
(fn [_ [_ _ {:keys [value]}]]
|
||||
{::log value}))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:store/get
|
||||
(fn [db [_ {:keys [key]}]]
|
||||
(get-in db [:extensions-store :collectible key])))
|
||||
:extensions/identity
|
||||
(fn [_ [_ _ {:keys [value]}]]
|
||||
value))
|
||||
|
||||
(re-frame/reg-sub :extensions/identity
|
||||
(fn [_ [_ {:keys [value]}]] value))
|
||||
(re-frame/reg-sub
|
||||
:store/get
|
||||
(fn [db [_ {id :id} {:keys [key]}]]
|
||||
(get-in db [:extensions/store id key])))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:store/put
|
||||
(fn [{:keys [db]} [_ {:keys [key value]}]]
|
||||
{:db (assoc-in db [:extensions-store :collectible key] value)}))
|
||||
(fn [{:keys [db]} [_ {id :id} {:keys [key value]}]]
|
||||
{:db (assoc-in db [:extensions/store id key] value)}))
|
||||
|
||||
(defn- append [acc k v]
|
||||
(let [o (get acc k)]
|
||||
|
@ -53,13 +55,13 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:store/append
|
||||
(fn [{:keys [db]} [_ {:keys [key value]}]]
|
||||
{:db (update-in db [:extensions-store :collectible] append key value)}))
|
||||
(fn [{:keys [db]} [_ {id :id} {:keys [key value]}]]
|
||||
{:db (update-in db [:extensions/store id] append key value)}))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:store/clear
|
||||
(fn [{:keys [db]} [_ {:keys [key]}]]
|
||||
{:db (update-in db [:extensions-store :collectible] dissoc key)}))
|
||||
(fn [{:keys [db]} [_ {id :id} {:keys [key]}]]
|
||||
{:db (update-in db [:extensions/store id] dissoc key)}))
|
||||
|
||||
(defn- json? [res]
|
||||
(when-let [type (get-in res [:headers "content-type"])]
|
||||
|
@ -76,7 +78,7 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:extensions/json-parse
|
||||
(fn [_ [_ m]]
|
||||
(fn [_ [_ _ m]]
|
||||
{::json-parse m}))
|
||||
|
||||
(re-frame/reg-fx
|
||||
|
@ -86,12 +88,12 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:extensions/json-stringify
|
||||
(fn [_ [_ {:keys [value]}]]
|
||||
(fn [_ [_ _ {:keys [value]}]]
|
||||
{::json-stringify value}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
:http/get
|
||||
(fn [_ [_ {:keys [url on-success on-failure timeout]}]]
|
||||
(fn [_ [_ _ {:keys [url on-success on-failure timeout]}]]
|
||||
{:http-raw-get (merge {:url url
|
||||
:success-event-creator
|
||||
(fn [{:keys [body] :as o}]
|
||||
|
@ -104,7 +106,7 @@
|
|||
|
||||
(re-frame/reg-event-fx
|
||||
:ipfs/cat
|
||||
(fn [_ [_ {:keys [hash on-success on-failure]}]]
|
||||
(fn [_ [_ _ {:keys [hash on-success on-failure]}]]
|
||||
{:http-raw-get (merge {:url (str "https://ipfs.infura.io/ipfs/" hash)
|
||||
:success-event-creator
|
||||
(fn [{:keys [status body]}]
|
||||
|
@ -118,7 +120,7 @@
|
|||
|
||||
(re-frame/reg-event-fx
|
||||
:http/post
|
||||
(fn [_ [_ {:keys [url body on-success on-failure timeout]}]]
|
||||
(fn [_ [_ _ {:keys [url body on-success on-failure timeout]}]]
|
||||
{:http-raw-post (merge {:url url
|
||||
:body (clj->js body)
|
||||
:success-event-creator
|
||||
|
@ -144,7 +146,7 @@
|
|||
|
||||
(handlers/register-handler-fx
|
||||
:extensions/arithmetic
|
||||
(fn [_ [_ m]]
|
||||
(fn [_ [_ _ m]]
|
||||
{::arithmetic m}))
|
||||
|
||||
(defn button [{:keys [on-click]} label]
|
||||
|
@ -286,14 +288,14 @@
|
|||
:on-result :event}}}
|
||||
:hooks {:commands commands/command-hook}})
|
||||
|
||||
(defn parse [{:keys [data]}]
|
||||
(defn parse [{:keys [data]} id]
|
||||
(try
|
||||
(reader/parse {:capacities capacities} data)
|
||||
(reader/parse {:capacities capacities :env {:id id}} data)
|
||||
(catch :default e {:errors [{:value (str e)}]})))
|
||||
|
||||
(defn parse-extension [{:keys [type value]}]
|
||||
(defn parse-extension [{:keys [type value]} id]
|
||||
(if (= type :success)
|
||||
(parse (reader/read (:content value)))
|
||||
(parse (reader/read (:content value)) id)
|
||||
{:errors [{:type type :value value}]}))
|
||||
|
||||
(def uri-prefix "https://get.status.im/extension/")
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
(ns status-im.extensions.registry
|
||||
(:refer-clojure :exclude [list])
|
||||
(:require [clojure.string :as string]
|
||||
[pluto.utils :as utils]
|
||||
[pluto.reader.hooks :as hooks]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.accounts.update.core :as accounts.update]
|
||||
|
@ -13,7 +12,7 @@
|
|||
[{:keys [db] :as cofx} hook-fn extension-key]
|
||||
(let [account (get db :account/account)
|
||||
hooks (get-in account [:extensions extension-key :hooks])]
|
||||
(apply utils/merge-fx cofx
|
||||
(apply fx/merge cofx
|
||||
(mapcat (fn [[_ extension-hooks]]
|
||||
(map (fn [[hook-id {:keys [hook-ref parsed]}]]
|
||||
(partial hook-fn (:hook hook-ref) hook-id parsed))
|
||||
|
@ -47,13 +46,11 @@
|
|||
(update-hooks hook-fn extension-key))))
|
||||
|
||||
(fx/defn install
|
||||
[{:keys [db random-id-generator] :as cofx} extension-data]
|
||||
[{:keys [db] :as cofx} extension-data]
|
||||
(let [{:extensions/keys [manage]
|
||||
:account/keys [account]} db
|
||||
{:keys [id url]} manage
|
||||
extension {:id (-> (:value id)
|
||||
(or (random-id-generator))
|
||||
(string/replace "-" ""))
|
||||
{:keys [url]} manage
|
||||
extension {:id (:value url)
|
||||
:name (get-in extension-data ['meta :name])
|
||||
:url (:value url)
|
||||
:active? true}
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
:extensions/load
|
||||
(fn [{:keys [extensions follow-up]}]
|
||||
(doseq [{:keys [url active?]} extensions]
|
||||
(extensions/load-from url #(re-frame/dispatch [follow-up url (extensions/parse-extension %) active?])))))
|
||||
(extensions/load-from url #(re-frame/dispatch [follow-up url (extensions/parse-extension % url) active?])))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:extensions/stage
|
||||
|
|
Loading…
Reference in New Issue