0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 23:49:45 -05:00

Reorganize repo code.

This commit is contained in:
Andrey Antukh 2016-04-02 11:53:39 +03:00
parent 299c2bf06c
commit cad95c67a5
11 changed files with 63 additions and 38 deletions

View file

@ -53,7 +53,7 @@
(let [params {:username username
:password password
:scope "webapp"}]
(->> (rp/do :fetch/token params)
(->> (rp/req :fetch/token params)
(rx/catch on-error)
(rx/map :payload)
(rx/mapcat #(rx/of (logged-in %)

View file

@ -39,7 +39,7 @@
(uum/error (tr "errors.fetch-page-history"))
(rx/empty))]
(let [params {:page id :pinned true}]
(->> (rp/do :fetch/page-history params)
(->> (rp/req :fetch/page-history params)
(rx/map on-success)
(rx/catch on-failure))))))
@ -74,7 +74,7 @@
(let [params (merge
{:page id :max (or max 15)}
(when since {:since since}))]
(->> (rp/do :fetch/page-history params)
(->> (rp/req :fetch/page-history params)
(rx/map on-success)
(rx/catch on-failure))))))
@ -211,7 +211,7 @@
(uum/error (tr "errors.page-history-update"))
(rx/empty))]
(rx/merge
(->> (rp/do :update/page-history item)
(->> (rp/req :update/page-history item)
(rx/map on-success)
(rx/catch on-failure))
(->> (rx/filter history-updated? s)

View file

@ -48,7 +48,7 @@
(on-error [err]
(js/console.error err)
(rx/empty))]
(->> (rp/do :fetch/pages-by-project {:project projectid})
(->> (rp/req :fetch/pages-by-project {:project projectid})
(rx/map on-loaded)
(rx/catch on-error)))))
@ -70,7 +70,7 @@
(rx/empty))]
(let [params (-> (into {} this)
(assoc :data {}))]
(->> (rp/do :create/page params)
(->> (rp/req :create/page params)
(rx/mapcat on-created)
(rx/catch on-failed))))))
@ -108,7 +108,7 @@
(uum/error (tr "errors.page-update"))
(rx/empty))]
(let [page (stpr/pack-page state id)]
(->> (rp/do :update/page page)
(->> (rp/req :update/page page)
(rx/map on-success)
(rx/catch on-failure))))))
@ -166,7 +166,7 @@
(on-failure [e]
(uum/error (tr "errors.page-update"))
(rx/empty))]
(->> (rp/do :update/page-metadata (into {} this))
(->> (rp/req :update/page-metadata (into {} this))
(rx/map on-success)
(rx/catch on-failure)))))
@ -191,7 +191,7 @@
(on-failure [e]
(uum/error (tr "errors.delete-page"))
(rx/empty))]
(->> (rp/do :delete/page id)
(->> (rp/req :delete/page id)
(rx/map on-success)
(rx/tap callback)
(rx/filter identity)

View file

@ -62,7 +62,7 @@
#(reduce stpr/assoc-project % projects))
(on-error [err]
(rx/empty))]
(->> (rp/do :fetch/projects)
(->> (rp/req :fetch/projects)
(rx/map on-loaded)
(rx/catch on-error)))))
@ -83,7 +83,7 @@
:data nil))))
(on-failure [err]
(uum/error (tr "errors.create-project")))]
(->> (rp/do :create/project {:name name})
(->> (rp/req :create/project {:name name})
(rx/mapcat on-success)
(rx/catch on-failure)))))
@ -107,7 +107,7 @@
(rs/swap #(stpr/dissoc-project % id)))
(on-failure [e]
(uum/error (tr "errors.delete-project")))]
(->> (rp/do :delete/project id)
(->> (rp/req :delete/project id)
(rx/map on-success)
(rx/catch on-failure)))))

View file

@ -33,7 +33,7 @@
(letfn [(on-error [err]
(uum/error (tr "errors.profile-fetch"))
(rx/empty))]
(->> (rp/do :fetch/profile)
(->> (rp/req :fetch/profile)
(rx/catch on-error)
(rx/map :payload)
(rx/map profile-fetched)))))
@ -50,7 +50,7 @@
(letfn [(on-error [err]
(uum/error (tr "errors.update-profile"))
(rx/empty))]
(->> (rp/do :update/profile data)
(->> (rp/req :update/profile data)
(rx/catch on-error)
(rx/map :payload)
(rx/map profile-fetched)))))
@ -67,7 +67,7 @@
;; (letfn [(on-error [err]
;; (uum/error (tr "errors.update-password"))
;; (rx/empty))]
;; (->> (rp/do :update/password data)
;; (->> (rp/req :update/password data)
;; (rx/catch on-error)))))
(js/alert "Not implemented")
(rx/empty)))

View file

