gerarts / lit-redux-watch Goto Github PK
View Code? Open in Web Editor NEWAttach Redux store state and Reselect selectors to properties in LitElement with a decorator or static getter
License: MIT License
Attach Redux store state and Reselect selectors to properties in LitElement with a decorator or static getter
License: MIT License
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);
}
Watchers stay active after disconnectedCallback
is called causing side-effects
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
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.