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

mithril-redux

v1.0.0

Published

Bindings between Mithril and Redux

Downloads

18

Readme

npm version

Mithril Redux

This package provides utilites for working with Redux within a Mithril application. Similar to react-redux.

It doesn't alter the redrawing functionality of Mithril, other than providing some basic middleware below. It does not subscribe to the Redux store. It generally allows you to continue to work with Mithril as normal, except with replacing your models with the store.

See https://github.com/colinbate/mithril-redux-starter for a sample useage.

It does not rely on you using the mjsx Babel plugin.

Usage

Install with:

npm install --save mithril-redux

Unfortunately there isn't a UMD version available at this time.

API

Provider.init(store, mithril, component)

When you are mounting your app, you should call this function to initialize the link between your store and Mithril.

The parameters are the Redux store, then the mithril (m) object, and then an optional mithril component. If the component is a function is it instantiated and returned, otherwise it is returned as-is.

Example

import m from 'mithril';
import {Provider} from 'mithril-redux';
import configStore from './store';
import Root from './root';

const store = configStore({name: 'World', age: 30});

m.mount(document.body, Provider.init(store, m, Root));

connect(selector, actions)(component)

Used to turn your Mithril components into Redux-aware Mithril components. Works similar to connect from react-redux.

  • selector - A function which maps the full state to the parts needed.
  • actions - An object listing action creators to be injected into the controller. Or, a function which returns the said object map.
  • component - The Mithril component to connect.

Example

import {connect} from 'mithril-redux';
import {incrementAge, decrementAge, resetAge} from './actions';

class _AgeBox {
  view(ctrl, {age}) {
    return m('div', [
        m('span', 'Age: ' + age),
        m('button', {onclick: ctrl.dec()}, 'Younger'),
        m('button', {onclick: ctrl.inc()}, 'Older'),
        m('button', {onclick: ctrl.reset()}, 'Reset')
    ]);
  }
}

export const AgeBox = connect((state) => ({age: state.age}), {
  inc: incrementAge,
  dec: decrementAge,
  reset: resetAge
})(_AgeBox);

It is worth noting that the action creators exposed on the controller are actually action creator factories. Any parameters you pass in during view creation will be prepended to those passed when the action creator is eventually invoked.

For example, in the code above, if you had ctrl.reset('Hello'), then the resetAge action creator would be called with 'Hello' as the first param and the event object as the second.

Also, the store's dispatch function is also passed to the props of the view in case necessary.

redrawMiddleware

Adds the ability for actions to specify that they need to cause a redraw. Useful for anything async where Mithril doesn't naturally redraw. This library does not subscribe to the store.

Trigger it by setting the redraw property on the action to true;

Example (Setup)

import { createStore, applyMiddleware } from 'redux';
import { redrawMiddleware } from 'mithril-redux';
import rootReducer from './reducers';

export default function configureStore(initialState) {
  const createModifiedStore = applyMiddleware(
    redrawMiddleware
  )(createStore);
  return createModifiedStore(rootReducer, initialState);

Future Work (possibly separate packages)

  • [ ] Integrate with m.request to get data into the store.
  • [ ] Create some sort of middleware for promises which calls m.startComputation/m.endComputation
  • [ ] Integrate with m.route for params and potentially more.