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

component-decorators

v1.0.5

Published

Web Components Decorators and helpers

Downloads

7

Readme

Web component decorators · npm version

Decorators

import {} from 'component-decorators

@Component({ options })

Options

| Name | Type | Description | | ------- | ----------------- | ----------------------------------------------------------------------------------------------- | | selector | string | Name of the tag to use. Must include a '-' (minus) | | template | string (optional) | An inline template for an web component | | extends | string (optional) | The extends property, specifies the built-in element your element inherits from, if any (only relevant to customized built-in elements)| | style | CSSStyleDeclarations (optional) | The style property specifies an inline style for an element. | | providers | Component[] (optional) | Array of components/providers, which become parents of template | | slots | boolean (optional) | Enable slots in custom component |

Replacement for customElements.define(tagname, element, options). To be put right above the class declaration of the web component. In template you can interpolate paramaters of component lik this <template slot="{{states.TABLE}}">. WARNING! It's only initial value. If value will be change, in DOM stay initial value. If you want rerender value use @State decorator or change value in other way. Additionally if component use slots and filled it with own parameters you can use scopeProps to keep interpolate inside template.

  <template slot="trow">
    <tr id="{{ scopeProps('id') }}">
      <td>{{ scopeProps('name') }}</td>
    </tr>
  </template>

@Attr(name, type)

Parameters

| Name | Type | Description | | ------------- | ------ | --------------------- | | name | string | Name of the attribute | | type | 'string' | 'boolean' | 'number' | 'json' (default: 'string') | Type determines how attribute will be getting and setting |

To be put right above the property of component. This decorator strictly connect parameter with attribute.

@Context(selector)

Parameters

| Name | Type | Description | | ------------- | ------ | --------------------- | | selector | string | Selector for parent component/provider |

To be put right above the property of component. This decorator assings the property the value this.closest(selector).

@Listener(selector, type)

Parameters

| Name | Type | Description | | ------------- | ------ | --------------------- | | selector | string | Selector for child of component | | type | string | The name of the event |

To be put right above the method of component. Replacement for this.querySelector(selector).addEventListener.call(this, type, method);

@OnAttrChange(name)

Parameters

| Name | Type | Description | | ------------- | ------ | --------------------- | | name | string | Name of attribute |

To be put right above the method of component. Method will be call when attribute was change;

@On(selector, methodName)

Parameters

| Name | Type | Description | | ------------- | ------ | --------------------- | | selector | string | Selector for child of component | | methodName | string ex. 'onclick' | determines which method you want set |

To be put right above the method of component. Replacement for this.querySelector(selector)[methodName] = (...props) => method.call(this, ...props)

@Prop(selector, argument)

Parameters

| Name | Type | Description | | ------------- | ------ | --------------------- | | selector | string | Selector for child of component | | argument | string | determines which property you want get/set |

To be put right above the property of component. Replacement for this.querySelector(selector)[argument]

@Ref(selector)

Parameters

| Name | Type | Description | | ------------- | ------ | --------------------- | | selector | string | Selector for child of component |

To be put right above the property of component. This decorator assings the property the value this.querySelector(selector)

@State(...selectors)

To be put right above the property of component. Selectors define which element in DOM and how shuld be change after change value of property.

Examples

  @State('[helloMessage]')
  public helloMessage: string;

Now when property helloMessage was change element [helloMessage].innerHtml = helloMessage.

Also you can modified value before putting to DOM

  @State({ '[completedTaskCounter]': (value) => value.length })
  public array: any[];

A decorator configured this way change element [completedTaskCounter].innerHtml = array.length.

Other option is change other property of selected element not only innerHtml.

  @State({ '[completedTaskCounter].color': (value) => value.length ? 'green' : 'red' })
  public array: any[];

@Subscription()

To be put right above the method of component. Method will be fire inside connectedCallback. Decorated method should return another function which will be fire in disconnectedCallback to unsubscribe.

More

To see more information about library please visit our wiki