Skip to content

Commit 1d559b8

Browse files
committed
update readme
1 parent 89eb3da commit 1d559b8

File tree

1 file changed

+22
-36
lines changed

1 file changed

+22
-36
lines changed

readme.md

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,39 @@
55
[![Travis](https://img.shields.io/travis/binaryage/cljs-zones.svg)](https://travis-ci.org/binaryage/cljs-zones)
66
[![Sample Project](https://img.shields.io/badge/project-example-ff69b4.svg)](https://github.com/binaryage/cljs-zones-sample)
77

8-
Magical `binding` which survives async calls (with the help of `bound-fn`).
8+
Magical `binding` macro which survives async calls (with the help of `bound-fn`).
99

1010
### Documentation
1111

12-
You can test it in your browser [with klipse][1].
13-
14-
If you want to test it locally, just do the following:
12+
Example
1513

1614
```clojure
17-
(ns zones.tests.core
18-
(:refer-clojure :exclude [binding get set])
19-
(:require [cljs.test :refer-macros [async deftest testing is use-fixtures]]
20-
[zones.core :refer-macros [binding get set bound-fn* bound-fn] :refer [make-zone default-zone]]))
21-
22-
; -- helpers ----------------------------------------------------------------------------------------------------------------
23-
24-
(defn default-zone-str []
25-
(pr-str default-zone))
26-
27-
(defn print-default-zone [& args]
28-
(apply print (concat args [": " (default-zone-str)])))
29-
30-
; -- T0 ---------------------------------------------------------------------------------------------------------------------
31-
32-
(defn test0 []
33-
(print-default-zone "before")
34-
(binding [v "I'm a dynamically bound value in default zone"]
35-
(print-default-zone "inside")
36-
(js/setTimeout (bound-fn* #(print-default-zone "in async call")) 500))
37-
(print-default-zone "after"))
38-
39-
(deftest T0
40-
(async done
41-
(test0)
42-
(js/setTimeout done 1000)))
15+
(ns zones.test
16+
(:refer-clojure :exclude [binding])
17+
(:require [zones.core :refer-macros [binding bound-fn] :refer [default-zone]]))
18+
19+
(defn print-default-zone [prefix]
20+
(println (str prefix ": " (pr-str default-zone))))
21+
22+
(print-default-zone "before")
23+
(binding [v "I'm a dynamically bound value in default zone"]
24+
(print-default-zone "inside")
25+
(js/setTimeout (bound-fn [] (print-default-zone "in async call")) 500))
26+
(print-default-zone "after")
27+
(println "main done")
4328
```
4429

4530
Prints:
4631

4732
```
48-
Testing zones.tests.core
49-
before : #js {}
50-
inside : #js {:v "I'm a dynamically bound value in default zone"}
51-
after : #js {}
52-
in async call : #js {:v "I'm a dynamically bound value in default zone"}
33+
before: #js {}
34+
inside: #js {:v "I'm a dynamically bound value in default zone"}
35+
after: #js {}
36+
in async call: #js {:v "I'm a dynamically bound value in default zone"}
5337
```
5438

39+
You can play with an example in your browser [with klipse][1].
40+
5541
For more info see [full tests](test/src/tests/zones/tests/core.cljs) and [Travis output](https://travis-ci.org/binaryage/cljs-zones).
5642

57-
[1]: http://app.klipse.tech/?cljs_in.gist=darwin/0de5c18d636d2c1db7b07d3500de51a0&external-libs=%5Bhttps://raw.githubusercontent.com/binaryage/cljs-zones/1089500c677513241b71b1ca1b73566f412eb3ec/src/lib%5D
43+
[1]: http://app.klipse.tech/?cljs_in.gist=darwin/1e31b0c33f1ca0e6e0e475b51f95b424&external-libs=%5Bhttps://raw.githubusercontent.com/binaryage/cljs-zones/v0.1.0/src/lib%5D

0 commit comments

Comments
 (0)