@notifyon/vue
Version:
Vue SDK for NotifyOn
63 lines • 1.5 kB
JavaScript
// src/index.ts
import { defineComponent, onMounted, onUnmounted, ref, watch } from "vue";
import { connect } from "@notifyon/web";
var NotifyOn = defineComponent({
name: "NotifyOn",
props: {
publicKey: {
type: String,
required: true
},
userId: {
type: String,
required: true
}
},
setup(props) {
const instance = ref(null);
const isMounted = ref(false);
const initializeNotifyOn = () => {
if (typeof window === "undefined" || instance.value) {
return;
}
try {
instance.value = connect({
publicKey: props.publicKey,
userId: props.userId
});
} catch (error) {
console.error("Failed to initialize NotifyOn:", error);
}
};
onMounted(() => {
if (!isMounted.value) {
isMounted.value = true;
initializeNotifyOn();
}
});
watch(
() => [props.publicKey, props.userId],
(newValues, oldValues) => {
if (isMounted.value && JSON.stringify(newValues) !== JSON.stringify(oldValues)) {
if (instance.value) {
instance.value.destroy();
instance.value = null;
}
initializeNotifyOn();
}
}
);
onUnmounted(() => {
if (instance.value) {
instance.value.destroy();
instance.value = null;
}
isMounted.value = false;
});
return () => null;
}
});
export {
NotifyOn
};
//# sourceMappingURL=index.mjs.map