1.0.1 • Published 3 years ago

svelte-xactor v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

svelte-xactor

This middleware allows you to easily convert your xactor machines into a global store that implements store contract.

Installation

yarn add svelte-xactor xactor

Usage

// 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')
<script lang="ts">
  import toSvelteStore from 'svelte-xactor'
  import { counterSystem } from './store'
  const state = toSvelteStore(counterSystem)
</script>

<button on:click={() => counterSystem.send({type: 'add', value: 1})}>
  Clicks: {$state.count}
</button>