From 0bad34b04449f628a511db91fac0f17e11fff6d5 Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Mon, 1 Feb 2021 11:57:56 +1000 Subject: [PATCH] group-view: refactor to surface UI state --- pkg/arvo/app/group-view.hoon | 130 +++++++++++++++---------------- pkg/arvo/app/metadata-store.hoon | 15 ++-- pkg/arvo/lib/group-view.hoon | 11 ++- pkg/arvo/sur/group-view.hoon | 2 +- 4 files changed, 79 insertions(+), 79 deletions(-) diff --git a/pkg/arvo/app/group-view.hoon b/pkg/arvo/app/group-view.hoon index 970d0d4da..cdb17577c 100644 --- a/pkg/arvo/app/group-view.hoon +++ b/pkg/arvo/app/group-view.hoon @@ -4,7 +4,7 @@ ++ card card:agent:gall +$ state-zero $: %0 - joining=(map rid=resource =ship) + joining=(map rid=resource [=ship =progress:view]) == ++ view view-sur -- @@ -37,7 +37,7 @@ (on-poke:def mark vase) =+ !<(=action:view vase) =^ cards state - (jn-start:join:gc +.action) + jn-abet:(jn-start:join:gc +.action) [cards this] :: ++ on-watch @@ -45,7 +45,12 @@ ?+ path (on-watch:def path) [%all ~] :_ this - (fact:io group-view-update+!>([%initial ~(key by joining)]) ~)^~ + :_ ~ + %+ fact:io + :- %group-view-update + !> ^- update:view + [%initial (~(run by joining) |=([=ship =progress:view] progress))] + ~ == :: ++ on-peek on-peek:def @@ -58,7 +63,7 @@ =/ rid (de-path:resource t.wire) ?. (~(has by joining) rid) `state - (jn-agent:(jn-abed:join:gc rid) t.t.t.t.wire sign) + jn-abet:(jn-agent:(jn-abed:join:gc rid) t.t.t.t.wire sign) == [cards this] :: @@ -75,20 +80,28 @@ :: :: ++ join - |_ [rid=resource =ship] + |_ [rid=resource =ship cards=(list card)] ++ jn-core . + ++ emit-many + |= crds=(list card) + jn-core(cards (weld (flop crds) cards)) + ++ emit + |= =card + jn-core(cards [card cards]) :: - ++ tx-fact + ++ tx-progress |= =progress:view + =. joining + (~(put by joining) rid [ship progress]) =; =cage - (fact:io cage /all tx+(en-path:resource rid) ~) + (emit (fact:io cage /all tx+(en-path:resource rid) ~)) group-view-update+!>([%progress rid progress]) :: ++ watch-md - (watch-our:(jn-pass-io /md) %metadata-store /updates) + (emit (watch-our:(jn-pass-io /md) %metadata-store /updates)) :: ++ watch-groups - (watch-our:(jn-pass-io /groups) %group-store /groups) + (emit (watch-our:(jn-pass-io /groups) %group-store /groups)) :: ++ jn-pass-io |= pax=path @@ -96,72 +109,69 @@ :: ++ jn-abed |= r=resource - =/ s=^ship + =/ [s=^ship =progress:view] (~(got by joining) r) jn-core(rid r, ship s) :: + ++ jn-abet + ^- (quip card _state) + [(flop cards) state] + :: ++ jn-start |= [rid=resource =^ship] - ^- (quip card _state) + ^+ jn-core ?< (~(has by joining) rid) =. joining - (~(put by joining) rid ship) + (~(put by joining) rid [ship %start]) =. jn-core (jn-abed rid) =/ maybe-group (peek-group:met %contacts rid) ?^ maybe-group ~|("already joined group {}" !!) - :_ state - :~ %+ poke:(jn-pass-io /add) - [ship %group-push-hook] - group-update+!>([%add-members rid (silt our.bowl ~)]) - :: - (tx-fact %start) - watch-md - watch-groups - == + =. jn-core + %- emit + %+ poke:(jn-pass-io /add) + [ship %group-push-hook] + group-update+!>([%add-members rid (silt our.bowl ~)]) + =. jn-core (tx-progress %start) + => watch-md + watch-groups :: ++ jn-agent |= [=wire =sign:agent:gall] - ^- (quip card _state) + ^+ jn-core |^ ?+ -.wire ~|("bad %join wire" !!) %add :: join group ?> ?=(%poke-ack -.sign) ?^ p.sign (cleanup %no-perms) - :_ state - :~ (tx-fact %added) + => %- emit %+ poke-our:(jn-pass-io /pull-groups) %group-pull-hook pull-hook-action+!>([%add ship rid]) - == + (tx-progress %added) :: %pull-groups ?> ?=(%poke-ack -.sign) - ?~ p.sign - :: do nothing, wait for update from store - `state - :: shouldn't ever fail - (cleanup %strange) + (ack +.sign) :: %groups ?+ -.sign !! %fact (groups-fact +.sign) %watch-ack (ack +.sign) - %kick groups-kick + %kick watch-groups == :: %pull-md ?> ?=(%poke-ack -.sign) - ?~ p.sign `state - (cleanup %strange) + (ack +.sign) :: %md ?+ -.sign !! %fact (md-fact +.sign) %watch-ack (ack +.sign) - %kick md-kick + %kick watch-md == :: %pull-graphs @@ -171,58 +181,46 @@ == ++ groups-fact |= =cage - ?. ?=(%group-update p.cage) - `state + ?. ?=(%group-update p.cage) jn-core =+ !<(=update:group-store q.cage) - ?. ?=(%initial-group -.update) - `state - ?. =(rid resource.update) - `state - :_ state - :_ ~ - %+ poke-our:(jn-pass-io /pull-md) %metadata-push-hook + ?. ?=(%initial-group -.update) jn-core + ?. =(rid resource.update) jn-core + %- emit + %+ poke-our:(jn-pass-io /pull-md) %metadata-pull-hook pull-hook-action+!>([%add [entity .]:rid]) :: ++ md-fact |= [=mark =vase] - ?. ?=(%metadata-update mark) `state + ?. ?=(%metadata-update mark) jn-core =+ !<(=update:metadata vase) - ?. ?=(%initial-group -.update) `state - ?. =(group.update rid) `state - =^ cards state - (cleanup %done) - :_ state - %+ welp cards - ?. hidden:(need (scry-group:grp rid)) ~ + ?. ?=(%initial-group -.update) jn-core + ?. =(group.update rid) jn-core + =. jn-core (cleanup %done) + ?. hidden:(need (scry-group:grp rid)) jn-core + %- emit-many %+ murn ~(tap by associations.update) |= [=md-resource:metadata =association:metadata] + ^- (unit card) ?. =(app-name.md-resource %graph) ~ =* rid resource.md-resource :- ~ %+ poke-our:(jn-pass-io /pull-graph) %graph-pull-hook pull-hook-action+!>([%add [entity .]:rid]) :: - ++ groups-kick - :_ state - watch-groups^~ - :: - ++ md-kick - :_ state - watch-md^~ - :: ++ ack |= err=(unit tang) - ?~ err `state + ?~ err jn-core + %- (slog u.err) (cleanup %strange) :: ++ cleanup |= =progress:view - ^- (quip card _state) - :_ state(joining (~(del by joining) rid)) - :~ (leave-our:(jn-pass-io /groups) %group-store) - (leave-our:(jn-pass-io /md) %metadata-store) - (tx-fact progress) - == + =. jn-core + (tx-progress progress) + =. joining (~(del by joining) rid) + =. jn-core + (emit (leave-our:(jn-pass-io /groups) %group-store)) + (emit (leave-our:(jn-pass-io /md) %metadata-store)) -- -- -- diff --git a/pkg/arvo/app/metadata-store.hoon b/pkg/arvo/app/metadata-store.hoon index fe8e8aa89..0f41e1695 100644 --- a/pkg/arvo/app/metadata-store.hoon +++ b/pkg/arvo/app/metadata-store.hoon @@ -353,7 +353,7 @@ ++ handle-add |= [group=resource =md-resource:store =metadatum:store] ^- (quip card _state) - :- %+ send-diff app-name.md-resource + :- %- send-diff [%add group md-resource metadatum] %= state associations @@ -374,7 +374,7 @@ ++ handle-remove |= [group=resource =md-resource:store] ^- (quip card _state) - :- (send-diff app-name.md-resource [%remove group md-resource]) + :- (send-diff [%remove group md-resource]) %= state associations (~(del by associations) md-resource) @@ -395,15 +395,15 @@ |= [group=resource =associations:store] =/ assocs=(list [=md-resource:store grp=resource =metadatum:store]) ~(tap by associations) - =| cards=(list card) + :- (send-diff %initial-group group associations) |- ?~ assocs - [cards state] + state =, assocs ?> =(group grp.i) - =^ new-cards state + =^ cards state (handle-add group [md-resource metadatum]:i) - $(cards (weld cards new-cards), assocs t) + $(assocs t) :: ++ metadata-for-app |= =app-name:store @@ -428,13 +428,12 @@ (~(put by out) md-resource [group metadatum]) :: ++ send-diff - |= [=app-name:store =update:store] + |= =update:store ^- (list card) |^ %- zing :~ (update-subscribers /all update) (update-subscribers /updates update) - (update-subscribers [%app-name app-name ~] update) == :: ++ update-subscribers diff --git a/pkg/arvo/lib/group-view.hoon b/pkg/arvo/lib/group-view.hoon index 2c73e5823..f3b1bf44b 100644 --- a/pkg/arvo/lib/group-view.hoon +++ b/pkg/arvo/lib/group-view.hoon @@ -15,7 +15,7 @@ ++ join %- ot :~ resource+dejs:resource - ship+ship + ship+(su ;~(pfix sig fed:ag)) == -- :: @@ -39,8 +39,11 @@ == :: ++ initial - |= resources=(set resource) - ^- json - a+(turn ~(tap in resources) (cork enjs-path:resource (lead %s))) + |= init=(map resource ^progress) + %- pairs + %+ turn ~(tap by init) + |= [rid=resource prog=^progress] + :_ s+prog + (enjs-path:resource rid) -- -- diff --git a/pkg/arvo/sur/group-view.hoon b/pkg/arvo/sur/group-view.hoon index be275136c..587430094 100644 --- a/pkg/arvo/sur/group-view.hoon +++ b/pkg/arvo/sur/group-view.hoon @@ -12,7 +12,7 @@ ?(%no-perms %strange %done) :: +$ update - $% [%initial =resources] + $% [%initial initial=(map resource progress)] [%progress =resource =progress] == --