Sawtaytoes
5/3/2019 - 10:07 AM

Redux without state in Svelte

<script>
  import { createStore } from './fakeRedux.js'
  
  let count = 0
  
  const stateModifiers = {
    DECREMENT: () => {
      count -= 1
    },
    INCREMENT: () => {
      count += 1
    },
  }

  const store = (
    createStore(
      stateModifiers
    )
  )
</script>

<h1>Count: {count}</h1>

<button
  on:click={() => {
    store.dispatch({ type: 'DECREMENT' })
  }}
>
  +
</button>

<button
  on:click={() => {
    store.dispatch({ type: 'INCREMENT' })
  }}
>
  -
</button>