Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Remove watches on destroy; add cell-let; cleanup

  • Loading branch information...
commit 2601c7184070b60109dfad0d43e4fc49a2b7ec44 1 parent c916835
@micha micha authored
View
5 README.md
@@ -173,6 +173,11 @@ API functions and macros:
;; Given a cell c containing a seqable value of size n and a function f, returns
;; a sequence of n formula cells such that the ith cell's formula is (f (nth c i)).
+(cell-let [binding-form c] body*)
+;; Given a cell c and a binding form, binds names in the binding form to formula
+;; cells containing the destructured values (these values will update as the
+;; value of c changes) and evaluates the body expressions.
+
(cell-doseq seq-expr body*)
;; Repeatedly executes the body expression(s) for side effects as doseq does.
;; However seq-expr is a single binding-form/collection-cell-expr pair instead
View
4 project.clj
@@ -1,4 +1,4 @@
-(defproject tailrecursion/javelin "3.0.0"
+(defproject tailrecursion/javelin "3.1.0"
:description "A Functional Reactive Programming library for ClojureScript"
:url "https://github.com/tailrecursion/javelin"
:license {:name "Eclipse Public License"
@@ -10,7 +10,7 @@
:repl-options {:init-ns tailrecursion.javelin}
:profiles {:devz {:plugins [[lein-cljsbuild "0.3.2"]
[com.cemerick/clojurescript.test "0.1.0"]]
- :dependencies [[org.clojure/clojurescript "0.0-1934"]]}}
+ :dependencies [[org.clojure/clojurescript "0.0-2138"]]}}
:cljsbuild {:builds
{:test
{:source-paths ["src" "test"]
View
2  script/test
@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+lein with-profile devz cljsbuild once test && test/run.sh
View
11 src/tailrecursion/javelin.clj
@@ -27,6 +27,10 @@
(binding [*print-meta* true]
(read-string (pr-str form))))
+(defn bind-syms [form]
+ (let [sym? #(and (symbol? %) (not= '& %))]
+ (->> form (tree-seq coll? seq) (filter sym?) distinct)))
+
(defn macroexpand* [env form]
(if (seq? form)
(let [ex (a/macroexpand-1 env form)]
@@ -177,9 +181,10 @@
(defmacro defc= ([sym expr] `(def ~sym (cell= ~expr)))
([sym doc expr] `(def ~sym ~doc (cell= ~expr))))
- (defn- bind-syms [form]
- (let [sym? #(and (symbol? %) (not= '& %))]
- (->> form (tree-seq coll? seq) (filter sym?) distinct)))
+ (defmacro cell-let [[bindings c] & body]
+ (let [syms (bind-syms bindings)
+ dcell `(cell= (let [~bindings ~c] [~@syms]))]
+ `(let [[~@syms] (cell-map identity ~dcell)] ~@body)))
(defmacro cell-doseq [[bindings cell] & body]
(let [syms (bind-syms bindings)]
View
1  src/tailrecursion/javelin.cljs
@@ -44,6 +44,7 @@
(defn destroy-cell! [this]
(let [srcs (.-sources this)]
(set! (.-sources this) [])
+ (set! (.-watches this) {})
(doseq [src (filter cell? srcs)]
(set! (.-sinks src) (disj (.-sinks src) this)))))
View
3  test/tailrecursion/javelin/test.cljs
@@ -123,9 +123,6 @@
(is (= @b 1))
(is (= @c 126)))
(testing
- "anonymous cells in formula are destroyed correctly"
- (is (= @u [0 1])))
- (testing
"convert formula cell to input cell"
(set-cell! c :hello)
(is (= c (input? c)))
Please sign in to comment.
Something went wrong with that request. Please try again.