Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/wobsoriano/svelte-xactor
- Owner: wobsoriano
- License: mit
- Created: 2021-09-17T18:07:06.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-09-17T18:29:03.000Z (about 3 years ago)
- Last Synced: 2024-11-21T11:48:29.552Z (21 days ago)
- Topics: svelte, xactor
- Language: Svelte
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-svelte-stores - svelte-xactor
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}```