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

@websublime/essential

v0.0.8

Published

Redux Vanilla OOP

Downloads

7

Readme

Essential

Essential is an opinited implementation of redux toolkit in the form of OOP. It is designed for the browser but can also work on nodeJs. This implementation is a vanilla implementation to work on all frameworks or node.

Table of contents

Usage

(Back to top)

Store is a singleton instance where you can use is as:

import { useStore } from '@websublime/essential';

const store = useStore();

Create a class that will be responsable for the partial state of your global state. This reducer class is extended from or base class.

import { EssentialReducer, createAction } from '@websublime/essential';

type MyReducerState = { count: number };
type MyReducerDispatchers = {increment(count: number): void, decrement(count: number): void};

const INCREMENT_ACTION = createAction<MyReducerState>('INCREMENT');
const DECREMENT_ACTION = createAction<MyReducerState>('DECREMENT');

class MyReducer extends EssentialReducer<MyReducerState, MyReducerDispatchers> {
  get initial(): MyReducerState {
    return { count: 0 };
  }

  get actions() {
    return [
      {action: INCREMENT_ACTION, reducer: this.incrementReducer.bind(this) },
      {action: DECREMENT_ACTION, reducer: this.decrementReducer.bind(this) }
    ];
  }

  get dispatchers(): MyReducerDispatchers {
    return {
      increment: this.incrementDispatcher.bind(this),
      decrement: this.decrementDispatcher.bind(this)
    };
  }

  private incrementReducer(state: MyReducerState, action: ReturnType<typeof INCREMENT_ACTION>) {
    state.count = state.count + action.payload.count

    return state;
  }

  private decrementReducer(state: MyReducerState, action: ReturnType<typeof DECREMENT_ACTION>) {
    state.count = state.count - action.payload.count

    return state;
  }

  private incrementDispatcher(count = 1) {
    const [first] = this.actions;

    this.dispatch(first.action({ count }));
  }

  private decrementDispatcher(count = 0) {
    const [_, last] = this.actions;

    this.dispatch(last.action({ count }));
  }
}

You can then register/build this reducer class in the store

const dispatchers = store.buildReducer<MyReducerState, MyReducerDispatchers, typeof MyReducer>(MyReducer, 'myreducer');

After being created the dispatchers object is returned and you can just dispatch any action you have defined on dispatchers property.

dispatchers.increment(1);

To be documented (more examples on tests like async, listeners).

Installation

(Back to top)

npm install @websublime/essential

Contributing

(Back to top)

Your contributions are always welcome! Please have a look at the contribution guidelines first. :tada:

Create branch, work on it and before submit run:

  • git add .
  • git commit -m "feat: title" -m "Description"
  • yarn changeset
  • git add .
  • git commit --amend
  • git push origin feat/... -f

License

(Back to top)

The MIT License (MIT) 2022 - Websublime. Please have a look at the LICENSE.md for more details.