Skip to content

Connect your svelte store to redux devtools with minimal code change

Notifications You must be signed in to change notification settings

unlocomqx/svelte-reduxify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

svelte-reduxify

connect your svelte store to redux devtools with minimal code change

Installation

npm install svelte-reduxify

Usage

import { reduxify } from "svelte-reduxify";
const store = reduxify(writable(0));

Full example

Original code

import { writable } from 'svelte/store';

function createCount() {
  const { subscribe, set, update } = writable(0);

  return {
    subscribe,
    increment: () => update(n => n + 1),
    decrement: () => update(n => n - 1),
    reset: () => set(0)
  };
}

export const count = createCount();

Modified code

import { writable } from 'svelte/store';
import { reduxify } from "svelte-reduxify";

function createCount() {
  const { subscribe, set, update } = writable(0);

  return reduxify({
    update, // necessary for updating state from devtools
    subscribe,
    increment: () => update(n => n + 1),
    decrement: () => update(n => n - 1),
    reset: () => set(0)
  });
}

export const count = createCount();

Comparison

  import { writable } from 'svelte/store';
+ import { reduxify } from "svelte-reduxify";
  
  function createCount() {
    const {subscribe, set, update } = writable(0);
 
-   return { 
+   return reduxify({
+     update, // necessary for updating state from devtools
      subscribe,
      increment: () => update(n => n + 1),
      decrement: () => update(n => n - 1),
      reset: () => set(0)
-   }
+   });
  }
  
  export const count = createCount();

Redux DevTools

View actions

Redux DevTools
You can "Jump" to states and use the timeline slider

Dispatch actions and states

You can dispatch an action by name
Dispatch Actions
You can also dispatch state in JSON format
Dispatch States

About

Connect your svelte store to redux devtools with minimal code change

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published