Shareable
Updated on August 22, 2024Source codeTests
The Shareable
class enhances share data, allowing it to:
- Determine whether or not the data can be shared with the Web Share API
- Share the data using the Web Share API, if possible
- Store any error that might happen while trying to share data
- Store a status ('ready', 'sharing', 'shared', or 'errored')
Construct a Shareable
instance
The Shareable
constructor accepts two parameters:
Parameter
Type
Required
Description
options
Object
no
Options for the
Shareable
instance. See the Shareable
constructor options section for more guidance.Shareable
constructor options
Shareable
's options
object currently does not accept any options.
State and methods
Property
Type
Description
Parameters
Return value
shareData
Getter/Setter
See return value
N/A
The shareData passed to the constructor.
If you assign a value directly to shareData
, a setter will pass the new value to setShareData
.
status
Getter
See return value
N/A
The status (String) of the
Shareable
instance. status
is ready
after the instance is constructed, sharing
immediately after the share
method is called, and shared
after the share
method finishes. status
can also be errored
if there is an error during the share
operation.can
Getter
See return value
N/A
A Resolveable
instance. Call shareableInstance.can.resolve()
to asynchronously check whether shareData
can be shared.
When shareableInstance.can.status
changes to resolved
, you can check shareableInstance.can.value
to read the result of the check.
error
Getter
See return value
N/A
The error that was thrown during the last share operation, when applicable.
setShareData(shareData)
Function
Sets the
Shareable
instance's shareData
, and updates can
with a new Resolveable
instanceThe new
shareData
(ShareData)The
Shareable
instanceshare()
Function
Shares the
Shareable
instance's shareData
None
The
Shareable
instanceUsing with TypeScript
Nothing special to know about using Shareable
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.The
options
object doesn't currently have any valid properties.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
shareData
Has a public method you can use to set a new value for that public getter
setShareData
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>
methodsnone
Has at least one additional getter property that you can't (and shouldn't) set directly
status
, can
, error
Has one or more public methods that expose core functionality
share
Either has no side effects or has side effects that can be cleaned up with a
stop
methodUses the sentence template to decide what state type should be accepted by a constructor
"Share data can be shared."
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