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

@thundersolutions/state

v0.3.1

Published

Complex state management made easy.

Downloads

4

Readme

Thunder State

standard-readme compliant

Complex state management made easy.

Your work environment should be as easy as possible, so simple tasks don't require excessive work or a monstrous learning curve. To help maintain your workflow efficiency, this package tackles one of the most difficult challenges of all: state management. We did all the complicated work so you don't have to. While still following best practices and some common patterns, this tool allows you to easily and quickly set up your state, with minimal learning involved.

Table of Contents

Install

npm i @thundersolutions/state

Usage

First, make sure you've imported the necessary item ...


// get the class or factory function as named exports
import { State, createState } from '@thundersolutions/state'

// or get the `State` class as a default export
import State from '@thundersolutions/state'

// You can also get the `createState()` factory function from the State class
const { createState } = State
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring

... Or include it as a UMD.

<script src="https://unpkg.com/@thundersolutions/state/umd/thunderState.min.js"></script>
<script>
  const { State, createState } = ThunderState
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring
</script>

Then create your state by adding some basic configuration options.

const state = new State({

  state: {
    user: {
      username: 'demo_user',
      email: '[email protected]',
      preferences: {
        notifications: true,
        newsletter: false,
      },
    },
    loggedIn: true,
    alert: {
      visible: true,
      text: 'This is a demo alert'
    },
  },

  actions: {
    changeUsername({state, payload}) {
      state.user.username = payload
    },
    toggleLogin({state, payload}) {
      state.loggedIn = payload
    },
    toggleAlert({state, payload}) {
      state.alert.visible = payload
    },
  },

})

Retrieve the state from getters, which are automatically created from your initial state.

console.log(state.getters.loggedIn) // true
console.log(state.getters.user.username) // 'demo_user'

Change the state by dispatching the actions defined above.

state.dispatchers.changeUsername('new_user')
state.dispatchers.toggleAlert(false)

That's all you need for your first simple state! Additionally, there are more options to make your state even more powerful, such as:

  • computed values
  • watchers
  • asynchronous actions
  • time travel debugging

Read more about these features in the documentation.

Maintainers

@jonathandewitt-dev

License

MIT © 2020 Jonathan DeWitt