factor/extra/webapps/counter/counter.factor

31 lines
821 B
Factor
Raw Normal View History

2008-06-02 16:38:44 -04:00
USING: math kernel accessors http.server http.server.dispatchers
2008-06-02 18:51:06 -04:00
furnace furnace.actions furnace.sessions
2008-06-15 19:29:10 -04:00
html.components html.forms html.templates.chloe
fry urls ;
2008-04-29 06:58:34 -04:00
IN: webapps.counter
SYMBOL: count
TUPLE: counter-app < dispatcher ;
2008-05-26 01:47:27 -04:00
M: counter-app init-session* drop 0 count sset ;
2008-04-29 06:58:34 -04:00
2008-05-26 01:47:27 -04:00
: <counter-action> ( quot -- action )
<action>
swap '[
count , schange
URL" $counter-app" <redirect>
] >>submit ;
2008-04-30 17:12:14 -04:00
2008-04-29 06:58:34 -04:00
: <display-action> ( -- action )
2008-05-26 01:47:27 -04:00
<page-action>
[ count sget "counter" set-value ] >>init
2008-06-02 16:00:03 -04:00
{ counter-app "counter" } >>template ;
2008-04-29 06:58:34 -04:00
: <counter-app> ( -- responder )
counter-app new-dispatcher
[ 1+ ] <counter-action> "inc" add-responder
[ 1- ] <counter-action> "dec" add-responder
<display-action> "" add-responder
<sessions> ;