@notifyon/vue
Version:
Vue SDK for NotifyOn
88 lines (87 loc) • 2.58 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
NotifyOn: () => NotifyOn
});
module.exports = __toCommonJS(index_exports);
var import_vue = require("vue");
var import_web = require("@notifyon/web");
var NotifyOn = (0, import_vue.defineComponent)({
name: "NotifyOn",
props: {
publicKey: {
type: String,
required: true
},
userId: {
type: String,
required: true
}
},
setup(props) {
const instance = (0, import_vue.ref)(null);
const isMounted = (0, import_vue.ref)(false);
const initializeNotifyOn = () => {
if (typeof window === "undefined" || instance.value) {
return;
}
try {
instance.value = (0, import_web.connect)({
publicKey: props.publicKey,
userId: props.userId
});
} catch (error) {
console.error("Failed to initialize NotifyOn:", error);
}
};
(0, import_vue.onMounted)(() => {
if (!isMounted.value) {
isMounted.value = true;
initializeNotifyOn();
}
});
(0, import_vue.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();
}
}
);
(0, import_vue.onUnmounted)(() => {
if (instance.value) {
instance.value.destroy();
instance.value = null;
}
isMounted.value = false;
});
return () => null;
}
});
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
NotifyOn
});
//# sourceMappingURL=index.js.map
;