Skip to content

Commit

Permalink
Re frame 1.0.0 (#98)
Browse files Browse the repository at this point in the history
* re-frame 1.0.0

* Latest expound

* Noisy logging no longer a problem in re-frame 1.0

* Using new re-frame api for global interceptors

* 1.0 version range

* re-frame 1.0 final

* Branch-specific version to avoid confusion

* Logging for app debugging

* Missing require
  • Loading branch information
ingesolvoll authored Oct 14, 2020
1 parent 06122a4 commit dfe5acb
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 72 deletions.
8 changes: 4 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
(defproject kee-frame "0.4.1-SNAPSHOT"
(defproject kee-frame "1.0.0-re-frame-1.0.0"
:description "A micro-framework on top of re-frame"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:url "https://github.com/ingesolvoll/kee-frame"
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.10.1"]
[org.clojure/clojurescript "1.10.597"]
[re-frame "0.12.0"]
[re-frame "1.0.0"]
[re-chain "1.1"]
[metosin/reitit-core "0.4.2"]
[metosin/reitit-core "0.5.6"]
[day8.re-frame/http-fx "v0.2.0"]
[cljs-ajax "0.8.0"]
[com.taoensso/timbre "4.10.0"]
[venantius/accountant "0.2.5"]
[org.clojure/core.match "1.0.0"]
[expound "0.8.4"]
[expound "0.8.5"]
[day8.re-frame/test "0.1.5"]
[breaking-point "0.1.2"]
[pez/clerk "1.0.0"]]
Expand Down
17 changes: 12 additions & 5 deletions src/kee_frame/controller.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,30 @@

(defn validate-and-dispatch! [dispatch]
(when dispatch
(log/debug "Dispatch returned from function " dispatch)
(if (map? dispatch)
[::fsm/start dispatch]
(do
(log/debug "Starting fsm from controller " dispatch)
[::fsm/start dispatch])
(do
(when-not (s/valid? ::spec/event-vector dispatch)
(e/expound ::spec/event-vector dispatch)
(throw (ex-info "Invalid dispatch value"
(s/explain-data ::spec/event-vector dispatch))))
dispatch))))

(defn stop-controller [ctx {:keys [id stop]}]
(log/debug "Stopping controller: " id)
(defn stop-controller [ctx {:keys [stop] :as controller}]
(log/debug {:type :controller-stop
:controller controller
:ctx ctx})
(cond
(vector? stop) stop
(ifn? stop) (validate-and-dispatch! (stop ctx))))

(defn start-controller [ctx {:keys [id last-params start]}]
(log/debug "Starting controller: " id)
(defn start-controller [ctx {:keys [last-params start] :as controller}]
(log/debug {:type :controller-start
:controller controller
:ctx ctx})
(when start
(cond
(vector? start) (conj start last-params)
Expand Down
5 changes: 2 additions & 3 deletions src/kee_frame/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
[re-chain.core :as chain]
[re-frame.core :as rf :refer [console]]
[kee-frame.log :as log]
[kee-frame.spec :as spec :refer [spec-interceptor]]
[kee-frame.spec :as spec]
[kee-frame.event-logger :as event-logger]
[kee-frame.interceptors :as i]
[clojure.spec.alpha :as s]
[expound.alpha :as e]))

;; Interceptors used by all chains and events registered through kee-frame
(def kee-frame-interceptors [i/add-global-interceptors (spec-interceptor state/app-db-spec) event-logger/interceptor rf/trim-v])
(def kee-frame-interceptors [event-logger/interceptor rf/trim-v])

(def valid-option-key? #{:router :hash-routing? :routes :process-route :debug? :debug-config
:chain-links :app-db-spec :root-component :initial-db
Expand Down
32 changes: 16 additions & 16 deletions src/kee_frame/fsm/alpha.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
(:require [clojure.spec.alpha :as s]
[re-frame.core :as f]
[kee-frame.interop :as interop]
[kee-frame.interceptors :as i]
[taoensso.timbre :as log]
#?(:cljs [reagent.core :as r])))

(defn reg-no-op
"Convenience function for declaring no-op events."
[id]
(f/reg-event-fx id
[i/add-global-interceptors]
(constantly nil)))
(f/reg-event-fx id (constantly nil)))

(defn find-transition
"Try to find a transition that matches some subset of the received event"
Expand All @@ -25,13 +22,16 @@
there is a valid transition, `nil` otherwise. Event transition
`:when` clause is optionally applied."
[transitions event]
(when-let [transition (find-transition transitions event)]
(if-let [transition (find-transition transitions event)]
(let [{next-state :to
dispatch :dispatch} transition]
(when dispatch
(doseq [e dispatch]
(f/dispatch e)))
next-state)))
next-state)
(log/trace {:type :fsm-transition-missed
:transitions transitions
:event event})))

(defn foreign-event? [fsm-id [event-id _ event-fsm-id]]
(and (#{::on-enter ::timeout} event-id)
Expand Down Expand Up @@ -103,19 +103,19 @@
(f/dispatch [::stop fsm]))
(assoc-in db [id state-attr] (or next-state current-state start))))


(f/reg-fx ::start
(fn [{:keys [id] :as fsm}]
(let [timeouts* (atom nil)
state->timeouts (compile-timeouts fsm)]
(->> (partial advance fsm timeouts* state->timeouts)
f/enrich
(i/reg-global-interceptor id)))))
(fn [{:keys [id] :as fsm}]
(let [timeouts* (atom nil)
state->timeouts (compile-timeouts fsm)]
(-> (partial advance fsm timeouts* state->timeouts)
f/enrich
(assoc :id id)
(f/reg-global-interceptor)))))

(f/reg-fx ::stop
(fn [{:keys [id]}]
(when id
(i/clear-global-interceptor id))))
(fn [{:keys [id]}]
(when id
(f/clear-global-interceptor id))))

(f/reg-event-fx ::start
;; Starts the interceptor for the given fsm.
Expand Down
27 changes: 0 additions & 27 deletions src/kee_frame/interceptors.cljc

This file was deleted.

9 changes: 1 addition & 8 deletions src/kee_frame/log.cljc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(ns kee-frame.log
(:require [re-frame.core :as rf]
[re-frame.loggers :as rfl]
[taoensso.timbre :as log]))

(def config
Expand All @@ -15,10 +14,4 @@
(rf/reg-fx :log
(fn [[level & vargs :as arg]]
(when arg
(log/log level vargs))))

#?(:cljs
(rfl/set-loggers!
{:warn (fn [& args]
(when-not (re-find #"^re-frame: overwriting" (first args))
(apply js/console.warn args)))}))
(log/log level vargs))))
5 changes: 4 additions & 1 deletion src/kee_frame/router.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
[kee-frame.event-logger :as event-logger]
[kee-frame.api :as api :refer [dispatch-current! navigate! url->data data->url]]
[kee-frame.interop :as interop]
[kee-frame.spec :as spec]
[kee-frame.state :as state]
[kee-frame.scroll :as scroll]
[kee-frame.controller :as controller]
[reitit.core :as reitit]
[clojure.string :as str]
[clojure.spec.alpha :as s]
[expound.alpha :as e]
[re-frame.core :as f]
[clojure.set :as set]))

