Skip to content

Commit 60d8307

Browse files
authored
Merge pull request #3 from vedovelli/bugfix-ajax
Bugfix Multiple Event Handlers
2 parents 6b7e01e + da30c7f commit 60d8307

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

client/src/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export default {
3131
<style lang="sass" src="assets/sass/app.scss"></style>
3232

3333
<style scoped>
34-
.fade-enter-active {
34+
.fade-enter-active, .fade-leave-active {
3535
transition: opacity .5s ease;
3636
}
37-
.fade-enter {
37+
.fade-enter, .fade-leave-active {
3838
opacity: 0;
3939
}
4040
</style>

client/src/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11

2+
// export const apiUrl = 'http://spa.vedcasts.com.br/api/'
23
export const apiUrl = 'http://localhost:8000/api/'

client/src/modules/categories/main.vue

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,19 @@
162162
return this.$route.name === 'categories.new' || this.$route.name === 'categories.edit'
163163
},
164164
},
165+
/**
166+
* Right before navigate out to another route
167+
* clears all event handlers, thus avoiding
168+
* multiple handlers to be set and the annoying
169+
* behaviour of multiple AJAX calls being made.
170+
*/
171+
beforeRouteLeave(to, from, next) {
172+
this.$bus.$off('navigate')
173+
this.$bus.$off('category.created')
174+
this.$bus.$off('category.updated')
175+
jQuery('body').off('keyup')
176+
next()
177+
},
165178
mounted() {
166179
/**
167180
* Listen to pagination navigate event
@@ -172,15 +185,11 @@
172185
*/
173186
this.$bus.$on('category.created', () => this.fetch())
174187
this.$bus.$on('category.updated', () => this.fetch())
188+
175189
/**
176-
* We only fetch data the first time
177-
* component is mounted. We can set
178-
* up a timer to fetch new data
179-
* from time to time
190+
* Fetch data immediately after component is mounted
180191
*/
181-
if (this.pager.data === undefined) {
182-
this.fetch()
183-
}
192+
this.fetch()
184193
},
185194
/**
186195
* This hook is called every time DOM

webservice/app/Providers/EventServiceProvider.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ public function boot()
2929

3030
Event::listen('tymon.jwt.absent', function () {
3131
return response()->json(
32-
['reason' => 'token', 'messages' => ['Token não fornecido']], 400);
32+
['reason' => 'token', 'messages' => ['Token not provided']], 400);
3333
});
3434

3535
Event::listen('tymon.jwt.expired', function () {
3636
return response()->json(
37-
['reason' => 'token', 'messages' => ['Token expirado']], 400);
37+
['reason' => 'token', 'messages' => ['Expired Token']], 400);
3838
});
3939

4040
Event::listen('tymon.jwt.invalid', function () {
4141
return response()->json(
42-
['reason' => 'token', 'messages' => ['Token inválido']], 400);
42+
['reason' => 'token', 'messages' => ['Invalid Token']], 400);
4343
});
4444
}
4545
}

0 commit comments

Comments
 (0)