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

Function eventsMixin

static/vuejs/vue.js:1846–1940  ·  view source on GitHub ↗
(Vue)

Source from the content-addressed store, hash-verified

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

Callers 1

vue.jsFile · 0.70

Calls 2

toArrayFunction · 0.70
hyphenateFunction · 0.50

Tested by

no test coverage detected