shrub/pkg/arvo/app/clock.hoon

108 lines
2.4 KiB
Plaintext
Raw Normal View History

/+ *server, default-agent, verb
/* tile %js /app/clock/js/tile/js
=/ as-octs as-octs:mimes:html
=/ tile-js (as-octs tile)
=, format
::
|%
::
+$ card card:agent:gall
+$ versioned-state
$% state-zero
==
+$ state-zero [%0 data=json]
--
2019-11-27 01:56:20 +03:00
%+ verb |
=| state-zero
=* state -
2019-11-19 07:36:21 +03:00
^- agent:gall
|_ =bowl:gall
2019-11-09 23:22:59 +03:00
+* this .
def ~(. (default-agent this %|) bowl)
::
++ on-init
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _this)
2019-11-09 23:22:59 +03:00
=/ launcha
[%launch-action !>([%clock /clocktile '/~clock/js/tile.js'])]
2019-11-09 23:22:59 +03:00
:_ this
:~ [%pass / %arvo %e %connect [~ /'~clock'] %clock]
[%pass /clock %agent [our.bowl %launch] %poke launcha]
==
:: bootstrapping to get %goad started OTA
::
++ on-save !>(%2)
++ on-load
|= old-state=vase
=/ old !<(?(~ %1 %2) old-state)
=^ cards this
?: ?=(%2 old)
`this
:_ this :_ ~
[%pass /behn %arvo %b %wait +(now.bowl)]
::
[cards this]
::
2019-11-09 23:22:59 +03:00
++ on-poke
|= [=mark =vase]
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _this)
|^
?: ?=(%json mark)
(poke-json !<(json vase))
?. ?=(%handle-http-request mark)
2019-11-09 23:22:59 +03:00
(on-poke:def mark vase)
=+ !<([eyre-id=@ta =inbound-request:eyre] vase)
2019-11-09 23:22:59 +03:00
:_ this
%+ give-simple-payload:app eyre-id
2019-11-09 23:22:59 +03:00
%+ require-authorization:app inbound-request
|= =inbound-request:eyre
=/ request-line (parse-request-line url.request.inbound-request)
=/ back-path (flop site.request-line)
=/ name=@t
=/ back-path (flop site.request-line)
?~ back-path
''
i.back-path
::
?~ back-path
not-found:gen
?: =(name 'tile')
(js-response:gen tile-js)
not-found:gen
::
++ poke-json
|= jon=json
^- (quip card:agent:gall _this)
=. data.state jon
:_ this
[%give %fact ~[/clocktile] %json !>(jon)]~
--
::
++ on-watch
|= =path
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _this)
?: ?=([%http-response *] path)
`this
?. =(/clocktile path)
(on-watch:def path)
[[%give %fact ~ %json !>(data.state)]~ this]
::
++ on-leave on-leave:def
++ on-peek on-peek:def
++ on-agent on-agent:def
++ on-arvo
|= [=wire =sign-arvo]
2019-11-19 07:36:21 +03:00
^- (quip card:agent:gall _this)
?: ?=(%wake +<.sign-arvo)
?^ error.sign-arvo
:_ this :_ ~
[%pass /dill %arvo %d %flog %crud %clock-fail u.error.sign-arvo]
:_ this :_ ~
[%pass /gall %arvo %g %goad | `%hood]
::
?. ?=(%bound +<.sign-arvo)
(on-arvo:def wire sign-arvo)
[~ this]
::
++ on-fail on-fail:def
--