Skip to main content
Version: 0.17

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​

Constructors​

constructor​

• new Bucket<Item>(settings?)

Type parameters​

NameType
Itemunknown

Parameters​

NameType
settingsBucketSettings

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​

NameType
eventEvent
...argsunknown[]

Returns​

void

Inherited from​

Evented.emit

Defined in​

packages/@orbit/core/src/evented.ts:29


getItem​

â–¸ Abstract getItem(key): Promise<Item>

Retrieves an item from the bucket.

Parameters​

NameType
keystring

Returns​

Promise<Item>

Defined in​

packages/@orbit/core/src/bucket.ts:65


listeners​

â–¸ listeners(event): Listener[]

Parameters​

NameType
eventEvent

Returns​

Listener[]

Inherited from​

Evented.listeners

Defined in​

packages/@orbit/core/src/evented.ts:30


off​

â–¸ off(event, listener?): void

Parameters​

NameType
eventEvent
listener?Listener

Returns​

void

Inherited from​

Evented.off

Defined in​

packages/@orbit/core/src/evented.ts:27


on​

â–¸ on(event, listener): () => void

Parameters​

NameType
eventEvent
listenerListener

Returns​

fn

â–¸ (): void

Returns​

void

Inherited from​

Evented.on

Defined in​

packages/@orbit/core/src/evented.ts:26


one​

â–¸ one(event, listener): () => void

Parameters​

NameType
eventEvent
listenerListener

Returns​

fn

â–¸ (): void

Returns​

void

Inherited from​

Evented.one

Defined in​

packages/@orbit/core/src/evented.ts:28


removeItem​

â–¸ Abstract removeItem(key): Promise<void>

Removes an item from the bucket.

Parameters​

NameType
keystring

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​

NameType
keystring
valueItem

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​

NameType
settingsBucketSettings

Returns​

Promise<void>

Defined in​

packages/@orbit/core/src/bucket.ts:112