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

staux

v1.0.4

Published

Staux is a predictable state container for react.js apps.

Downloads

8

Readme

Staux

Staux is a predictable state container for react.js apps.

NPM JavaScript Style Guide

Install

# NPM
npm install --save staux
# Yarn
yarn add @reduxjs/toolkit

Purpose

The Staux package creates a store between all parts of the React.js web application. That store contents: State that contains data, Dispatch function to edit this state.

What's Included

Stauxt includes these APIs:

  • configureStore() : wraps createStore to provide simplified configuration options.
  • CombinGroups() : Uesd for combine your group reducers.
  • createGroup() : combines Reducers + Actions. Accepts an object of reducer functions, a group name, and an initial state value, and automatically generates a group reducer with corresponding action creators and action types.

Usage

Configration file :

import {
  CombinGroups,
  ConfigureStore,
  TypedUseSelectorHook
} from 'state-any-where'
import productGroup from './groups/planet'

// create store
const groups = CombinGroups({
  reducer: {
    planet: productGroup
  }
})

type RootState = typeof groups

export const { useSelector, dispatch } = ConfigureStore(groups)

export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector

export const useAppDispatch = () => dispatch

Group file :

import { MetaResponseAttributs, Planet } from '../models'
import { AppThunk, createGroup, PayloadAction } from 'staux'
import axios from 'axios'

interface InitState {
  isLoading: boolean
  error?: string
  planets: Planet[]
  meta?: MetaResponseAttributs
}

const initialState: InitState = {
  isLoading: false,
  planets: []
}

const productGroup = createGroup({
  initialState,
  name: 'planet',
  reducers: {
    toggleLoading: (state) => {
      state.isLoading = !state.isLoading
    },
    setError: (state, { payload }: PayloadAction<string>) => {
      state.error = payload
    },
    setPlanets: (state, { payload }: PayloadAction<Planet[]>) => {
      state.planets = payload
    },
    setMeta: (state, { payload }: PayloadAction<MetaResponseAttributs>) => {
      state.meta = payload
    }
  }
})

const { actions } = productGroup

export const { toggleLoading, setError, setPlanets, setMeta } = actions

export const FetchPlanets =
  (page = 1): AppThunk =>
  async ({ dispatch }) => {
    // const dispatch = store.dispatch

    try {
      //Start loading
      dispatch(toggleLoading())

      //check pagnation status
      let getUrl = 'https://swapi.dev/api/planets'

      const res = await axios.get(getUrl, { params: { page } })
      const { results, ...rest } = res.data

      let planets: Planet[] = results

      dispatch(setMeta({ ...rest }))
      dispatch(setPlanets(planets))
    } catch (error) {
      dispatch(setError('Error on fetch planets..'))
    } finally {
      dispatch(toggleLoading())
    }
  }

export default productGroup.reducer

UI side :

import React from 'react'
import { FetchPlanets } from './core/groups/planet'
import { useAppDispatch, useAppSelector } from './core/store'

const App = () => {
  const { isLoading, planets } = useAppSelector((state) => state.planet)
  const dispatch = useAppDispatch()

  const handleClick = () => {
    dispatch(FetchPlanets())
  }
  return (
    <div>
      <button onClick={handleClick}>Test</button>
      {isLoading ? (
        'loading'
      ) : (
        <div style={{ display: 'flex', gap: '10px' }}>
          {planets.map(({ name }) => (
            <div key={name}>{name}</div>
          ))}
        </div>
      )}
    </div>
  )
}

export default App

License

MIT © abdulrahmanAlh