Make user data source refreshable in client apps

This commit is contained in:
Andrew Kingston 2021-02-26 14:04:31 +00:00
parent a67a8fb957
commit d27dff0261
1 changed files with 12 additions and 1 deletions

View File

@ -11,6 +11,7 @@
screenStore, screenStore,
authStore, authStore,
} from "../store" } from "../store"
import { TableNames, ActionTypes } from "../constants"
// Provide contexts // Provide contexts
setContext("sdk", SDK) setContext("sdk", SDK)
@ -25,10 +26,20 @@
await authStore.actions.fetchUser() await authStore.actions.fetchUser()
loaded = true loaded = true
}) })
// Register this as a refreshable datasource so that user changes cause
// the user object to be refreshed
$: actions = [
{
type: ActionTypes.RefreshDatasource,
callback: () => authStore.actions.fetchUser(),
metadata: { datasource: { type: "table", tableId: TableNames.USERS } },
},
]
</script> </script>
{#if loaded && $screenStore.activeLayout} {#if loaded && $screenStore.activeLayout}
<Provider key="user" data={$authStore}> <Provider key="user" data={$authStore} {actions}>
<Component definition={$screenStore.activeLayout.props} /> <Component definition={$screenStore.activeLayout.props} />
<NotificationDisplay /> <NotificationDisplay />
</Provider> </Provider>