unistore-lit

    0.1.1 • Public • Published

    unistore-lit

    unistore connector to lit and uhtml (and any tagged template library).

    Examples

    Usage

    store.js

    import createStore from 'unistore';
    import connectTo from 'unistore-lit';
    
    export const store = createStore({
      list: [
        { id: 1, text: 'Do the thing!' },
        { id: 2, text: 'Do another thing!' },
      ],
    });
    
    export const connect = connectTo(store);

    app.js

    import { connect } from './store';
    
    const mapStateToProps = (state) => ({
      myList: state.list,
    });
    
    export const App = connect(mapStateToProps)(
      ({ myList }) => html`
        <ul>
          ${myList.map((item) => html`<li>${item.id} - ${item.text}</li>`)}
        </ul>
      `
    );

    index.js

    import { render } from 'lit'; // or 'uhtml'
    import { store } from './store';
    import { App } from './app';
    
    const renderApp = () => render(App(), document.body);
    
    renderApp() && store.subscribe(renderApp);

    Install

    npm i unistore-lit

    DownloadsWeekly Downloads

    5

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    13.4 kB

    Total Files

    10

    Last publish

    Collaborators

    • djalmajr