MCPcopy Create free account
hub / github.com/TruthHun/BookStack / eventsMixin

Function eventsMixin

static/vuejs/vue.runtime.common.js:1838–1932  ·  view source on GitHub ↗
(Vue)

Source from the content-addressed store, hash-verified

1836}
1837
1838function eventsMixin (Vue) {
1839 var hookRE = /^hook:/;
1840 Vue.prototype.$on = function (event, fn) {
1841 var this$1 = this;
1842
1843 var vm = this;
1844 if (Array.isArray(event)) {
1845 for (var i = 0, l = event.length; i < l; i++) {
1846 this$1.$on(event[i], fn);
1847 }
1848 } else {
1849 (vm._events[event] || (vm._events[event] = [])).push(fn);
1850 // optimize hook:event cost by using a boolean flag marked at registration
1851 // instead of a hash lookup
1852 if (hookRE.test(event)) {
1853 vm._hasHookEvent = true;
1854 }
1855 }
1856 return vm
1857 };
1858
1859 Vue.prototype.$once = function (event, fn) {
1860 var vm = this;
1861 function on () {
1862 vm.$off(event, on);
1863 fn.apply(vm, arguments);
1864 }
1865 on.fn = fn;
1866 vm.$on(event, on);
1867 return vm
1868 };
1869
1870 Vue.prototype.$off = function (event, fn) {
1871 var this$1 = this;
1872
1873 var vm = this;
1874 // all
1875 if (!arguments.length) {
1876 vm._events = Object.create(null);
1877 return vm
1878 }
1879 // array of events
1880 if (Array.isArray(event)) {
1881 for (var i$1 = 0, l = event.length; i$1 < l; i$1++) {
1882 this$1.$off(event[i$1], fn);
1883 }
1884 return vm
1885 }
1886 // specific event
1887 var cbs = vm._events[event];
1888 if (!cbs) {
1889 return vm
1890 }
1891 if (arguments.length === 1) {
1892 vm._events[event] = null;
1893 return vm
1894 }
1895 // specific handler

Callers 1

Calls 2

toArrayFunction · 0.70
hyphenateFunction · 0.50

Tested by

no test coverage detected