1.0.3 • Published 7 years ago

lit-redux v1.0.3

Weekly downloads
1
License
ISC
Repository
-
Last release
7 years ago

lit-redux

lit-redux is implementation of react-redux API for lit-html library.

Example

import {html, render} from 'lit-html/lib/lit-extended';
import {connect} from 'lit-redux';
import {createStore, bindActionCreators} from 'redux';

const todos = (state = [], action) => {
  switch (action.type) {
    case 'ADD_TODO':
      return state.concat([action.text]);
    default:
      return state;
  }
};

const store = createStore(todos, ['Use Redux']);

const actions = {
  add() {
    return {
      type: 'ADD_TODO',
      text: `Hello ${Math.random()}`
    };
  },
};

const todosView = connect(
  state => ({ todos: state }),
  dispatch => ({ actions: bindActionCreators(actions, dispatch) })
)(({todos, actions}) => html`
  ${ todos.map(text => html`<p>${ text }</p>`) }
  <button type="button" onclick="${ () => actions.add() }">Add</button>
`);
  
render(
  html`${ todosView({ store }) }`,
  document.body
);

Live Demo

Current progress

  • Implemented connect() function (only storeKey option is available)

Other related projects

  • lit-form - Formik API implementation for lit-html library