SHIFT + D

Grantable

Updated on August 22, 2024Source codeTests

Grantable is a class that enriches a permission descriptor, giving it the ability to:

  • Attempt to grant its permission status
  • Store its permission status
  • Store an error, if one occurs
  • Store a status (ready, granting, granted, or errored)

Construct a Grantable instance

The Grantable constructor accepts two parameters:

Parameter
Type
Required
Description
descriptor
PermissionDescriptor
yes
The permission descriptor that will be made grantable.
options
Object
no
Options for the Grantable instance. See the Grantable constructor options section for more guidance.

Grantable constructor options

Grantable's options object currently does not accept any options.

State and methods

Property
Type
Description
Parameters
Return value
descriptor
Getter/Setter
See return value
N/A

The permission descriptor (PermissionDescriptor) passed to the constructor.

If you assign a value directly to descriptor, a setter will pass the new value to setDescriptor.

permission
Getter
See return value
N/A

The permission status (PermissionStatus) of the Grantable instance.

permission is undefined before the grant method is called, and it changes to a PermissionStatus object after the grant method is called.

status
Getter
See return value
N/A
The status (String) of the Grantable instance. status is ready after the instance is constructed, and changes to granting while the grant method is running. It changes to granted after the grant method finishes, and it changes to errored if the grant method encounters an error.
error
Getter
See return value
N/A
undefined before the grant method is called, and an Error object after the grant method is called and encounters an error.
setDescriptor(descriptor)
Function
Sets the Grantable instance's descriptor
The new descriptor (PermissionDescriptor)
The Grantable instance
grant()
Function
Queries the Grantable instance's permission status.
None
The Grantable instance

Using with TypeScript

Nothing special to know about using Grantable with TypeScript 🚀

API design compliance

Spec
Compliance status
Notes
Access functionality by constructing an instance
Constructor accepts two parameters: a piece of state, and an options object.
Constructor does not access the DOM
Takes the form of a JavaScript Object
State and methods are accessible through properties of the object
Methods always return the instance
Stores the constructor's state in a public getter named after the state's type
descriptor
Has a public method you can use to set a new value for that public getter
setDescriptor
Has a setter for that getter so you can assign a new value directly
Any other public getters that should be set by you in some cases also have setters and set<Property> methods
none
Has at least one additional getter property that you can't (and shouldn't) set directly
status, permission, error
Has one or more public methods that expose core functionality
grant
Either has no side effects or has side effects that can be cleaned up with a stop method
Uses the sentence template to decide what state type should be accepted by a constructor
"A permission (described by a permission descriptor) can be granted."
Constructor does not accept options that only customize the behavior of public methods, it allows those options to be passed to the method itself as a parameter.
Named after its core action, proper-cased and suffixed with able

FullscreenableListenable

Edit doc on GitHub

ON THIS PAGE

GrantableConstruct a Grantable instanceGrantable constructor optionsState and methodsUsing with TypeScriptAPI design compliance