vanilla-js-state-management icon indicating copy to clipboard operation
vanilla-js-state-management copied to clipboard

Using with LitElement

Open chisholmd opened this issue 5 years ago • 6 comments
trafficstars

First thank you so much for this article and code. Such a nice break from untangling all the yarn and ts and other toolchain confusion.

I am still learning a lot of this stuff and I am trying to adapt this code for use with my app that is using LitElement.

Your sample code uses a new base class called component, and I was wondering what you would advise? Should I create myNewBaseClass that extends LitElements and include your constructor code? or is there a better approach? Thanks for any pointers

chisholmd avatar Apr 20 '20 03:04 chisholmd

I'm not 100% up to scratch with Lit stuff. Can you give me a sample of your code please?

Andy-set-studio avatar Apr 20 '20 19:04 Andy-set-studio

I figured it out, I had a little typo. Basically when using Lit-Element all your classes are extending LitElement. Just like your sample uses 'component' My instincts seemed to be correct as I just created a new class with your constructors that extended LitElement, and then all my elements extend this new class.

export class MiadminBaseclass extends LitElement {
	constructor(props = {}){
        super();
        let self = this;
       and the rest of the vanilla store code

And then my apps elements extend that.
class MiadminApp extends (MiadminBaseclass) {

chisholmd avatar Apr 20 '20 20:04 chisholmd

Glad to hear you sorted it!

Andy-set-studio avatar Apr 21 '20 17:04 Andy-set-studio

Working like a charm, and I have to thank you again for providing this walk through uncluttered by a dozen different tools. The ecosystem around some of this stuff is all to often turning "reusable" into "unusable".

chisholmd avatar Apr 21 '20 18:04 chisholmd

Hell yeh. That's exactly why I wrote it :)

Andy-set-studio avatar Apr 21 '20 18:04 Andy-set-studio

Hi, Thanks for the great repo. I am also using lit-Element. Can we push the litElement logic to creating a webcomponent with this state-management model ? I am thinking that it may be more convenient to use than extending a class. What do you think ?

madeInLagny avatar May 08 '20 05:05 madeInLagny