Skip to content

# Class: ExtensionStore<T>

Common.Store.ExtensionStore

Copyright (c) 2021 OpenLens Authors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

## Type parameters

Name
`T`

## Hierarchy

- `BaseStore`<T>

↳ ExtensionStore

## Table of contents

### Constructors

- constructor

### Properties

- extension
- params
- storeConfig
- syncDisposers

### Accessors

- name
- path
- syncMainChannel
- syncRendererChannel

### Methods

- applyWithoutSync
- cwd
- disableSync
- enableSync
- fromStore
- load
- loadExtension
- onModelChange
- onSync
- onSyncFromMain
- saveToFile
- toJSON
- unregisterIpcListener
- createInstance
- getInstance
- resetInstance

## Constructors

### constructor

• `Protected` new ExtensionStore<T>(`params`)

#### Type parameters

Name
`T`

#### Parameters

Name | Type
--- | ---
`params` | `BaseStoreParams`<T>

#### Inherited from

BaseStore<T>.constructor

## Properties

### extension

• `Protected` extension: `LensExtension`

### params

• `Protected` params: `BaseStoreParams`<T>

#### Inherited from

BaseStore.params

### storeConfig

• `Protected` `Optional` storeConfig: `Conf`<T>

#### Inherited from

BaseStore.storeConfig

### syncDisposers

• `Protected` syncDisposers: `Disposer`[] = []

#### Inherited from

BaseStore.syncDisposers

## Accessors

### name

• `get` name(): `string`

#### Returns

`string`

### path

• `get` path(): `string`

#### Returns

`string`

### syncMainChannel

• `Protected` `get` syncMainChannel(): `string`

#### Returns

`string`

### syncRendererChannel

• `Protected` `get` syncRendererChannel(): `string`

#### Returns

`string`

## Methods

### applyWithoutSync

▸ `Protected` applyWithoutSync(`callback`): `void`

#### Parameters

Name | Type
--- | ---
`callback` | () => `void`

#### Returns

`void`

#### Inherited from

BaseStore.applyWithoutSync

### cwd

▸ `Protected` cwd(): `string`

#### Returns

`string`

#### Overrides

BaseStore.cwd

### disableSync

▸ disableSync(): `void`

#### Returns

`void`

#### Inherited from

BaseStore.disableSync

### enableSync

▸ enableSync(): `void`

#### Returns

`void`

#### Inherited from

BaseStore.enableSync

### fromStore

▸ `Protected` `Abstract` fromStore(`data`): `void`

fromStore is called internally when a child class syncs with the file system.

#### Parameters

Name | Type | Description
--- | --- | ---
`data` | `T` | the parsed information read from the stored JSON file

#### Returns

`void`

#### Inherited from

BaseStore.fromStore

### load

▸ load(): `void`

#### Returns

`void`

#### Overrides

BaseStore.load

### loadExtension

▸ loadExtension(`extension`): `void`

#### Parameters

Name | Type
--- | ---
`extension` | `LensExtension`

#### Returns

`void`

### onModelChange

▸ `Protected` onModelChange(`model`): `Promise`<void>

#### Parameters

Name | Type
--- | ---
`model` | `T`

#### Returns

`Promise`<void>

#### Inherited from

BaseStore.onModelChange

### onSync

▸ `Protected` onSync(`model`): `void`

#### Parameters

Name | Type
--- | ---
`model` | `T`

#### Returns

`void`

#### Inherited from

BaseStore.onSync

### onSyncFromMain

▸ `Protected` onSyncFromMain(`model`): `void`

#### Parameters

Name | Type
--- | ---
`model` | `T`

#### Returns

`void`

#### Inherited from

BaseStore.onSyncFromMain

### saveToFile

▸ `Protected` saveToFile(`model`): `Promise`<void>

#### Parameters

Name | Type
--- | ---
`model` | `T`

#### Returns

`Promise`<void>

#### Inherited from

BaseStore.saveToFile

### toJSON

▸ `Abstract` toJSON(): `T`

toJSON is called when syncing the store to the filesystem. It should produce a JSON serializable object representation of the current state.

It is recommended that a round trip is valid. Namely, calling `this.fromStore(this.toJSON())` shouldn't change the state.

#### Returns

`T`

#### Inherited from

BaseStore.toJSON

### unregisterIpcListener

▸ unregisterIpcListener(): `void`

#### Returns

`void`

#### Inherited from

BaseStore.unregisterIpcListener

### createInstance

▸ `Static` createInstance<T, R>(...`args`): `T`

Creates the single instance of the child class if one was not already created.

Multiple calls will return the same instance. Essentially throwing away the arguments to the subsequent calls.

Note: this is a racy function, if two (or more) calls are racing to call this function only the first's arguments will be used.

#### Type parameters

Name | Type
--- | ---
`T` | `T`
`R` | `R`: `any`[]

#### Parameters

Name | Type | Description
--- | --- | ---
`...args` | `R` | The constructor arguments for the child class

#### Returns

`T`

An instance of the child class

#### Inherited from

BaseStore.createInstance

### getInstance

▸ `Static` getInstance<T, R>(`strict`): `T`

Get the instance of the child class that was previously created.

#### Type parameters

Name | Type
--- | ---
`T` | `T`
`R` | `R`: `any`[]

#### Parameters

Name | Type | Description
--- | --- | ---
`strict` | `boolean` | If false will return `undefined` instead of throwing when an instance doesn't exist. Default: `true`

#### Returns

`T`

An instance of the child class

#### Inherited from

BaseStore.getInstance

### resetInstance

▸ `Static` resetInstance(): `void`

Delete the instance of the child class.

Note: this doesn't prevent callers of `getInstance` from storing the result in a global.

There is no way in JS or TS to prevent globals like that.

#### Returns

`void`

#### Inherited from

BaseStore.resetInstance