import { html, render } from 'lit'
import { provide, connect } from './unlit'
const app = provide(store)( () => html`<div>${counter}</div>` )
const counter = connect('count', {
add: ({ count }) => ({ count: count+1 })
})( ({ count, actions }) => html`
<button on-click="${actions.add}">${count}</button>
`);
render(app, document.body)
Created
January 29, 2018 15:17
-
-
Save developit/f256933605c31d44eaf8c3887ec4287a to your computer and use it in GitHub Desktop.
unistore + lit-html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { select, mapActions } from '../util'; // ~unistore/src/util | |
import { directive } from 'lit-html'; | |
export function connect(mapState, createActions) { | |
if (typeof mapState!=='function') mapState = select(mapState || []) | |
return comp => props => { | |
let actions = createActions ? mapActions(createActions, props.store) : {} | |
let upd = state => comp({ actions, ...mapState(state, props), ...props }) | |
return directive(part => { | |
store.subscribe( state => part.setValue(upd(state)) ) | |
return upd(store.getState()) | |
}) | |
} | |
} | |
export const provide = store => comp => props => comp({ ...props, store }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment