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

@disorrder/storm

v0.3.1

Published

StoreModule. Trying to combine Redux and OOP

Downloads

6

Readme

Store Modules

Redux is a predictable state container for JavaScript apps. (c) Facebook

Storm is inspired by Redux and Vuex with saving all core conepts but in more simple OOP style. Do the same with less code and even more!

Install

npm install --save @disorrder/storm

Just show me the code!

See more in examples folder.

import {Store, state, Mutation, Action} from "@disorrder/storm";

export default class Account extends Store {
    @state amount = 0

    @Mutation setAmount(val = 0) {
        return {amount: val};
    }

    @Action async updateAmount() {
        let {data} = await api.get("/user/account");
        // Variant 1
        this.setAmount(data);
        // Variant 2
        this.amount = data;
        // Variant 3
        this.mutate({amount: data}); // Actually you won't use this
        // This 3 variants are equal.
    }
}

There is a mutate() call inside amount state's setter. If you want to change two properties or more, it's better to use Mutation:

export default class Account extends Store {
    // . . .

    @state transactions = []

    @Mutation charge(val = 0) { // mutates 2 properties in one time
        let transaction = {
            id: this.transactions.length + 1,
            amount: val,
            date: Date.now(),
        };
        let transactions = [...this.transactions, transaction]; // never use .push(), always copy objects
        return {
            amount: this.amount + val,
            transactions,
        };
    }
}

Yep, that's it!

Import store

// ./src/store/index.js
import Account from "./Account"
export const account = new Account()
import {account} from "/src/store"

Subscribe

// Let the props be only props
account.subscribe((mutation, oldState) => {
    // React Component constructor:
    this.setState({});
})

Inheritance

import user from "./store";

class App extends Component { componentDidMount() { user.subscribe(() => { this.setState({}); }); } }