(def default-chain-links [{:effect-present? (fn [effects] (:http-xhrio effects))
Expand Down Expand Up @@ -119,7 +121,8 @@
:or {scroll true}
:as config}]
(deprecations config)
(reset! state/app-db-spec app-db-spec)
(when app-db-spec
(f/reg-global-interceptor (spec/spec-interceptor app-db-spec)))
(chain/configure! (concat default-chain-links
chain-links))

Expand Down
6 changes: 3 additions & 3 deletions src/kee_frame/spec.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
(log-spec-error new-db db-spec)
(assoc-effect context :db (get-coeffect context :db))))

(defn spec-interceptor [db-spec-atom]
(defn spec-interceptor [db-spec]
(->interceptor
:id :spec
:after (fn [context]
(let [new-db (get-effect context :db)]
(if (and @db-spec-atom new-db (not (s/valid? @db-spec-atom new-db)))
(rollback context new-db @db-spec-atom)
(if (and new-db (not (s/valid? db-spec new-db)))
(rollback context new-db db-spec)
context)))))
5 changes: 0 additions & 5 deletions src/kee_frame/state.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@

(def navigator (atom nil))

(def app-db-spec (atom nil))

(def debug? (atom false))

(def debug-config (atom nil))

(def fsm-interceptors (atom {}))

(def breakpoints-initialized? (atom false))

;; Test utility
(defn reset-state! []
(reset! controllers {})
(reset! fsm-interceptors {})
(reset! router nil)
(reset! navigator nil))

0 comments on commit dfe5acb

Please sign in to comment.