@teamthread/elm-web-components
Advanced tools
Comparing version
@@ -20,3 +20,5 @@ // adapted from https://github.com/PixelsCommander/ReactiveElements | ||
_ref$staticFlags = _ref.staticFlags, | ||
staticFlags = _ref$staticFlags === void 0 ? {} : _ref$staticFlags; | ||
staticFlags = _ref$staticFlags === void 0 ? {} : _ref$staticFlags, | ||
_ref$onDetached = _ref.onDetached, | ||
onDetached = _ref$onDetached === void 0 ? function () {} : _ref$onDetached; | ||
@@ -32,2 +34,6 @@ var elementPrototype = Object.create(HTMLElement.prototype); | ||
elementPrototype.detachedCallback = function () { | ||
onDetached(); | ||
}; | ||
document.registerElement(name, { | ||
@@ -34,0 +40,0 @@ prototype: elementPrototype |
{ | ||
"name": "@teamthread/elm-web-components", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Run your Elm apps through web components.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -103,4 +103,21 @@ # elm-web-components | ||
Will end up with the Elm component having two flags: `someCustomProp` and `name`. | ||
## `onDetached` (new in 0.3.0) | ||
If you need to do some work when the Elm component is removed from the DOM, you can now pass `onDetached: () => ...` as another option: | ||
```js | ||
elmWebComponents.register('component-with-ports', ComponentWithPorts, { | ||
setupPorts: ports => {}, | ||
staticFlags: { | ||
someCustomProp: 'foo', | ||
}, | ||
onDetached: () => { | ||
console.log('Called when the component is removed from the DOM') | ||
} | ||
}) | ||
``` | ||
This is useful for tidying up any event listeners you might have. | ||
## Examples | ||
@@ -112,2 +129,6 @@ | ||
**v0.3.0** [3 May 2018] | ||
* You can now pass `onDetached` as an option. This is a callback function that will be run when component is removed from the DOM. | ||
**v0.2.0** [1 May 2018] | ||
@@ -114,0 +135,0 @@ |
5648
15.95%34
17.24%136
18.26%