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

polymer-2-decorators

v1.1.1

Published

JS decorators for Polymer 2

Downloads

35

Readme

Polymer 2 Decorators

Decorators can be used to describe element properties, observers, etc.

@customElement(tagName)

Sets the tag name of the custom element. The decorator is applied to the class. Tag names must include a - as per WebComponents specs.

Example of a <my-element>:

@customElement('my-element')
class MyElement extends Polymer.Element {

}

@property(propertyConfig)

Creates a Polymer property. It can be applied to a static class properties only.

The parameter propertyConfig is a map object that sets the options for the property:

{
    type?: enum;                     // Boolean, Date, Number, String, Array or Object
    reflectToAttribute?: boolean;    // should the property reflect to attribute
    readonly?: boolean;              // marks property as read-only
    notify?: boolean;                // if set to true, will trigger "propname-changed"
    computed?: string;               // computed function name (as string)
}

Examples:

@property
static foo;
// type: is specified for property deserialization.
// Used when it is passed to another elements in html attribute
@property({type: Number})
static initialValue = 42;
@property({readonly: true, computed: '_computeValue(foo, initialValue)'})
static computedReadOnlyValue = 0;

_computeValue(foo, initialValue) {
  return foo.toString() + initialValue;
}

@computed(propList, computedFn)

Makes a property computed. It can be applied to a static class properties only.

@property
static one = 'one';

@property
static two = 'two';

@property
@computed('one, two', (one, two) => one + two)
static three;

@observe(propList)

Sets an observer function for a single property or a list of properties.

If observing a single property, the function should be of the type function(newValue, oldValue).

If observing multiple properties (comma separated), the function receives only the new values, in the same order of the list.

// single property observer
@observe('name')
nameChanged(newName, oldName) {
   // ...
}
// multiple property observer
@observe('firstname, lastname')
fullnameChanged(newFirstName, newLastName) {
   // ...
}

@observeOnValue(prop)

Same as @observe decorator, but the function is called when the newValue is not null or undefined.

Only single property can be observed.

@observeSinceValue(prop)

Same as @observe decorator, but the function is called on the next change, since property was initialized with any value (oldValue !== undefined).

Only single property can be observed.

@eventListener(eventType, options)

Sets an event listener for the element and binds it to a function. Options — addEventListener options.

@eventListener('click')
onClick(e) {
   e.stopPropagation();
}

@statePath(statePath)

Use with polymer-redux

Assigns a Polymer property to reflect the Redux app state.

  @property
  @statePath('objects.total')
  static totalItems;

@routerStateParameter(stateParameter, options)

Use with polymer-2-ui-router

Assigns a Polymer property to reflect current ui-router state parameter.

The parameter options is a map object that sets the options for the property:

{
    reflectToState?: boolean;    // should the property be reflected back to state on change
}
  @property
  @routerStateParameter('page')
  static currentPage;