# ReactiveStore

> ReactiveStore is an in-memory key-value store backed by the window object with Proxy-based validation. The library uses it internally to hold configuration and runtime state.

## Usage

All methods are static:

```typescript
import { ReactiveStore } from '@segmentify/integration';

ReactiveStore.set('myKey', 'myValue');
const value = ReactiveStore.get('myKey'); // 'myValue'
ReactiveStore.has('myKey'); // true
ReactiveStore.remove('myKey');
ReactiveStore.getAll(); // { ... }
ReactiveStore.clear();
```

`set`, `remove`, and `clear` return the class for chaining:

```typescript
ReactiveStore.set('lang', 'EN').set('currency', 'USD');
```

## Validators

Attach validation functions to keys. Invalid values throw an error:

```typescript
ReactiveStore.addValidator(
  'apiKey',
  v => typeof v === 'string' && v.length > 0
);

ReactiveStore.set('apiKey', 'abc123'); // OK
ReactiveStore.set('apiKey', ''); // throws Error
```

## Internal Keys

| Key                           | Purpose                        |
| ----------------------------- | ------------------------------ |
| `__store:SegmentifyConfig`    | The `SegmentifyConfig` object  |
| `__store:SegmentifyPage`      | The `pageMap` configuration    |
| `__store:__segmentifyReady__` | `true` when SDK is loaded      |
| `__segmentify:initialized__`  | Prevents double initialization |

::: warning
Avoid overwriting these keys — doing so may break the library.
:::

## ReactiveStore vs PersistedStore

| Feature              | ReactiveStore     | PersistedStore              |
| -------------------- | ----------------- | --------------------------- |
| Storage              | `window` (memory) | `localStorage` (persistent) |
| Survives page reload | No                | Yes                         |
| Validators           | Yes               | No                          |
| Value type           | Any               | Strings only                |
| Use case             | Runtime state     | User data, event queues     |

## See Also

- [PersistedStore](/09-persisted-store)
