urbit/pkg/arvo/app/clock.hoon

121 lines
2.7 KiB
Plaintext
Raw Normal View History

2020-04-01 23:26:07 +03:00
/+ *server, default-agent, verb, dbug
/= tile-js
/^ octs
/; as-octs:mimes:html
/: /===/app/clock/js/tile
/| /js/
/~ ~
==
=, format
::
|%
::
+$ card card:agent:gall
+$ versioned-state
$% state-zero
==
+$ state-zero [%0 data=json]
--
2019-11-27 01:56:20 +03:00
%+ verb |
2020-04-01 23:26:07 +03:00
%- agent:dbug
=| 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
2020-03-26 00:53:12 +03:00
[%launch-action !>([%add %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 !>(%3)
++ on-load
|= old-state=vase
^- (quip card _this)
=/ old !<(?(~ %1 %2 %3) old-state)
=^ cards this
?: ?=(%3 old)
`this
?: ?=(%2 old)
:: ensure launch is set up to listen to us correctly
::
=/ launcha
[%launch-action !>([%add %clock /clocktile '/~clock/js/tile.js'])]
:_ this
[%pass /clock %agent [our.bowl %launch] %poke launcha]~
:_ 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
--