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

storage-container

v0.0.1

Published

This is an alternative to redux and should work with react and inferno in particular but there is no reason it couldn't work with other things. It combines multiple kinds of storage so you don't have to

Downloads

2

Readme

Storage Container

This is an alternative to redux and should work with react and inferno in particular but there is no reason it couldn't work with other things. It combines multiple kinds of storage so you don't have to

Usage

import StorageContainer from 'storage-container'

const storageContainer = StorageContainer({
    onChange: (newState, oldState) => console.log(newState, oldState),
    initialState: {
        name_0: {},
        name_1: {}
    },
    actions: {
        name_0: {
            action_0 (storageContainer) {},
            action_1 (storageContainer) {}
        }
    },
    reducers: {
        name_0: {
            reducer_0 (storageContainer) {},
            reducer_1 (storageContainer) {}
        }
    },
    urls: {
        'name_0': {
            pathname: '',
            alias: ['name_0', 'name0', 'name-0', '0'],
            subname: {
                pathname: 'subname',
                alias: ['subname_0', '/subname0', '/subname-0', '0'],
            }
        }
    }
})

// in-memory usage

storageContainer.name_0.set({ a: 1 })
storageContainer.name_0.override({})
storageContainer.name_0.reset()
storageContainer.name_0.get()
storageContainer.name_0.actions()

storageContainer.set({})
storageContainer.override({})
storageContainer.reset()
storageContainer.get()
storageContainer.actions()

// local storage

storageContainer.name_0.local.save({a: 1})
storageContainer.name_0.local.remove({a: 1})
storageContainer.saveLocal('name', 'value')
storageContainer.getLocal('name)

// cookie storage

storageContainer.name_0.cookie.save({a: 1})
storageContainer.name_0.cookie.remove({a: 1})
storageContainer.saveCookie('name', 'value')
storageContainer.getCookie('name)

// history

storageContainer.go('/url')
storageContainer.name_0.go()
storageContainer.name_0.subname.go()
storageContainer.location()

With React (or similarly with Inferno)

going to make a stopwatch which starts the time, you can stop it, restart it and it saves your time to local storage so when you refresh the page it will be there, it also changes the time using the route so /hh-mm-ss will give hours minutes and seconds where as /hh-mm will only give hours and minutes etc.

import React from 'react'

const Ticker = ({start, stop, restart, startDisabled, stopDisabled, restartDisabled}) => {
    return <div>
        <h2>Ticker</h2>
        <button onClick={start} disabled={startDisabled}>Start</button>
        <button onClick={stop} disabled={stopDisabled}>Stop</button>
        <button onClick={restart} disabled={restartDisabled}>Restart</button>
    </div>
}
import React from 'react'

const Format = ({toggleHours, toggleMinutes, toggleSeconds, hoursChecked, minutesChecked, secondsChecked}) => {
    return <div>
        <h2>Format</h2>
        <input type="checkbox" checked={hoursChecked} onChange={toggleHours} />
        <label>Hours</label>
        <input type="checkbox" checked={minutesChecked} onChange={toggleMinutes} />
        <label>Minutes</label>
        <input type="checkbox" checked={secondsChecked} onChange={toggleSeconds} />
        <label>Seconds</label>
    </div>
}
import React from 'react'

const Time = ({value}) => {
    return <div>
        <h2>Time</h2>
        <span>{value}</span>
    </div>
}
{
    "ticker": {
        "startDisabled": false,
        "stopDisabled": true,
        "restartDisabled": true
    },
    "format": {
        "hoursChecked": true,
        "minutesChecked": true,
        "secondsChecked": true
    },
    "time": {
        "seconds": 0,
        "value": "00:00:00"
    }
}
const tickerActions = {
    start (storageContainer) {
        const interval = setInterval(() => {
            const seconds = storageContainer.time.get().seconds
            storageContainer.time.save({
                seconds: seconds + 1
            })
        }, 1000)

        storageContainer.ticker.set({
            startDisabled: true,
            stopDisabled: false,
            restartDisabled: false,
            interval
        })
    },
    stop (storageContainer) {
        clearInterval(storageContainer.ticker.get().interval)

        storageContainer.ticker.set({
            startDisabled: false,
            stopDisabled: true,
            restartDisabled: true
        })
    },
    restart (storageContainer) {
        storageContainer.ticker.get().stop()                        
        storageContainer.time.save({
            seconds: 0
        })
        storageContainer.ticker.get().start()
    }
}
const actions = {
    ticker: tickerActions
}
const reducers = {

}
import React from 'react'
import StorageContainer from 'storage-container'
import Actions from './actions'
import Reducers from './reducers'
import initialState from './initial-state'
import urls from './urls'

const StopWatch extends React.Component({
    constructor(props) {
        super(props)
        this.storageContainer = StorageContainer({
            onChange: (newState, oldState) => this.setState(newState),
            initialState,
            actions,
            reducers,
            urls
        })
    }
    render () {
        return <div>
            <Ticker {...this.storageContainer.ticker.get()} >
            <Format {...this.storageContainer.format.get()}>
            <Time {...this.storageContainer.time.get()} >
        </div>
    }
})
import ReactDOM from 'react-dom'