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

k-simple-state

v0.5.1

Published

State manager for your components apps, the safe and easy way.

Downloads

5

Readme

k-simple-state

State manager for your components apps, the safe and easy way.

CircleCI Coverage Status NPM Version Size Greenkeeper badge

Contents

Purpose

TODO

Why

TODO

Installation

  • yarn add k-simple-state
  • npm install --save k-simple-state

API

createStore(<store_description>, <options>)

| parameter | required | description | |---|---|---| | <store_description>| required | object describing your store, it can be nested | | <options> | optional | all options you may want to override |

options

All options are optionals to keep the default usage as simple as possible.

| key | type | default | description | |---|---|---|---| | listeners | array | undefined | array of all listeners. Listeners are a big part of this lib, you can click here for detail. | | devtools | boolean | true | redux-devtools is activated. | | hideRedux | boolean | true | actions and selectors from k-redux-factory are used without specifying dispatch or getState. | | enhancer | redux enhancer | undefined | usual compose and applyMiddlare you already use with Redux can be injected here (like router, redux-saga, etc). compose and applyMiddleware from Redux are exposed by the lib. To use them: import { compose, applyMiddleware } from 'k-simple-state'. | | init | object | undefined | the default value of your store. |

listeners

TODO

Examples

Create a simple store

import { createStore, keyValue } from 'k-simple-state'

// create a store of todos
const store = createStore({
  todos: keyValue({ key: 'id' }),
})

// dispatch an action and update the store in one line, without k-simple-state inner reducer
store.todos.add({ id: 2, label: 'write a better README' })

// you can retrieve data like that
const todo = store.todos.get(2)

Connect it with ReactJS

  1. Provide this store to React context

app.jsx

import { provider } from 'k-simple-state/react'
import store from './store'
import TodosContainer from './todos.container'

const App = () => <TodosContainer />

// use `provider` HoC to inject store to the React context
export default provider(store)(App)
  1. Use inject to interact with the store, wrap your <Todos /> graphical component in a container

todos.container.js

import { inject } from 'k-simple-state/react'
import Todos from './todos'

// `inject` is an HoC, like `connect` from react-redux,
// it takes one parameter and returns props to be injected to the wrapped component
// (FYI: props injected to the wrapped component are added to the props given by the parent)
export default inject(store => ({
  todos: store.todos.getAsArray(),
  onAdd: event => store.todos.add({ id: Date.now(), label: event.target.value }),
}))(Todos)
  1. Write your classical React JSX component (here, as pure function)

todos.jsx

import React from 'react'
import PropTypes from 'prop-types'

const Todos = ({ todos, onAdd }) => (
  <div>
    <input onBlur={onAdd} />
    <ul>
      {todos.map(todo => <li>{todo.label}</li>})}
    </ul>
  </div>
)

Todos.propTypes = {
  todos: PropTypes.array.isRequired,
  onAdd: PropTypes.func.isRequired,
}

export default Todos

About alakarte

alakarte is created by two passionate french developers.

Do you want to contact them ? Go to their website