@ -7,16 +7,17 @@
(ns uxbox.repo
"A main interface for access to remote resources."
(:refer-clojure :exclude [do])
(:require [uxbox.repo.core :refer (-do)]
(:require [uxbox.repo.core :refer (request)]
[uxbox.repo.auth]
[uxbox.repo.users]
[uxbox.repo.projects]
[uxbox.repo.pages]
[beicon.core :as rx]))
(defn do
(defn req
"Perform a side effectfull action accesing
remote resources."
([type]
(-do type nil))
(request type nil))
([type data]
(-do type data)))
(request type data)))

View file

@ -8,15 +8,15 @@
"A main interface for access to remote resources."
(:refer-clojure :exclude [do])
(:require [beicon.core :as rx]
[uxbox.repo.core :refer (-do url send!)]
[uxbox.repo.core :refer (request url send!)]
[uxbox.state :as ust]))
(defmethod -do :fetch/profile
(defmethod request :fetch/profile
[type _]
(let [url (str url "/profile/me")]
(send! {:method :get :url url})))
(defmethod -do :fetch/token
(defmethod request :fetch/token
[type data]
(let [url (str url "/auth/token")]
(send! {:url url
@ -24,7 +24,7 @@
:auth false
:body data})))
(defmethod -do :update/profile
(defmethod request :update/profile
[type data]
(let [params {:url (str url "/profile/me")
:method :put

View file

@ -78,9 +78,9 @@
(rx/map conditional-decode)
(rx/mapcat handle-http-status))))
(defmulti -do
(defmulti request
(fn [type data] type))
(defmethod -do :default
(defmethod request :default
[type data]
(throw (ex-info (str "No implementation found for " type) {:data data})))

View file

@ -7,55 +7,55 @@
(ns uxbox.repo.pages
"A main interface for access to remote resources."
(:require [beicon.core :as rx]
[uxbox.repo.core :refer (-do url send!)]
[uxbox.repo.core :refer (request url send!)]
[uxbox.state :as ust]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Login
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmethod -do :fetch/pages
(defmethod request :fetch/pages
[type data]
(send! {:url (str url "/pages") :method :get}))
(defmethod -do :fetch/pages-by-project
(defmethod request :fetch/pages-by-project
[type {:keys [project] :as params}]
(let [url (str url "/projects/" project "/pages")]
(send! {:method :get :url url})))
(defmethod -do :fetch/page-history
(defmethod request :fetch/page-history
[type {:keys [page] :as params}]
(let [url (str url "/pages/" page "/history")
query (select-keys params [:max :since :pinned])]
(send! {:method :get :url url :query query })))
(defmethod -do :delete/page
(defmethod request :delete/page
[_ id]
(let [url (str url "/pages/" id)]
(send! {:url url :method :delete})))
(defmethod -do :create/page
(defmethod request :create/page
[type {:keys [id] :as data}]
(let [params {:url (str url "/pages")
:method :post
:body data}]
(send! params)))
(defmethod -do :update/page
(defmethod request :update/page
[type {:keys [id] :as data}]
(let [params {:url (str url "/pages/" id)
:method :put
:body data}]
(send! params)))
(defmethod -do :update/page-history
(defmethod request :update/page-history
[type {:keys [id page] :as data}]
(let [params {:url (str url "/pages/" page "/history/" id)
:method :put
:body data}]
(send! params)))
(defmethod -do :update/page-metadata
(defmethod request :update/page-metadata
[type {:keys [id] :as data}]
(let [params {:url (str url "/pages/" id "/metadata")
:method :put

View file

@ -7,26 +7,26 @@
(ns uxbox.repo.projects
"A main interface for access to remote resources."
(:require [beicon.core :as rx]
[uxbox.repo.core :refer (-do url send!)]
[uxbox.repo.core :refer (request url send!)]
[uxbox.state :as ust]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Login
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmethod -do :fetch/projects
(defmethod request :fetch/projects
[type data]
(let [url (str url "/projects")]
(send! {:url url :method :get})))
(defmethod -do :create/project
(defmethod request :create/project
[_ data]
(let [params {:url (str url "/projects")
:method :post
:body data}]
(send! params)))
(defmethod -do :delete/project
(defmethod request :delete/project
[_ id]
(let [url (str url "/projects/" id)]
(send! {:url url :method :delete})))

24
src/uxbox/repo/users.cljs Normal file
View file

@ -0,0 +1,24 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2016 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.repo.users
"A main interface for access to remote resources."
(:refer-clojure :exclude [do])
(:require [beicon.core :as rx]
[uxbox.repo.core :refer (request url send!)]
[uxbox.state :as ust]))
(defmethod request :fetch/profile
[type _]
(let [url (str url "/profile/me")]
(send! {:method :get :url url})))
(defmethod request :update/profile
[type data]
(let [params {:url (str url "/profile/me")
:method :put
:body data}]
(send! params)))