Packages

Helpers for rendering components from front-end frameworks in Phoenix

Current section

Files

Jump to
phx_frontend js dist index.js
Raw

js/dist/index.js

const n = ({
apps: e
}) => ({
mounted() {
const t = this.el.dataset.component;
if (this.adapter = e[t], !this.adapter)
throw new Error(
`Couldn't find JS app adapter for "${t}" - have you added it to the list of apps in the jsApp hook?`
);
const s = JSON.parse(this.el.dataset.props), a = JSON.parse(this.el.dataset.callbacks);
this.mountReturnValue = this.adapter.mount(
this.el,
s,
a,
(o, p) => this.pushEvent(o, p)
);
},
updated() {
const t = JSON.parse(this.el.dataset.props);
this.adapter.update(this.mountReturnValue, t);
},
destroyed() {
this.adapter.unmount(this.mountReturnValue);
}
});
export {
n as createJsAppsHook
};