New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@morbidick/lit-element-notify

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@morbidick/lit-element-notify - npm Package Compare versions

Comparing version

to
0.4.0

index.js

18

package.json
{
"name": "@morbidick/lit-element-notify",
"version": "0.3.0",
"description": "Small mixin for LitElement to get easy change events via the properties getter",
"version": "0.4.0",
"description": "Small helpers for LitElement to dispatch change notifications and two-way binding",
"license": "MIT",

@@ -10,3 +10,15 @@ "repository": {

},
"main": "lit-element-notify.js"
"main": "index.js",
"dependencies": {
"@polymer/lit-element": "^0.6.3",
"lit-html": "^0.13.0"
},
"devDependencies": {
"@webcomponents/webcomponentsjs": "^2.0.2",
"polyserve": "^0.27.0"
},
"scripts": {
"start": "npm run serve",
"serve": "polyserve --npm --module-resolution=node"
}
}

@@ -1,6 +0,6 @@

# Change notification mixin for LitElement
# Change notification helpers for LitElement
[![npm version](https://img.shields.io/npm/v/@morbidick/lit-element-notify.svg)](https://www.npmjs.com/package/@morbidick/lit-element-notify)
Small mixin for LitElement to get easy change events via the `properties` getter.
Small helpers for LitElement to dispatch change notifications and two-way binding to siblings.

@@ -15,5 +15,17 @@ ## Install

### Notify mixin
Small mixin for LitElement to get easy change events via the `properties` getter.
This mixin adds the `notify` option to the property definition. Similar to the LitElement `attribute` option (which reflects a property to the dom) it fires an event as soon as the property value changes. The event name depends on the following conditions:
0. `notify: true`: the property gets lowercased and `-changed` is appended (note: contrary to PolymerElement and similar to LitElements attribute handling no camelCase to kebap-case conversion is done)
0. the notify option contains a string: `notify: 'success-event` fires an event named `success-event`
0. `notify: true` is set and the attribute option is a string (`attribute: 'attribute-name`): the attribute name will be suffixed with `-changed`
The updated value of the property is available in `event.detail.value`.
```javascript
import { LitElement, html } from '@polymer/lit-element/lit-element.js';
import LitNotify from '@morbidick/lit-element-notify/lit-element-notify.js';
import LitNotify from '@morbidick/lit-element-notify/notify.js';

@@ -51,1 +63,30 @@ class NotifyingElement extends LitNotify(LitElement) {

```
### Subscribe directive
lit-html directive to subscribe an element property to a sibling property, adding two-way binding to lit-element. The function takes three parameters:
1. the object on which the property will be updated
2. the property name to update
3. (optional) the event name to subscribe to, by default the property name will be lowercased and suffixed with `-changed`
```javascript
import { LitElement, html } from '@polymer/lit-element/lit-element.js';
import subscribe from '@morbidick/lit-element-notify/subscribe.js';
class SubscribingElement extends LitElement {
static get properties() {
return {
myProperty: {type: String},
myProperty2: {type: String},
};
}
render() {
return html`
<notifying-element
token=${subscribe(this, 'myProperty')}
.anotherProperty=${subscribe(this, 'myProperty2', 'another-attribute-changed')}
></notifying-element>`;
}
}
```
lit-element-notify.js

Sorry, the diff of this file is not supported yet