Browse files

removed discrete propagation

- To achieve discrete propagation behavior, one must only introduce
  values that are guaranteed to be distinct.  Traditionally this is
  achieved with timestamps or some other guaranteed-distinct value.
  If one needs discrete values in Javelin, one may model event streams
  by introducing pairs of [timestamp, value].

  As such, Javelin doesn't need to natively provide support for
  discrete propagation.
  • Loading branch information...
1 parent 1bbd52e commit b76514d34ea1d44dc155108769f466acfb860ce5 @alandipert alandipert committed Mar 18, 2013
@@ -92,34 +92,6 @@ to the value in the cell prior to updating, of course.
-### Continuous vs. Discrete Propagation
-Normally, if the value contained by a cell does not change, nothing
-happens. For instance, `(swap! c identity)` has no effect on input
-cell `c`'s dependents, if any. This behavior, the default, is known as
-**continuous propagation**.
-The `all!` function can be used to mutate a cell and turn on
-**discrete propagation**. All updates will then trigger
-propagation. The `distinct!` function turns off discrete
-propagation. If a formula references a cell that is in discrete
-propagation mode, the dependent formula cell is also put in discrete
-(def a (cell 0))
-(def b (cell (.log js/console a)))
-(all! a) ;; turn on discrete propagation
-(reset! a 0) ;; 0 is printed in the console
-(reset! a 0) ;; 0 is printed in the console again
-(distinct! a) ;; turn off discrete propagation
-(reset! a 0) ;; nothing happens
## License
Copyright (c) Alan Dipert and Micha Niskin. All rights
10 src/cljs/tailrecursion/javelin.cljs
@@ -25,16 +25,6 @@
(def timeout #(.setTimeout js/window %1 %2))
(def interval #(.setInterval js/window %1 %2))
-(defn all! [x]
- (set! (.-always x) true)
- (doseq [c (core/sinks-seq x)] (set! (.-always c) true))
- x)
-(defn distinct! [x]
- (set! (.-always x) false)
- (doseq [c (core/sinks-seq x)] (set! (.-always c) false))
- x)
(defn route*
[msec default]
(let [hash #(.-hash (.-location js/window))
7 src/cljs/tailrecursion/javelin/core.cljs
@@ -33,7 +33,7 @@
(when (seq queue)
(let [next (key (peek queue))
value ((.-thunk next))
- continue? (or (.-always next) (not= value (.-prev next)))
+ continue? (not= value (.-prev next))
reducer #(assoc %1 %2 (.-rank %2))
siblings (pop queue)
children (.-sinks next)]
@@ -44,7 +44,6 @@
(doseq [source (filter cell? (.-sources this))]
(set! (.-sinks source) (disj (.-sinks source) this)))
(set! (.-sources this) (if f (conj (vec sources) f) (vec sources)))
- (set! (.-always this) (some #(.-always %) (filter cell? (.-sources this))))
(doseq [source (filter cell? (.-sources this))]
(set! (.-sinks source) (conj (.-sinks source) this))
(if (> (.-rank source) (.-rank this))
@@ -57,7 +56,7 @@
(set! (.-thunk this) (if f thunk #(deref this)))
(doto this propagate!)))
-(deftype Cell [meta state rank prev sources sinks done always thunk watches]
+(deftype Cell [meta state rank prev sources sinks done thunk watches]
(-meta [this] meta)
@@ -79,7 +78,7 @@
(def input* #(if (cell? %) % (input %)))
(defn input [value]
- (set-formula! (Cell. {} value (next-rank) value [] #{} false false nil {})))
+ (set-formula! (Cell. {} value (next-rank) value [] #{} false nil {})))
(defn lift [f]
(fn [& sources]
13 test/tailrecursion/javelin/test.cljs
@@ -7,7 +7,7 @@
; You must not remove this notice, or any other, from this software.
(ns tailrecursion.javelin.test
- (:require [tailrecursion.javelin :refer [all! distinct!]])
+ (:require tailrecursion.javelin)
(:require-macros [tailrecursion.javelin.macros :refer [mx cell are=]]))
(defn ^:export start []
@@ -61,17 +61,6 @@
(swap! a inc)
(are= 200 @d))
- (let [a (all! (cell 0))
- b (cell (conj ~[] a))]
- (swap! a identity)
- (swap! a identity)
- (are= 0 @a
- [0 0 0] @b)
- (distinct! a)
- (swap! a identity)
- (are= 0 @a
- [0 0 0] @b))
(let [a (cell ((comp inc (comp inc identity)) 123))]
(are= 125 @a))

0 comments on commit b76514d

Please sign in to comment.