npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lit-cherry

v2.7.4

Published

A small cherry on lit

Downloads

7

Readme

lit-cherry

Published on npm

lit-cherry is a LitElement-extended class that gives you all the benefits of LitElement + some of the most missing features LitElement doesn't provide by default.

Overview

// [1]
import {LitCherry, customElement, debounce, html} from 'lit-cherry'

@customElement('my-element')
export class MyElement extends LitCherry {

  render({ sayHello }) { // [2]
    return html`
      <input id="username" @keydown=${sayHello} />

      <div id="container"></div>
    `
  }

  @debounce(1000) // [3]
  sayHello() {
    // [4]
    const helloStr = `Hello ${this.$.username.value}!`;
    this.$.container.textContent = helloStr;
  }
}
  • [1] import everything from one place

  • [2] instance argument old syntax

  • [3] support debouncing class methods

  • [4] $ getter for your template's ids

What's more?

Because lit-cherry uses LitElement, you don't need to install it. You can always import LitElement from the same package.

import {LitElement} from 'lit-cherry'

Note that lit-cherry version is in sync with lit version (starting from 2.7.4).
For instance if you want to use lit 2.7.4 in your project, in Deno you would use:

import {LitElement} from 'npm:[email protected]'
// [email protected]

About decorators

The decorators (@debounce, @delay, @lock) work on any class's method. In other words they are not specific to LitElement/LitCherry,

import {debounce} from 'lit-cherry'

class RandomClass {
  @debounce(250)
  static doSomething() {}
}

RandomClass.doSomething()

@delay (alias: @timeout)

Delay the execution of a method,

class MyClass {
  @delay(1000)
  saySomething() {
    console.log('Hello, you waited 1s.')
  }
}

Note that this decorator turns the method async, a cancel function is provided in case you want to stop the execution,

class MyClass {
  @delay(2000)
  static returnSomething() {
    return 'something';
  }
}

let promise;
promise = MyClass.returnSomething();
console.log(await promise); // prints 'something' after 2 seconds

promise = MyClass.returnSomething(); // new call
promise.cancel(); // cancel the timeout
try {
  console.log(await promise); // promise was canceled, catch is called
} catch (err) {
  /* canceled, do something */
}

@lock

lock decorator makes sure an async method is not called again before it has finished being executed. For example:

class MyElement extends LitElement {
  @lock
  async saySomething() {
    console.log('something')
  }
}

myElement.saySomething() // prints 'something'
myElement.saySomething() // does nothing

The lock decorator always returns the current unresolved promise:

const initialPromise = myElement.returnSomething();
const secondCall = myElement.returnSomething();
initialPromise == secondCall// true
await initialPromise // 'something'
await secondCall // 'something'

const thirdCall = myElement.returnSomething()
thirdCall == secondCall // false

Contributing

If you think about a cool feature to implement, please open an issue to let me know. I also accept PR's.