Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wobsoriano/svelte-xactor

Convert xactor machines into global svelte stores
https://github.com/wobsoriano/svelte-xactor

svelte xactor

Last synced: 6 days ago
JSON representation

Convert xactor machines into global svelte stores

Awesome Lists containing this project

README

        

# svelte-xactor

This middleware allows you to easily convert your [xactor](https://github.com/statelyai/xactor) machines into a global store that implements store contract.

## Installation

```sh
yarn add svelte-xactor xactor
```

## Usage

```ts
// store.ts
import { createSystem, createBehavior } from 'xactor'

const counter = createBehavior(
(state, message, context) => {
if (message.type === 'add') {
return {
...state,
count: state.count + message.value,
}
}

return state
},
{ count: 0 }
)

export const counterSystem = createSystem(counter, 'counter')
```

```svelte

import toSvelteStore from 'svelte-xactor'
import { counterSystem } from './store'
const state = toSvelteStore(counterSystem)

counterSystem.send({type: 'add', value: 1})}>
Clicks: {$state.count}

```