npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

deren

v1.0.0

Published

--- title: State management done right with Sveltix. description: Use pinia-like API in Svelte with Sveltix. thumbnail: https://vueschool.io/storage/media/39ebc760d644aa4625743dfc727ff737/pinia-the-enjoyable-vue-store.jpg date: 18/08/2023 | dd-mm-yyyy

Downloads

4

Readme


title: State management done right with Sveltix. description: Use pinia-like API in Svelte with Sveltix. thumbnail: https://vueschool.io/storage/media/39ebc760d644aa4625743dfc727ff737/pinia-the-enjoyable-vue-store.jpg date: 18/08/2023 | dd-mm-yyyy

The problem

A few months ago, I was building a video player for my project OpenAnime and it became so big that we wanted to split the player into components to improve readability of the player. That time, player included 1300 lines of code in a single component making it very hard to read and maintain. We first tried to use the built-in svelte stores which is great for basic use cases. However, we wanted to also split the Javascript part of the player and storing them in a directory like players, events and utils. And working with svelte stores in plain javascript was just painful we had nearly 30 object properties to manage in a single store and it was clear that built-in svelte stores wasn't enough.

The solution

We needed a library that could work with existing svelte stores to handle reactive changes within the template and we needed another way to use it easily inside our Javascript. So, I created a library called sveltix (yes, the name is inspired from vuex 😏) to do this. Sveltix's API looks too much like Pinia's but currently getter support is not implemented.

Examples with Sveltix

A basic usage

<script>
  import { sveltix } from "sveltix";

  const newStore = sveltix({
    state: () => ({
     value: 1
    })
  });

  const useStore = newStore.useStore();
</script>

<button
  on:click={() => newStore.value++}>count is {$useStore.value}
</button>

Working with actions

<script>
  import { sveltix } from "sveltix";

  const newStore = sveltix({
    state: () => ({
      value: 1,
    }),
    actions: {
      increment() {
        this.value++;
      },
    },
  });

  const useStore = newStore.useStore();
</script>

<button on:click={() => newStore.increment()}>count is {$useStore.value}</button>

Binding components

<script>
  import { sveltix } from "sveltix";

  const newStore = sveltix({
    state: () => ({
     button: null
    })
  });

 //you can't use bind:this={$useStore.button}. Currently this is the only way of binding components 😅
  function binder(node, prop) {
   newStore[prop] = node
  }
</script>

<button use:binder={'button'}>
  hello!
</button>

The end

I hope you enjoyed your stay. The Github repo for this project is here and I appreciate any star you give or your PRs and issues.