New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

svelte-store-extended

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-store-extended

Svelte/store but with additionals functionalities

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

svelte-store-extended is still in beta, use with caution

svelte-store-extended

Svelte store extended has been created to ease quite a bit your state management within your application by provinding 3 usefull new methods:

function action(name: string, a: ActionHook<T>): Function {}

function selector(name: string | ((strValue: T) => any)): Readable<any> {}

function on<R>(action: Action, hook: (actionState: R, storeState: T) => T

It is really easy to use and straightforward

App.svelte

<script lang="ts">
  import { darkMode, toggleDarkMode } from './store/settings';
</script>

<main>
  DarkMode: {$darkMode}

  <button on:click="{toggleDarkMode}">Toggle dark mode</button>
</main>

<style>
  main {
    text-align: center;
    padding: 1em;
    max-width: 240px;
    margin: 0 auto;
  }

  @media (min-width: 640px) {
    main {
      max-width: none;
    }
  }
</style>

settings.ts

import { store } from 'svelte-store-extended';

export const settings = store({ darkMode: false });

export const darkMode = settings.selector((state) => state.darkMode);
// or you can do the following
export const darkModeBis = settings.selector('darkMode');

export const toggleDarkMode = settings.action(
  '[Settings] Toggle dark mode',
  (state) => {
    state.darkMode = !state.darkMode;
    return state;
  }
);

settings.on(toggleDarkMode, () => {
  console.log('Dark mode changed');
});

Keywords

FAQs

Package last updated on 04 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc