GithubHelp home page GithubHelp logo

gerarts / lit-redux-watch Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 0.0 1.29 MB

Attach Redux store state and Reselect selectors to properties in LitElement with a decorator or static getter

License: MIT License

TypeScript 99.16% JavaScript 0.84%
redux decorators typescript lit-element reselect

lit-redux-watch's People

Contributors

gerarts avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lit-redux-watch's Issues

LitElement changed lifecycle hook doesn't fire when Redux store changes

When using the @watch decorator on the Redux store, if another component modifies the store, I would expect the changed lifecycle hook to fire in the component, but it currently does not.

export class MyElement extends connect(store)(LitElement) {
    constructor() {
      super();
    }

    @watch('restaurants.restaurantList')
    public restaurantList: any = {
      data: []
    }

    changed(something: any) {
      // this doesn't fire when `this.restaurantList` changes 
      console.log("something changed: ", something);
    }

Error when bundling (`this` has been rewritten to `undefined`)

Hello, I am using rollup to bundle my app and getting a (non-fatal) error:

dist/index.html → dist...
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/lit-redux-watch/dist/components/connect.js: (1:13)
(!) Error when using sourcemap for reporting an error: Can't resolve original location of error.
node_modules/lit-redux-watch/dist/components/connect.js: (1:21)
(!) `this` has been rewritten to `undefined`
https://rollupjs.org/guide/en/#error-this-is-undefined
node_modules/lit-redux-watch/dist/components/connect.js
1: var __rest = this && this.__rest || function (s, e) {
                ^
2:   var t = {};
...and 1 other occurrence
node_modules/marked/lib/marked.js
1386:   root.marked = marked;
1387: }
1388: })(this || (typeof window !== 'undefined' ? window : global));
         ^
created dist in 13.7s

Using watch as a normal function

Is it possible to use watch as a normal function and not as a watch decorator?
I am using your package because of course the decorators are best suited but I am facing a situation where I need to update my view from a selector and that selector depends on one variable on that custom Element. Let me provide you with an example

Somewhere :

render () {
  const myCustomElement = new CustomElement('2k32fa0auiccDc2F')
  return html`
    ${myCustomElement}
  `
}

Elsewhere :

class CustomElement extends connect(store)(LitElement) {

  constructor (id: string) {
    super()
    
    const selector = (state: RootState) => state.user.documents.find(d => d.id == id).content
    /** ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
     * I now need to register a watch with that selector,
     * so I can update that custom element instance only when the target document's content changes.
     * Using the @watch decorator won't work from the static context because `id` is passed on instanciation.
     * /
  }

  render () { ... }
}

If there is a hack, please let me know Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.