Skip to content
Browse files

transition was a misleading name, switched to defevent and trigger

Signed-off-by: Chris Granger <ibdknox@gmail.com>
  • Loading branch information...
1 parent 71d708d commit b7fcb525daf98eee7b45eb0ddde9347c00355cf2 @ibdknox committed Apr 9, 2012
Showing with 28 additions and 28 deletions.
  1. +9 −9 README.md
  2. +1 −1 project.clj
  3. +3 −3 src/waltz/macros.clj
  4. +8 −8 src/waltz/state.cljs
  5. +7 −7 src/waltz/transition.cljs
View
18 README.md
@@ -13,7 +13,7 @@ Here's an example using waltz, crate, jayq, and fetch:
[crate.core :as crate]
[fetch.lazy-store :as store])
(:use [jayq.core :only [append $ find show hide inner add-class remove-class]]
- [waltz.state :only [transition]])
+ [waltz.state :only [trigger]])
(:use-macros [waltz.macros :only [in out defstate deftrans]]
[crate.macros :only [defpartial]]))
@@ -35,25 +35,25 @@ Here's an example using waltz, crate, jayq, and fetch:
delay (or (:delay params) 10000)
me (state/machine (:label params))]
- (defstate me :loading
+ (defstate me :loading
(in [] (show $loading))
(out [] (hide $loading)))
(defstate me :normal
- (in [v]
+ (in [v]
(inner $value v)
- (wait delay #(transition me :update))))
+ (wait delay #(trigger me :update))))
- (deftrans me :update []
+ (defevent me :update []
(state/set me :loading)
- (store/latest [:metrics (:metric params)]
- #(transition me :set %)))
+ (store/latest [:metrics (:metric params)]
+ #(trigger me :set %)))
- (deftrans me :set [v]
+ (defevent me :set [v]
(state/unset me :loading)
(state/set me :normal v))
- (transition me :update)
+ (trigger me :update)
(append $container $elem)
me))
View
2 project.clj
@@ -1,3 +1,3 @@
-(defproject waltz "0.1.0-SNAPSHOT"
+(defproject waltz "0.1.0-alpha1"
:description "A ClojureScript library to keep your state in step"
:dependencies [[clojure "1.3.0"]])
View
6 src/waltz/macros.clj
@@ -6,10 +6,10 @@
~@body)]
(waltz.state/add-state ~sm ~name s#)))
-(defmacro deftrans
+(defmacro defevent
[sm name params & body]
- `(waltz.state/add-transition ~sm ~name (fn ~params
- ~@body)))
+ `(waltz.state/add-event ~sm ~name (fn ~params
+ ~@body)))
(defmacro in [sm & body]
(if (second body)
View
16 src/waltz/state.cljs
@@ -20,11 +20,11 @@
:constraints []})
(defn machine [& [n]]
- (atom {:debug true
+ (atom {:debug true
:name (name n)
:current #{}
:states {}
- :transitions {}}))
+ :events {}}))
(defn get-name [sm]
(get-in-sm sm [:name]))
@@ -47,14 +47,14 @@
(defn has-state? [sm state]
(get-in-sm sm [:states state]))
-(defn has-transition? [sm trans]
- (get-in-sm sm [:transitions trans]))
+(defn has-event? [sm trans]
+ (get-in-sm sm [:events trans]))
(defn add-state [sm name v]
(assoc-sm sm [:states name] v))
-(defn add-transition [sm name v]
- (assoc-sm sm [:transitions name] v))
+(defn add-event [sm name v]
+ (assoc-sm sm [:events name] v))
(defn in* [state fn]
(update-in state [:in] conj fn))
@@ -99,9 +99,9 @@
(apply unset sm to-unset context)
(apply set sm to-set context))
-(defn transition [sm ts & context]
+(defn trigger [sm ts & context]
(doseq [trans (->coll ts)]
- (when-let [t (get-in-sm sm [:transitions trans])]
+ (when-let [t (get-in-sm sm [:events trans])]
(let [res (apply t context)]
(debug-log sm "(trans " (str trans) ") -> " (boolean res) " :: context " (pr-str context))))))
View
14 src/waltz/transition.cljs
@@ -1,16 +1,16 @@
(ns waltz.transition
(:require [waltz.history :as history]
- [waltz.state :as state])
- (:use [waltz.state :only [transition debug-log]]))
+ [waltz.state :as state])
+ (:use [waltz.state :only [trigger debug-log]]))
(defn exclude [sm name to-set to-unset]
- (state/add-transition sm name (fn [& args]
- (state/unset sm to-unset)
- (apply state/set sm to-set args))))
+ (state/add-event sm name (fn [& args]
+ (apply state/unset sm to-unset args)
+ (apply state/set sm to-set args))))
(defn by-url [sm]
(let [url (.-location.pathname js/window)]
- (transition sm [:url url])))
+ (trigger sm [:url url])))
(defn by-hash [sm]
(history/listen (fn [e]
@@ -24,6 +24,6 @@
(debug-log sm "hash keyword: " kw)
(debug-log sm "hash changed: " token " :: navigation? " navigation? " :: type " type)
(when navigation?
- (transition sm kw))))))
+ (trigger sm kw))))))

0 comments on commit b7fcb52

Please sign in to comment.
Something went wrong with that request. Please try again.