# FakeLayerCatalogue

A [`LayerCatalogue`](https://docs.mapcairn.com/api/core/LayerCatalogue.md) a test scripts directly.

This is a class exported by `@mapcairn/core`, checked against version 0.2.0.

## Signature

```ts
import { FakeLayerCatalogue } from "@mapcairn/core";
 
class FakeLayerCatalogue implements LayerCatalogue
```

## Description

How to script it: pass the layers it should hold (none by default, which
matches the host in this release) and it is ready with them. Call
`setLayers` to replace them and `setState` to put it in any state, such as
`loading` or `failed`; each tells the subscribers once. `refresh` only
counts the calls in `refreshes` and changes nothing, so a test decides what
a refresh does by calling `setState` itself.

## Constructors

### (constructor)

```ts
constructor(layers?: readonly LayerDefinition[]);
```

Constructs a new instance of the `FakeLayerCatalogue` class

- `layers?` (`readonly LayerDefinition[]`)

## Properties

### getState

```ts
readonly getState: () => CatalogueState;
```

The state now, which `setLayers` and `setState` change. The same object is returned until then.

### refresh

```ts
readonly refresh: () => Promise<void>;
```

Counts the call in `refreshes` and changes nothing; a test decides what a refresh does by calling `setState`.

### refreshes

```ts
refreshes: number;
```

How many times `refresh` has been called.

### subscribe

```ts
readonly subscribe: (listener: () => void) => (() => void);
```

Calls the listener after each change. Returns the function that unsubscribes. An arrow property, so it works unbound.

## Methods

### setLayers

```ts
setLayers(layers: readonly LayerDefinition[]): void;
```

Replaces the layers, ready with none skipped, and tells the subscribers.

- `layers` (`readonly LayerDefinition[]`)

### setState

```ts
setState(state: CatalogueState): void;
```

Puts the catalogue in `state` as it is, and tells the subscribers.

- `state` (`CatalogueState`)

## See also

- [`LayerCatalogue`](https://docs.mapcairn.com/api/core/LayerCatalogue.md)
- [`LayerDefinition`](https://docs.mapcairn.com/api/core/LayerDefinition.md)
- [`CatalogueState`](https://docs.mapcairn.com/api/core/CatalogueState.md)

Source: [packages/core/src/fakes/FakeLayerCatalogue.ts:21](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/fakes/FakeLayerCatalogue.ts#L21)
