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

purescript-mini-redux

v3.0.4

Published

An idiomatic mini-interface to Redux for PureScript

Downloads

22

Readme

purescript-mini-redux

Latest release Latest release redux channel on discord Build Status

An idiomatic PureScript mini-interface to Redux.

Why?

Because I want to work with Redux in an idiomatic way inspired by purescript-redux-utils, but in a more lightweight and less intrusive fashion. Store creation is still handled by your imperative code, but reducers and actions are defined in your PureScript modules, and thus they are strictly typed and purely functional.

This approach is inspired by the "functional core, imperative shell" strategy made popular by the Destroy All Software talk, Boundaries.

Usage

Install with bower:

$ bower install --save purescript-mini-redux

Define your root reducer and initial state with PureScript (only for this example - you can actually compose PureScript and plain JavaScript reducers any way you like):

module MyApp.State.Store (rootReducer, initialState) where

import Control.Monad.Eff (Eff)
import MyApp.State.MyReducer (State, initialState, reducer) as MyReducer
import Redux.Mini (Store, STORE, ReduxReducer, combineReducers)

rootReducer :: forall action state. ReduxReducer action state
rootReducer = combineReducers { myReducer: MyReducer.reducer }

initialState :: { myReducer :: MyReducer.State }
initialState = { myReducer: MyReducer.initialState }

Define your child reducers in PureScript as well:

module MyApp.State.MyReducer
  ( Action(..)
  , State
  , setMyValue
  , initialState
  , reducer
  ) where

import Prelude
import Redux.Mini (Action) as Redux
import Redux.Mini (Reducer, ReduxReducer, createAction, createReducer)

type State = { myValue :: String }

-- Actions ---------------------------------------------------------------------

data Action = Set String
  | Else -- Represents external actions

setMyValue :: String -> Redux.Action Action
setMyValue value = createAction $ Set value

-- Reducer ---------------------------------------------------------------------

initialState :: State
initialState = { myValue: "" }

myReducer :: Reducer Action State
myReducer (Set value) state = state { myValue = value }
myReducer _ state = state

reducer :: ReduxReducer Action State
reducer = createReducer myReducer initialState

Then create your store with JavaScript:

/* MyApp/State/Create.js */
import {rootReducer} from 'MyApp/State/Store.purs'
import * as Redux from 'redux'

function devToolsEnhancer () {
  if (typeof window === 'object' && typeof window.devToolsExtension !== 'undefined') {
    return window.devToolsExtension()
  }
  return id => id
}

export function createStore (initialState) {
  const enhancers = [devToolsEnhancer()]

  const store = Redux.createStore(
    rootReducer,
    initialState,
    Redux.compose(...enhancers)
  )

  return store
}

Now, you can call your createStore function and pass it an optional initialState value:

import {createStore} from 'MyApp/State/Create'
import {Provider} from 'react-redux'

const store = createStore()

const element = (
  <Provider store={store}>
    <div>My awesome component is awesome!</div>
  </Provider>
)

API Documentation

License

MIT