Skip to content
This repository was archived by the owner on May 3, 2023. It is now read-only.

Commit d88b093

Browse files
committed
prep for v1
1 parent 17c5577 commit d88b093

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
**v1.0.0** [10 May 2019]
4+
5+
* Released the breaking changes in 0.7-beta as a v1.
6+
* Allow passing an `onSetupError` function to handle errors registering Elm web components. Thanks @PChambino for this PR.
7+
38
**v0.7.0-beta** [14 Feb 2019]
49

510
* **BREAKING**: this version supports the new Web Components V1 spec and **removes support for the V0 spec**. If you need to stay on the V0 spec, please stick to v0.6.1. Thanks @PChambino for the pull request implementing this.

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A small JavaScript package to let you wrap your Elm applications up in a web component.
44

5-
## NOTE: this documentation is for v0.7.0-beta, which supports V1 of the Web Elements spec. If you still need V0, please [check the docs for 0.6.1](https://github.com/thread/elm-web-components/tree/0.6.1)
5+
**Only supports the V1 web component spec**.
66

77
## Install
88

@@ -140,7 +140,7 @@ Rendering the component with:
140140

141141
Will pass the flags as `{ someId : Int }`, rather than `{ someId : String }`.
142142

143-
## `onDetached` (new in 0.3.0)
143+
## `onDetached`
144144

145145
If you need to do some work when the Elm component is removed from the DOM, you can now pass `onDetached: () => ...` as another option:
146146

@@ -158,6 +158,18 @@ elmWebComponents.register('component-with-ports', ComponentWithPorts, {
158158

159159
This is useful for tidying up any event listeners you might have.
160160

161+
## Handling errors
162+
163+
If you want to catch any errors registering the component, you can pass `onSetupError`:
164+
165+
```js
166+
elmWebComponents.register('component-with-ports', ComponentWithPorts, {
167+
onSetupError: error => {
168+
console.log('Something went wrong', error)
169+
},
170+
})
171+
```
172+
161173
## Examples
162174

163175
You can find full examples in the `example` directory. If you have cloned the repository, you can run `yarn run example` to run them locally.

src/index.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const elmWebComponents = {
4141
staticFlags = {},
4242
onDetached = () => {},
4343
mapFlags = flags => flags,
44-
onSetupError = () => {}
44+
onSetupError,
4545
} = {}
4646
) {
4747
if (!this.__elmVersion) {
@@ -62,13 +62,13 @@ const elmWebComponents = {
6262

6363
class ElmElement extends HTMLElement {
6464
connectedCallback() {
65-
const context = {};
65+
const context = {}
6666
try {
6767
let props = Object.assign({}, getProps(this), staticFlags)
6868
if (Object.keys(props).length === 0) props = undefined
6969

7070
const flags = mapFlags(props)
71-
context.flags = flags;
71+
context.flags = flags
7272

7373
if (elmVersion === '0.19') {
7474
/* a change in Elm 0.19 means that ElmComponent.init now replaces the node you give it
@@ -90,8 +90,15 @@ const elmWebComponents = {
9090
setupPorts(elmElement.ports)
9191
}
9292
} catch (error) {
93-
console.error(error)
94-
onSetupError(error, context)
93+
if (onSetupError) {
94+
onSetupError(error, context)
95+
} else {
96+
console.error(
97+
`Error from elm-web-components registering ${name}`,
98+
'You can pass an `onSetupError` to handle these.',
99+
error
100+
)
101+
}
95102
}
96103
}
97104

@@ -100,7 +107,7 @@ const elmWebComponents = {
100107
}
101108
}
102109

103-
customElements.define(name, ElmElement);
110+
customElements.define(name, ElmElement)
104111
},
105112
}
106113

0 commit comments

Comments
 (0)