Primitives / foldkit-primitives/device
permissions
function · packages/primitives/src/device/permissions.ts:67
function permissions<const Name extends string>(config: {
readonly name: Name
readonly create?:
((navigator: Navigator) => PermissionsHandle | null) | undefined
}): Bundle.Bundle<
Name,
{ readonly names: readonly string[] },
{
readonly states: { readonly [x: string]: 'prompt' | 'denied' | 'granted' }
readonly lastError: Option.Option<string>
},
| { readonly _tag: 'Cleared' }
| {
readonly _tag: 'Changed'
readonly name: string
readonly state: 'prompt' | 'denied' | 'granted'
}
| { readonly _tag: 'Failed'; readonly message: string }
| {
readonly _tag: 'Snapshot'
readonly states: { readonly [x: string]: 'prompt' | 'denied' | 'granted' }
},
never,
never,
ManagedResource.ManagedResourceService<'permissions'>,
NoView,
{
watch: ManagedResource.Entry<
{
readonly states: {
readonly [x: string]: 'prompt' | 'denied' | 'granted'
}
readonly lastError: Option.Option<string>
},
| { readonly _tag: 'Cleared' }
| {
readonly _tag: 'Changed'
readonly name: string
readonly state: 'prompt' | 'denied' | 'granted'
}
| { readonly _tag: 'Failed'; readonly message: string }
| {
readonly _tag: 'Snapshot'
readonly states: {
readonly [x: string]: 'prompt' | 'denied' | 'granted'
}
},
Option.Option<readonly string[]>,
Acquired,
ManagedResource.ManagedResourceService<'permissions'>,
({ snapshot }: Acquired) => {
readonly _tag: 'Snapshot'
readonly states: {
readonly [x: string]: 'prompt' | 'denied' | 'granted'
}
}
>
},
{},
undefined
>Permission states as a bundle factory: queried on placement, kept current
by each status object's onchange. A resource holds the status objects
(they cannot live in the Model); its queue feeds the subscription, and
release detaches every handler. An unknown permission name fails the
acquire; an unknown state string fails it too — both become Failed,
never Model facts.