]> gitweb.factorcode.org Git - factor.git/blob - extra/webapps/counter/counter.factor
a14d6d98235b1bfc212d872e1f76988dfd15597c
[factor.git] / extra / webapps / counter / counter.factor
1 USING: math kernel accessors http.server http.server.dispatchers
2 furnace furnace.actions furnace.sessions furnace.redirection
3 html.components html.forms html.templates.chloe
4 fry urls ;
5 IN: webapps.counter
6
7 SYMBOL: count
8
9 TUPLE: counter-app < dispatcher ;
10
11 M: counter-app init-session* drop 0 count sset ;
12
13 : <counter-action> ( quot -- action )
14     <action>
15         swap '[
16             count , schange
17             URL" $counter-app" <redirect>
18         ] >>submit ;
19
20 : <display-action> ( -- action )
21     <page-action>
22         [ count sget "counter" set-value ] >>init
23         { counter-app "counter" } >>template ;
24
25 : <counter-app> ( -- responder )
26     counter-app new-dispatcher
27         [ 1+ ] <counter-action> "inc" add-responder
28         [ 1- ] <counter-action> "dec" add-responder
29         <display-action> "" add-responder
30     <sessions> ;