group-view: refactor to surface UI state

This commit is contained in:
Liam Fitzgerald 2021-02-01 11:57:56 +10:00
parent d41ea872c5
commit 0bad34b044
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB
4 changed files with 79 additions and 79 deletions

View File

@ -4,7 +4,7 @@
++ card card:agent:gall ++ card card:agent:gall
+$ state-zero +$ state-zero
$: %0 $: %0
joining=(map rid=resource =ship) joining=(map rid=resource [=ship =progress:view])
== ==
++ view view-sur ++ view view-sur
-- --
@ -37,7 +37,7 @@
(on-poke:def mark vase) (on-poke:def mark vase)
=+ !<(=action:view vase) =+ !<(=action:view vase)
=^ cards state =^ cards state
(jn-start:join:gc +.action) jn-abet:(jn-start:join:gc +.action)
[cards this] [cards this]
:: ::
++ on-watch ++ on-watch
@ -45,7 +45,12 @@
?+ path (on-watch:def path) ?+ path (on-watch:def path)
[%all ~] [%all ~]
:_ this :_ 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 ++ on-peek on-peek:def
@ -58,7 +63,7 @@
=/ rid =/ rid
(de-path:resource t.wire) (de-path:resource t.wire)
?. (~(has by joining) rid) `state ?. (~(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] [cards this]
:: ::
@ -75,20 +80,28 @@
:: ::
:: ::
++ join ++ join
|_ [rid=resource =ship] |_ [rid=resource =ship cards=(list card)]
++ jn-core . ++ 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 |= =progress:view
=. joining
(~(put by joining) rid [ship progress])
=; =cage =; =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]) group-view-update+!>([%progress rid progress])
:: ::
++ watch-md ++ watch-md
(watch-our:(jn-pass-io /md) %metadata-store /updates) (emit (watch-our:(jn-pass-io /md) %metadata-store /updates))
:: ::
++ watch-groups ++ watch-groups
(watch-our:(jn-pass-io /groups) %group-store /groups) (emit (watch-our:(jn-pass-io /groups) %group-store /groups))
:: ::
++ jn-pass-io ++ jn-pass-io
|= pax=path |= pax=path
@ -96,72 +109,69 @@
:: ::
++ jn-abed ++ jn-abed
|= r=resource |= r=resource
=/ s=^ship =/ [s=^ship =progress:view]
(~(got by joining) r) (~(got by joining) r)
jn-core(rid r, ship s) jn-core(rid r, ship s)
:: ::
++ jn-abet
^- (quip card _state)
[(flop cards) state]
::
++ jn-start ++ jn-start
|= [rid=resource =^ship] |= [rid=resource =^ship]
^- (quip card _state) ^+ jn-core
?< (~(has by joining) rid) ?< (~(has by joining) rid)
=. joining =. joining
(~(put by joining) rid ship) (~(put by joining) rid [ship %start])
=. jn-core =. jn-core
(jn-abed rid) (jn-abed rid)
=/ maybe-group =/ maybe-group
(peek-group:met %contacts rid) (peek-group:met %contacts rid)
?^ maybe-group ?^ maybe-group
~|("already joined group {<rid>}" !!) ~|("already joined group {<rid>}" !!)
:_ state =. jn-core
:~ %+ poke:(jn-pass-io /add) %- emit
[ship %group-push-hook] %+ poke:(jn-pass-io /add)
group-update+!>([%add-members rid (silt our.bowl ~)]) [ship %group-push-hook]
:: group-update+!>([%add-members rid (silt our.bowl ~)])
(tx-fact %start) =. jn-core (tx-progress %start)
watch-md => watch-md
watch-groups watch-groups
==
:: ::
++ jn-agent ++ jn-agent
|= [=wire =sign:agent:gall] |= [=wire =sign:agent:gall]
^- (quip card _state) ^+ jn-core
|^ |^
?+ -.wire ~|("bad %join wire" !!) ?+ -.wire ~|("bad %join wire" !!)
%add :: join group %add :: join group
?> ?=(%poke-ack -.sign) ?> ?=(%poke-ack -.sign)
?^ p.sign ?^ p.sign
(cleanup %no-perms) (cleanup %no-perms)
:_ state => %- emit
:~ (tx-fact %added)
%+ poke-our:(jn-pass-io /pull-groups) %group-pull-hook %+ poke-our:(jn-pass-io /pull-groups) %group-pull-hook
pull-hook-action+!>([%add ship rid]) pull-hook-action+!>([%add ship rid])
== (tx-progress %added)
:: ::
%pull-groups %pull-groups
?> ?=(%poke-ack -.sign) ?> ?=(%poke-ack -.sign)
?~ p.sign (ack +.sign)
:: do nothing, wait for update from store
`state
:: shouldn't ever fail
(cleanup %strange)
:: ::
%groups %groups
?+ -.sign !! ?+ -.sign !!
%fact (groups-fact +.sign) %fact (groups-fact +.sign)
%watch-ack (ack +.sign) %watch-ack (ack +.sign)
%kick groups-kick %kick watch-groups
== ==
:: ::
%pull-md %pull-md
?> ?=(%poke-ack -.sign) ?> ?=(%poke-ack -.sign)
?~ p.sign `state (ack +.sign)
(cleanup %strange)
:: ::
%md %md
?+ -.sign !! ?+ -.sign !!
%fact (md-fact +.sign) %fact (md-fact +.sign)
%watch-ack (ack +.sign) %watch-ack (ack +.sign)
%kick md-kick %kick watch-md
== ==
:: ::
%pull-graphs %pull-graphs
@ -171,58 +181,46 @@
== ==
++ groups-fact ++ groups-fact
|= =cage |= =cage
?. ?=(%group-update p.cage) ?. ?=(%group-update p.cage) jn-core
`state
=+ !<(=update:group-store q.cage) =+ !<(=update:group-store q.cage)
?. ?=(%initial-group -.update) ?. ?=(%initial-group -.update) jn-core
`state ?. =(rid resource.update) jn-core
?. =(rid resource.update) %- emit
`state %+ poke-our:(jn-pass-io /pull-md) %metadata-pull-hook
:_ state
:_ ~
%+ poke-our:(jn-pass-io /pull-md) %metadata-push-hook
pull-hook-action+!>([%add [entity .]:rid]) pull-hook-action+!>([%add [entity .]:rid])
:: ::
++ md-fact ++ md-fact
|= [=mark =vase] |= [=mark =vase]
?. ?=(%metadata-update mark) `state ?. ?=(%metadata-update mark) jn-core
=+ !<(=update:metadata vase) =+ !<(=update:metadata vase)
?. ?=(%initial-group -.update) `state ?. ?=(%initial-group -.update) jn-core
?. =(group.update rid) `state ?. =(group.update rid) jn-core
=^ cards state =. jn-core (cleanup %done)
(cleanup %done) ?. hidden:(need (scry-group:grp rid)) jn-core
:_ state %- emit-many
%+ welp cards
?. hidden:(need (scry-group:grp rid)) ~
%+ murn ~(tap by associations.update) %+ murn ~(tap by associations.update)
|= [=md-resource:metadata =association:metadata] |= [=md-resource:metadata =association:metadata]
^- (unit card)
?. =(app-name.md-resource %graph) ~ ?. =(app-name.md-resource %graph) ~
=* rid resource.md-resource =* rid resource.md-resource
:- ~ :- ~
%+ poke-our:(jn-pass-io /pull-graph) %graph-pull-hook %+ poke-our:(jn-pass-io /pull-graph) %graph-pull-hook
pull-hook-action+!>([%add [entity .]:rid]) pull-hook-action+!>([%add [entity .]:rid])
:: ::
++ groups-kick
:_ state
watch-groups^~
::
++ md-kick
:_ state
watch-md^~
::
++ ack ++ ack
|= err=(unit tang) |= err=(unit tang)
?~ err `state ?~ err jn-core
%- (slog u.err)
(cleanup %strange) (cleanup %strange)
:: ::
++ cleanup ++ cleanup
|= =progress:view |= =progress:view
^- (quip card _state) =. jn-core
:_ state(joining (~(del by joining) rid)) (tx-progress progress)
:~ (leave-our:(jn-pass-io /groups) %group-store) =. joining (~(del by joining) rid)
(leave-our:(jn-pass-io /md) %metadata-store) =. jn-core
(tx-fact progress) (emit (leave-our:(jn-pass-io /groups) %group-store))
== (emit (leave-our:(jn-pass-io /md) %metadata-store))
-- --
-- --
-- --

