Skip to content

Commit 31120d7

Browse files
committed
Added rackt/react example, updated dockerfile to import rackt, added dockerignore
1 parent 11d085a commit 31120d7

File tree

7 files changed

+64
-1
lines changed

7 files changed

+64
-1
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
examples/*.rkt.js
2+
/node_modules/
3+
/build

Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,24 @@ RUN apt-get update -y --allow-releaseinfo-change \
55
&& apt-get install -y --no-install-recommends xz-utils make \
66
&& apt-get clean
77

8+
RUN apt-get -y install git
9+
810
WORKDIR /app
911
RUN curl -O https://nodejs.org/dist/v18.16.0/node-v18.16.0-linux-x64.tar.xz
1012
RUN tar xvf node-v18.16.0-linux-x64.tar.xz -C .
1113
ENV PATH="/app/node-v18.16.0-linux-x64/bin:${PATH}"
1214
RUN npm install -g js-beautify
1315

1416
COPY . /app/racketscript-playground
17+
RUN cd racketscript-playground && npm install
18+
1519
ENV PATH="/root/.local/share/racket/8.7/bin/:${PATH}"
1620
RUN raco pkg install --auto racketscript
1721

22+
RUN git clone https://github.com/leiDnedyA/rackt \
23+
&& cd rackt && git checkout cdn-import \
24+
&& raco pkg install
25+
1826
WORKDIR /app/racketscript-playground
1927
RUN make build || true
2028
CMD ["make", "run-forever"]

examples/rackt-counter.rkt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#lang racketscript/base
2+
3+
(require rackt)
4+
5+
;;
6+
;; Uses a slightly modified version of the rackt module, a lightweight react wrapper
7+
;; for racketscript.
8+
;; Check it out @ https://github.com/rackt-org/rackt
9+
;;
10+
11+
(define root (#js*.document.createElement #js"div"))
12+
($/:= #js.root.id #js"root")
13+
(#js*.document.body.appendChild root)
14+
15+
(define (header props ..)
16+
(<el "div"
17+
(<el "h1" "React Counter Example")
18+
(<el "p" "A simple counter demo using "
19+
(<el "a" "rackt"
20+
#:props ($/obj [href "https://github.com/rackt-org/rackt"]))
21+
", a react wrapper for racketscript.")))
22+
23+
(define (counter props ..)
24+
(define-values (counter set-counter) (use-state 0))
25+
26+
(<el "div"
27+
(<el header)
28+
(<el "button"
29+
#:props ($/obj [ className "button" ]
30+
[ type "button" ]
31+
[onClick (lambda (_) (set-counter (- counter 1)))])
32+
"- 1")
33+
34+
(<el "span" #:props ($/obj [ className "counter" ]) counter)
35+
36+
(<el "button"
37+
#:props ($/obj [ className "button" ]
38+
[ type "button" ]
39+
[onClick (lambda (_) (set-counter (+ counter 1)))])
40+
"+ 1")))
41+
42+
(render (<el counter) "root")

static/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<li><a class="dropdown-item" href="#example/tetris">Tetris</a></li>
7979
<li><a class="dropdown-item" href="#example/archery">Archery</a></li>
8080
<li><a class="dropdown-item" href="#example/wordle">Wordle</a></li>
81+
<li><a class="dropdown-item" href="#example/rackt-counter">React Counter</a></li>
8182
</ul>
8283
</li>
8384

static/modules/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
window.parent.postMessage('run-iframe-init', window.location.origin);
1111
});
1212
</script>
13+
14+
<script crossorigin src="https://unpkg.com/react@18/umd/react.development.js"></script>
15+
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
1316
</head>
1417

1518
<body>

static/rackt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../build/runtime/rackt

stub.rkt

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
(require racketscript/interop
66
racketscript/browser
77
racketscript/htdp/image
8-
racketscript/htdp/universe)
8+
racketscript/htdp/universe
9+
rackt)
910

1011
;; interop
1112
assoc->object
@@ -55,3 +56,7 @@ vector-member
5556

5657
;; string
5758
string-contains?
59+
60+
;; rackt
61+
<el
62+
render

0 commit comments

Comments
 (0)