Class: Bucket<Item>
Buckets can persist state. The base Bucket
class is abstract and should be
extended to create buckets with different persistence strategies.
Buckets have a simple map-like interface with methods like getItem
,
setItem
, and removeItem
. All methods return promises to enable usage with
asynchronous stores like IndexedDB.
Buckets can be assigned a unique namespace
in order to avoid collisions.
Buckets can be assigned a version, and can be "upgraded" to a new version. The upgrade process allows buckets to migrate their data between versions.
Type parameters​
Name |
---|
Item |
Hierarchy​
Evented
<"upgrade"
>↳
Bucket
Constructors​
constructor​
• new Bucket<Item
>(settings?
)
Type parameters​
Name | Type |
---|---|
Item | unknown |
Parameters​
Name | Type |
---|---|
settings | BucketSettings |
Inherited from​
Evented<'upgrade'>.constructor
Defined in​
packages/@orbit/core/src/bucket.ts:50
Accessors​
name​
• get
name(): undefined
| string
Name used for tracking and debugging a bucket instance.
Returns​
undefined
| string
Defined in​
packages/@orbit/core/src/bucket.ts:85
namespace​
• get
namespace(): string
The namespace used by the bucket when accessing any items.
This is used to distinguish one bucket's contents from another.
Returns​
string
Defined in​
packages/@orbit/core/src/bucket.ts:94
version​
• get
version(): number
The current version of the bucket.
This is read-only. To change versions, upgrade
should be invoked.
Returns​
number
Defined in​
packages/@orbit/core/src/bucket.ts:103
Methods​
clear​
â–¸ Abstract
clear(): Promise
<void
>
Clears all items from the bucket.
Returns​
Promise
<void
>
Defined in​
packages/@orbit/core/src/bucket.ts:80
emit​
â–¸ emit(event
, ...args
): void
Parameters​
Name | Type |
---|---|
event | Event |
...args | unknown [] |
Returns​
void
Inherited from​
Defined in​
packages/@orbit/core/src/evented.ts:29
getItem​
â–¸ Abstract
getItem(key
): Promise
<Item
>
Retrieves an item from the bucket.
Parameters​
Name | Type |
---|---|
key | string |
Returns​
Promise
<Item
>
Defined in​
packages/@orbit/core/src/bucket.ts:65
listeners​
â–¸ listeners(event
): Listener
[]
Parameters​
Name | Type |
---|---|
event | Event |
Returns​
Listener
[]
Inherited from​
Defined in​
packages/@orbit/core/src/evented.ts:30
off​
â–¸ off(event
, listener?
): void
Parameters​
Name | Type |
---|---|
event | Event |
listener? | Listener |
Returns​
void
Inherited from​
Defined in​
packages/@orbit/core/src/evented.ts:27
on​
â–¸ on(event
, listener
): () => void
Parameters​
Name | Type |
---|---|
event | Event |
listener | Listener |
Returns​
fn
â–¸ (): void
Returns​
void
Inherited from​
Defined in​
packages/@orbit/core/src/evented.ts:26
one​
â–¸ one(event
, listener
): () => void
Parameters​
Name | Type |
---|---|
event | Event |
listener | Listener |
Returns​
fn
â–¸ (): void
Returns​
void
Inherited from​
Defined in​
packages/@orbit/core/src/evented.ts:28
removeItem​
â–¸ Abstract
removeItem(key
): Promise
<void
>
Removes an item from the bucket.
Parameters​
Name | Type |
---|---|
key | string |
Returns​
Promise
<void
>
Defined in​
packages/@orbit/core/src/bucket.ts:75
setItem​
â–¸ Abstract
setItem(key
, value
): Promise
<void
>
Stores an item in the bucket.
Parameters​
Name | Type |
---|---|
key | string |
value | Item |
Returns​
Promise
<void
>
Defined in​
packages/@orbit/core/src/bucket.ts:70
upgrade​
â–¸ upgrade(settings?
): Promise
<void
>
Upgrades Bucket to a new version with new settings.
Settings, beyond version
, are bucket-specific.
Parameters​
Name | Type |
---|---|
settings | BucketSettings |
Returns​
Promise
<void
>