View File

@ -353,7 +353,7 @@
++ handle-add ++ handle-add
|= [group=resource =md-resource:store =metadatum:store] |= [group=resource =md-resource:store =metadatum:store]
^- (quip card _state) ^- (quip card _state)
:- %+ send-diff app-name.md-resource :- %- send-diff
[%add group md-resource metadatum] [%add group md-resource metadatum]
%= state %= state
associations associations
@ -374,7 +374,7 @@
++ handle-remove ++ handle-remove
|= [group=resource =md-resource:store] |= [group=resource =md-resource:store]
^- (quip card _state) ^- (quip card _state)
:- (send-diff app-name.md-resource [%remove group md-resource]) :- (send-diff [%remove group md-resource])
%= state %= state
associations associations
(~(del by associations) md-resource) (~(del by associations) md-resource)
@ -395,15 +395,15 @@
|= [group=resource =associations:store] |= [group=resource =associations:store]
=/ assocs=(list [=md-resource:store grp=resource =metadatum:store]) =/ assocs=(list [=md-resource:store grp=resource =metadatum:store])
~(tap by associations) ~(tap by associations)
=| cards=(list card) :- (send-diff %initial-group group associations)
|- |-
?~ assocs ?~ assocs
[cards state] state
=, assocs =, assocs
?> =(group grp.i) ?> =(group grp.i)
=^ new-cards state =^ cards state
(handle-add group [md-resource metadatum]:i) (handle-add group [md-resource metadatum]:i)
$(cards (weld cards new-cards), assocs t) $(assocs t)
:: ::
++ metadata-for-app ++ metadata-for-app
|= =app-name:store |= =app-name:store
@ -428,13 +428,12 @@
(~(put by out) md-resource [group metadatum]) (~(put by out) md-resource [group metadatum])
:: ::
++ send-diff ++ send-diff
|= [=app-name:store =update:store] |= =update:store
^- (list card) ^- (list card)
|^ |^
%- zing %- zing
:~ (update-subscribers /all update) :~ (update-subscribers /all update)
(update-subscribers /updates update) (update-subscribers /updates update)
(update-subscribers [%app-name app-name ~] update)
== ==
:: ::
++ update-subscribers ++ update-subscribers

View File

@ -15,7 +15,7 @@
++ join ++ join
%- ot %- ot
:~ resource+dejs:resource :~ resource+dejs:resource
ship+ship ship+(su ;~(pfix sig fed:ag))
== ==
-- --
:: ::
@ -39,8 +39,11 @@
== ==
:: ::
++ initial ++ initial
|= resources=(set resource) |= init=(map resource ^progress)
^- json %- pairs
a+(turn ~(tap in resources) (cork enjs-path:resource (lead %s))) %+ turn ~(tap by init)
|= [rid=resource prog=^progress]
:_ s+prog
(enjs-path:resource rid)
-- --
-- --

View File

@ -12,7 +12,7 @@
?(%no-perms %strange %done) ?(%no-perms %strange %done)
:: ::
+$ update +$ update
$% [%initial =resources] $% [%initial initial=(map resource progress)]
[%progress =resource =progress] [%progress =resource =progress]
== ==
-- --