From 7c15bfd00ceea007d7f3c4e2e23fd66976e0a9de Mon Sep 17 00:00:00 2001 From: fitorec Date: Thu, 17 Dec 2020 14:03:27 -0600 Subject: [PATCH] check the arrows functions in demo-vue Anonymous functions, allow not to lose the instance of this --- demo-vue/app/components/Home.vue | 28 +++++++++++++--------------- demo-vue/package.json | 6 ++++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/demo-vue/app/components/Home.vue b/demo-vue/app/components/Home.vue index 9caec11..35927e0 100644 --- a/demo-vue/app/components/Home.vue +++ b/demo-vue/app/components/Home.vue @@ -33,8 +33,8 @@ } }, methods: { - enableLocationTap: function() { - geolocation.isEnabled().then(function (isEnabled) { + enableLocationTap: () => { + geolocation.isEnabled().then((isEnabled) => { if (!isEnabled) { geolocation.enableLocationRequest(true, true).then(() => { console.log("User Enabled Location Service"); @@ -44,34 +44,32 @@ console.log("Unable to Enable Location", ex); }); } - }, function (e) { + }, (e) => { console.log("Error: " + (e.message || e)); }); }, - buttonGetLocationTap: function() { - let that = this; + buttonGetLocationTap: () => { geolocation.getCurrentLocation({ desiredAccuracy: Accuracy.high, maximumAge: 5000, timeout: 10000 - }).then(function (loc) { + }).then((loc) => { if (loc) { - that.locations.push(loc); + this.locations.push(loc); } - }, function (e) { + }, (e) => { console.log("Error: " + (e.message || e)); }); }, - buttonStartTap: function() { + buttonStartTap: () => { try { - let that = this; this.watchIds.push(geolocation.watchLocation( - function (loc) { + (loc) => { if (loc) { - that.locations.push(loc); + this.locations.push(loc); } }, - function (e) { + (e) => { console.log("Error: " + e.message); }, { @@ -84,14 +82,14 @@ console.log("Error: " + ex.message); } }, - buttonStopTap: function() { + buttonStopTap: () => { let watchId = this.watchIds.pop(); while (watchId != null) { geolocation.clearWatch(watchId); watchId = this.watchIds.pop(); } }, - buttonClearTap: function() { + buttonClearTap: () => { this.locations.splice(0, this.locations.length); } } diff --git a/demo-vue/package.json b/demo-vue/package.json index 8ff6c20..6467ed3 100644 --- a/demo-vue/package.json +++ b/demo-vue/package.json @@ -22,10 +22,12 @@ "@babel/core": "~7.1.0", "@babel/preset-env": "~7.1.0", "babel-loader": "~8.0.0", + "eslint": "^7.15.0", + "eslint-plugin-vue": "^7.3.0", "nativescript-dev-webpack": "^1.3.0", "nativescript-vue-template-compiler": "~2.4.0", "node-sass": "~4.12.0", - "vue-loader": "~15.4.0", - "typescript": "~3.4.5" + "typescript": "~3.4.5", + "vue-loader": "~15.4.0" } }