lit-redux
is implementation of react-redux
API for lit-html
library.
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
);
- Implemented
connect()
function (onlystoreKey
option is available)
lit-html
-lit-html
lets you write HTML templates with JavaScript template literals, and efficiently render and re-render those templates to DOMlit-form
- Formik API implementation forlit-html
librarylit-todo-example
-lit-html
+lit-redux
+lit-form