Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

As a developer, I would like a redux example #57

Open
2 of 6 tasks
hutchgrant opened this issue Nov 23, 2018 · 0 comments
Open
2 of 6 tasks

As a developer, I would like a redux example #57

hutchgrant opened this issue Nov 23, 2018 · 0 comments
Labels
documentation Documentation for the wiki example something that should include a code sample

Comments

@hutchgrant
Copy link
Member

hutchgrant commented Nov 23, 2018

Type of Change

  • New Feature Request
  • Documentation
  • Future Spec
  • Improvement / Suggestion
  • Bug
  • Other (please clarify below)

Summary

Developers such as myself would like to know how to use libraries like redux within lit-element components. A working example and a wiki guide would be great to have.

The pwa-starter-kit has a really nice guide.

Use Case

Managing state across components necessitates the use of a central store, hence why a redux based example would be something that developers would find useful.

Code Sample

import { html, LitElement } from '@polymer/lit-element';
import { store } from '../../store.js';
import { connect } from 'pwa-helpers/connect-mixin.js';
import { getPosts } from '../../actions/app.js';

class PostList extends connect(store)(LitElement) {
  static get properties() {
    return {
      posts: Array,
    };
  }

  render() {
    return this.posts && html`
    <ul>
      ${this.posts.map(post => html`
        <li>
          <h1>{post.title}</h1>
        </li>
      `)}
    </ul>
    `;
  }

  constructor() {
    super();
    store.dispatch(getPosts());
  }

  // This is called every time something is updated in the store.
  stateChanged(state) {
    this.posts = state.app.posts;
    console.log('My Posts!', this.posts);
  }
}

customElements.define('post-list', PostList);

See blog-redux-example branch for entire example

@hutchgrant hutchgrant added documentation Documentation for the wiki example something that should include a code sample labels Nov 23, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Documentation for the wiki example something that should include a code sample
Projects
None yet
Development

No branches or pull requests

1 participant