New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@koax/store

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@koax/store

Redux style store.

latest
Source
npmnpm
Version
0.1.2
Version published
Maintainers
1
Created
Source

store

Build status Git tag NPM version Code style

Redux style store.

Installation

$ npm install @koax/store

Usage

import koax from 'koax'
import createStore from '@koax/store'
import combineReducers from '@f/combine-reducers'
import getProp from '@f/get-prop'
import {fetchEffect, fetchType} from '@koax/fetch'
import {get} from '@koax/fetch-json'

const REQUEST_POSTS = 'REQUEST_POSTS'
const RECEIVE_POSTS = 'RECEIVE_POSTS'
const RETRIEVE_STATE = 'RETRIEVE_STATE'

let app = koax()
app.use(fetchEffect)
app.use(retrieveState)
let store = createStore(combineReducers({postsBySubredit}), {}, app)

app(getPosts('frontend')).then(res => res) // => frontend posts

function * getPosts (subredit) {
  let items = yield {type: RETRIEVE_STATE, path: `postsBySubredit.${subredit}.items`}
  if (!items) {
    yield {type: REQUEST_POSTS, subredit}
    items = yield get(`api.redit.com/posts/${subredit}`)
    yield {
      type: RECEIVE_POSTS,
      payload: items
      subredit
    }
  }
  return items
}

function retrieveState (action, next getState) {
  if (action.type === RETRIEVE_STATE) {
    return getProp(action.path, getState())
  }
  return next()
}

function postsBySubredit (state, action) {
  switch (action.type) {
    case REQUEST_POSTS:
      return {
        ...state,
        [action.subredit]: {
          isFetching: true
        }
      }
    case RECEIVE_POSTS:
      return {
        ...state,
        [action.subredit]: {
          isFetching: false,
          items: action.payload
        }
      }
  }
}

API

store(reducer, initialState, app)

  • reducer - redux style reducer
  • initialState - initial state object
  • app - koax app to bind state and mount store dispatcher

Returns: store (redux store api excluding dispatch - koax app should be used to dispatch)

.getState()

Returns: current state of store

.subscribe(listener)

  • listener - listener called when updates to state occur - recieves new state

.replaceReducer(reducer)

  • reducer - new reducer to

License

MIT

FAQs

Package last updated on 13 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts