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

stores-x

v0.0.872

Published

This is minimal vueX implementation.

Downloads

12

Readme

stores-x

This is inspired by Vuex

It's for now a minimal implementation of the vuex

It uses the svelte store( or your own custom svelte store)

It makes working with svelte stores somewhat clean and organised

Also the compiled version should be able to work in any other js web app(not tested yet)

installation

npm install stores-x

Also you can try cdn

<script src="https://cdn.jsdelivr.net/npm/stores-x/dist/index.min.js"><script>

for old browsers

<script src="https://cdn.jsdelivr.net/npm/stores-x/dist/old.index.min.js"><script>

module

<script src="https://cdn.jsdelivr.net/npm/stores-x/dist/index.min.mjs"><script>

Usage

check out the svelte relp demo

it should be similar in other js frameworks(not tested yet)

API

store.state

each individual state defaults as a writable svelte store but with an additional get property to get the current state value.

example: storeItem.get() // gets current value by making a temporal store subscription

store.mutations

They mutate the state values. Simply put they change or set state values. The are funtions.

declared like This :

mutationName(state,...args){}

run as

commit('mutationName', val);
or;
mutationName(val);

store.actions

The do tasks like any other function. They can commit 'store.mutations' also can dispatch store.actions.

declared like This :

actionName({state, commit, dispatch, g },...args){}

run as

dispatch('actionName', ...args);
or;
actionName(...args);

store.getters

They are used to get state values or any other custom one

declared like This :

getterName(state,...args:Optional){}

run as

g('getterName');
or;
getterName();

store.noStore

this an array of state items which you don't wish to be a any store. that is the item will have a static state. It's a config

store.defaults

This controls the default settings (ie. whether to disable the default getter or mutation for a particular state). It's a config

if the default mutation for a particular state item is disabled the corresponding default action will also be disabled.

default: true all items getters, mutations, actions will be created automatically. This is the default`

or

default: {
  item1:true,//getters, mutations, actions will be created automatically
  item2:{getters: false},// mutations, actions will be created automatically
  item3:false// no default getters, mutations, actions will be created
  }

store.storeType

It's a config this declares the type of store you want for an storeitem

storeType: 'writable' // all items will be writable. This is the default or storeType: {item1:'writable',item2:'sessionPersistantStore',item3:customStore} //an item's defaults to 'writable'

options:

  • 'writable' => svelteWritable store with a get method
  • 'sessionPersistantStore' => uses sessionStorage but still reactive like any other svelte store
  • 'localPersistantStore' => uses localStorage but still reactive like any other svelte store
  • a custom store function

commit

is a function that executes/runs a mutation

like:

commit('mutationName', val);

dispatch

is a function that executes/runs an action and returns Promise

like:

dispatch('mutationName', ...args);

Example

import storesX from 'stores-x';

store1 = {
  noStore: ['apiKey'],
  state: {
    apiKey: 'string',
  },
  actions: {
    doThatThing({ dispatch, state }) {
      //doing it
      dispatch('isLoggedIn', state.apiKey);
      //state.apiKey.get() will be error since apiKey is not a store
    },
  },
};

store2 = {
  storeType: 'writable',
  state: {
    isLoggedIn: false,
  },
  getters: {
    islogedIn(state) {
      // this will be created be default unless disabled
      return state.isLoggedIn;
    },
  },
  mutations: {
    isLoggedIn(state, val) {
      // this will be created be default unless disabled
      state.isLoggedIn.set(val);
    },
  },
  actions: {
    isLoggedIn({ state, commit, dispatch, g }, val) {
      // this will be created be default unless disabled
      // logging in
      commit('isLoggedIn', val);
    },
  },
};

store = storesX([store1, store2]);

apiKey = store.g('apiKey'); // apiKey is getter is created automatically by default
isLoggedIn = store.g('isLoggedIn');

console.log(apiKey); // logs => 'string'

console.log(isLoggedIn.get()); // logs => true|false
// or if in *.svelte
console.log($isLoggedIn); // logs => true|false

if you want you can give the defaults a prefix

store = storesX([store1, store2], { getters: 'get', mutations: 'set', actions: 'set' });
// so now
apiKey = store.g('getApiKey');
store.commit('setIsLoggedIn', val);