@channel-state/vue
Version:
Vue composables for channel-state, providing seamless integration with Vue applications for cross-context state management.
74 lines (68 loc) • 2.48 kB
JavaScript
var ChannelState = (function (exports) {
'use strict';
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
__defProp(target, "default", { value: mod, enumerable: true }) ,
mod
));
// globals:vue
var require_vue = __commonJS({
"globals:vue"(exports, module) {
module.exports = Vue;
}
});
// src/index.ts
var import_vue = __toESM(require_vue());
function useChannelState(store) {
const state = (0, import_vue.ref)(store.get());
const unsubscribe = store.subscribe((value) => {
state.value = value;
});
(0, import_vue.onUnmounted)(() => {
unsubscribe();
});
return (0, import_vue.computed)({
get() {
return state.value;
},
set(newValue) {
store.set(newValue);
}
});
}
function useChannelStatus(store) {
const status = (0, import_vue.ref)(store.status);
const unsubscribeStatus = store.subscribeStatus((newStatus) => {
status.value = newStatus;
});
(0, import_vue.onUnmounted)(() => {
unsubscribeStatus();
});
return status;
}
exports.useChannelState = useChannelState;
exports.useChannelStatus = useChannelStatus;
return exports;
})({});
//# sourceMappingURL=index.global.js.map
//# sourceMappingURL=index.global.js.map