@meve/ui
Version:
Argon design system components library
75 lines (69 loc) • 1.71 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import Vue from 'vue';
import context from '.';
export function resolveLock() {
var lockCounts = Object.keys(context.locks).length;
lockCounts <= 0 ? document.body.classList.remove('m--lock') : document.body.classList.add('m--lock');
}
export function addLock(uid) {
Vue.set(context.locks, uid, 1);
resolveLock();
}
export function releaseLock(uid) {
delete context.locks[uid];
resolveLock();
}
export function createLockMixin(state, use) {
var _ref, _extends2;
var propWatcher = use ? (_ref = {}, _ref[use] = function (newValue) {
if (!newValue) {
releaseLock(this._uid);
} else if (newValue && this[state]) {
addLock(this._uid);
}
}, _ref) : {};
return {
watch: _extends({}, propWatcher, (_extends2 = {}, _extends2[state] = function (newValue) {
if (use && !this[use]) {
return;
}
if (newValue) {
addLock(this._uid);
} else {
releaseLock(this._uid);
}
}, _extends2)),
beforeMount: function beforeMount() {
if (use && !this[use]) {
return;
}
if (this[state]) {
addLock(this._uid);
}
},
beforeDestroy: function beforeDestroy() {
if (use && !this[use]) {
return;
}
if (this[state]) {
releaseLock(this._uid);
}
},
activated: function activated() {
if (use && !this[use]) {
return;
}
if (this[state]) {
addLock(this._uid);
}
},
deactivated: function deactivated() {
if (use && !this[use]) {
return;
}
if (this[state]) {
releaseLock(this._uid);
}
}
};
}