shrub/pkg/garden/app/settings-store.hoon

203 lines
5.0 KiB
Plaintext
Raw Normal View History

2021-01-12 23:36:30 +03:00
/- *settings
/+ verb, dbug, default-agent, agentio
2021-01-12 23:36:30 +03:00
|%
+$ card card:agent:gall
+$ versioned-state
$% state-0
state-1
2021-09-09 03:41:39 +03:00
state-2
2021-01-12 23:36:30 +03:00
==
2021-02-25 04:28:26 +03:00
+$ state-0 [%0 settings=settings-0]
2021-09-09 03:41:39 +03:00
+$ state-1 [%1 settings=settings-1]
+$ state-2 [%2 =settings]
2021-01-12 23:36:30 +03:00
--
2021-09-09 03:41:39 +03:00
=| state-2
2021-01-12 23:36:30 +03:00
=* state -
::
%- agent:dbug
%+ verb |
^- agent:gall
=<
|_ bol=bowl:gall
+* this .
do ~(. +> bol)
def ~(. (default-agent this %|) bol)
io ~(. agentio bol)
2021-01-12 23:36:30 +03:00
::
++ on-init on-init:def
2021-01-12 23:36:30 +03:00
::
++ on-save !>(state)
::
++ on-load
|= =old=vase
^- (quip card _this)
=/ old !<(versioned-state old-vase)
|-
2021-01-12 23:36:30 +03:00
?- -.old
2021-02-25 04:28:26 +03:00
%0 $(old [%1 +.old])
2021-09-29 12:38:42 +03:00
%1 $(old [%2 (~(put by *^settings) %landscape settings.old)])
2021-09-09 03:41:39 +03:00
%2 `this(state old)
2021-01-12 23:36:30 +03:00
==
::
++ on-poke
|= [mar=mark vas=vase]
^- (quip card _this)
?> (team:title our.bol src.bol)
?. ?=(%settings-event mar)
(on-poke:def mar vas)
=/ evt=event !<(event vas)
=^ cards state
?- -.evt
2021-09-09 03:41:39 +03:00
%put-bucket (put-bucket:do [desk key bucket]:evt)
%del-bucket (del-bucket:do [desk key]:evt)
%put-entry (put-entry:do [desk buc key val]:evt)
%del-entry (del-entry:do [desk buc key]:evt)
2021-01-12 23:36:30 +03:00
==
[cards this]
::
++ on-watch
|= pax=path
^- (quip card _this)
?> (team:title our.bol src.bol)
?+ pax (on-watch:def pax)
[%all ~]
[~ this]
2021-09-09 04:35:57 +03:00
::
[%desk @ ~]
=* desk i.t.pax
[~ this]
2021-01-12 23:36:30 +03:00
::
2021-09-09 03:41:39 +03:00
[%bucket @ @ ~]
=* desk i.t.pax
=* bucket-key i.t.t.pax
?> (~(has bi settings) desk bucket-key)
2021-01-12 23:36:30 +03:00
[~ this]
::
2021-09-09 03:41:39 +03:00
[%entry @ @ @ ~]
=* desk i.t.pax
=* bucket-key i.t.t.pax
=* entry-key i.t.t.t.pax
=/ bucket (~(got bi settings) desk bucket-key)
2021-01-12 23:36:30 +03:00
?> (~(has by bucket) entry-key)
[~ this]
==
::
++ on-peek
|= pax=path
^- (unit (unit cage))
?+ pax (on-peek:def pax)
[%x %all ~]
``settings-data+!>(`data`all+settings)
2021-09-09 04:35:57 +03:00
::
[%x %desk @ ~]
=* desk i.t.t.pax
2021-09-20 05:16:41 +03:00
=/ desk-settings (~(gut by settings) desk ~)
``settings-data+!>(desk+desk-settings)
2021-01-12 23:36:30 +03:00
::
2021-09-09 03:41:39 +03:00
[%x %bucket @ @ ~]
=* desk i.t.t.pax
=* buc i.t.t.t.pax
=/ bucket=(unit bucket) (~(get bi settings) desk buc)
2021-01-12 23:36:30 +03:00
?~ bucket [~ ~]
``settings-data+!>(`data`bucket+u.bucket)
2021-01-12 23:36:30 +03:00
::
2021-09-09 03:41:39 +03:00
[%x %entry @ @ @ ~]
=* desk i.t.t.pax
=* buc i.t.t.t.pax
=* key i.t.t.t.t.pax
=/ =bucket (~(gut bi settings) desk buc *bucket)
2021-01-12 23:36:30 +03:00
=/ entry=(unit val) (~(get by bucket) key)
?~ entry [~ ~]
``settings-data+!>(`data`entry+u.entry)
2021-02-18 03:52:45 +03:00
::
2021-09-09 03:41:39 +03:00
[%x %has-bucket @ @ ~]
=/ desk i.t.t.pax
=/ buc i.t.t.t.pax
=/ has-bucket=? (~(has bi settings) desk buc)
``noun+!>(`?`has-bucket)
2021-02-18 03:52:45 +03:00
::
2021-09-09 03:41:39 +03:00
[%x %has-entry @ @ @ ~]
=* desk i.t.t.pax
=* buc i.t.t.t.pax
=* key i.t.t.t.t.pax
=/ =bucket (~(gut bi settings) desk buc *bucket)
2021-02-18 03:52:45 +03:00
=/ has-entry=? (~(has by bucket) key)
``noun+!>(`?`has-entry)
2021-01-12 23:36:30 +03:00
==
::
++ on-agent on-agent:def
++ on-leave on-leave:def
++ on-arvo on-arvo:def
++ on-fail on-fail:def
--
::
|_ bol=bowl:gall
::
:: +put-bucket: put a bucket in the top level settings map, overwriting if it
:: already exists
::
++ put-bucket
2021-09-09 03:41:39 +03:00
|= [=desk =key =bucket]
2021-01-12 23:36:30 +03:00
^- (quip card _state)
=/ pas=(list path)
:~ /all
2021-09-09 04:35:57 +03:00
/desk/[desk]
2021-09-09 03:41:39 +03:00
/bucket/[desk]/[key]
2021-01-12 23:36:30 +03:00
==
2021-09-09 03:41:39 +03:00
:- [(give-event pas %put-bucket desk key bucket)]~
state(settings (~(put bi settings) desk key bucket))
2021-01-12 23:36:30 +03:00
::
:: +del-bucket: delete a bucket from the top level settings map
::
++ del-bucket
2021-09-09 03:41:39 +03:00
|= [=desk =key]
2021-01-12 23:36:30 +03:00
^- (quip card _state)
=/ pas=(list path)
:~ /all
2021-09-09 04:35:57 +03:00
/desk/[desk]
2021-01-12 23:36:30 +03:00
/bucket/[key]
==
2021-09-09 03:41:39 +03:00
:- [(give-event pas %del-bucket desk key)]~
state(settings (~(del bi settings) desk key))
2021-01-12 23:36:30 +03:00
::
:: +put-entry: put an entry in a bucket, overwriting if it already exists
:: if bucket does not yet exist, create it
::
++ put-entry
2021-09-09 03:41:39 +03:00
|= [=desk buc=key =key =val]
2021-01-12 23:36:30 +03:00
^- (quip card _state)
=/ pas=(list path)
:~ /all
2021-09-09 04:35:57 +03:00
/desk/[desk]
2021-09-09 03:41:39 +03:00
/bucket/[desk]/[buc]
/entry/[desk]/[buc]/[key]
2021-01-12 23:36:30 +03:00
==
2021-09-09 03:41:39 +03:00
=/ =bucket (~(put by (~(gut bi settings) desk buc *bucket)) key val)
:- [(give-event pas %put-entry desk buc key val)]~
2021-09-13 04:42:10 +03:00
state(settings (~(put bi settings) desk buc bucket))
2021-01-12 23:36:30 +03:00
::
:: +del-entry: delete an entry from a bucket, fail quietly if bucket does not
:: exist
::
++ del-entry
2021-09-09 03:41:39 +03:00
|= [=desk buc=key =key]
2021-01-12 23:36:30 +03:00
^- (quip card _state)
=/ pas=(list path)
:~ /all
2021-09-09 04:35:57 +03:00
/desk/[desk]
2021-09-09 03:41:39 +03:00
/bucket/[desk]/[buc]
/entry/[desk]/[buc]/[key]
2021-01-12 23:36:30 +03:00
==
2021-09-09 03:41:39 +03:00
=/ bucket=(unit bucket) (~(get bi settings) desk buc)
2021-01-12 23:36:30 +03:00
?~ bucket
[~ state]
=. u.bucket (~(del by u.bucket) key)
2021-09-09 03:41:39 +03:00
:- [(give-event pas %del-entry desk buc key)]~
state(settings (~(put bi settings) desk buc u.bucket))
2021-01-12 23:36:30 +03:00
::
++ give-event
|= [pas=(list path) evt=event]
^- card
[%give %fact pas %settings-event !>(evt)]
--