# FakeThemeSource

A scripted [`ThemeSource`](https://docs.mapcairn.com/api/core/ThemeSource.md).

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

## Signature

```ts
import { FakeThemeSource } from "@mapcairn/core";
 
class FakeThemeSource implements ThemeSource
```

## Description

How to script it: pass the starting system theme (light by default) and
call `setSystemTheme(theme)` to change it. Subscribers are notified only
when the theme actually changes, like a media query. `apply` notifies
nobody; it records the theme in `appliedTheme` (null until first applied)
and every call in `applyCalls`.

## Constructors

### (constructor)

```ts
constructor(systemTheme?: ResolvedTheme);
```

Constructs a new instance of the `FakeThemeSource` class

- `systemTheme?` (`ResolvedTheme`)

## Properties

### appliedTheme

```ts
readonly get appliedTheme(): ResolvedTheme | null;
```

The last theme passed to `apply`, or null if none has been.

### applyCalls

```ts
readonly applyCalls: ResolvedTheme[];
```

Every theme passed to `apply`, in order.

## Methods

### apply

```ts
apply(theme: ResolvedTheme): void;
```

Records the theme in `appliedTheme` and `applyCalls`. It notifies nobody.

- `theme` (`ResolvedTheme`)

### getSystemTheme

```ts
getSystemTheme(): ResolvedTheme;
```

The system theme as scripted, light until `setSystemTheme` changes it.

### setSystemTheme

```ts
setSystemTheme(theme: ResolvedTheme): void;
```

Changes the system theme and notifies subscribers if it differs.

- `theme` (`ResolvedTheme`)

### subscribe

```ts
subscribe(listener: (theme: ResolvedTheme) => void): () => void;
```

Calls the listener when `setSystemTheme` changes the theme. Returns the function that unsubscribes.

- `listener` (`(theme: ResolvedTheme) => void`)

## See also

- [`ThemeSource`](https://docs.mapcairn.com/api/core/ThemeSource.md)
- [`ResolvedTheme`](https://docs.mapcairn.com/api/core/ResolvedTheme.md)

Source: [packages/core/src/fakes/FakeThemeSource.ts:15](https://github.com/MapCairn/mapcairn/blob/main/packages/core/src/fakes/FakeThemeSource.ts#L15)
