Skip to content

Commit 99490ac

Browse files
more syntactically pleasing article modules
Signed-off-by: Arnav Gupta <[email protected]>
1 parent 0da120a commit 99490ac

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

src/store/modules/articles.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
VuexModule,
44
getModule,
55
Mutation,
6-
Action,
6+
Action, MutationAction,
77
} from 'vuex-module-decorators';
88
import store from '@/store';
99
import { Article } from '../models';
@@ -19,15 +19,12 @@ type FeedType = 'global' | 'user'
1919
class ArticlesModule extends VuexModule {
2020
feed: Article[] = [];
2121

22-
@Mutation
23-
setFeed(articles: Article[]) {
24-
this.feed = articles;
25-
}
26-
27-
@Action({ commit: 'setFeed' })
22+
@MutationAction
2823
async refreshFeed(feedType: FeedType) {
2924
const globalFeed = await api.getGlobalFeed();
30-
return globalFeed.articles;
25+
return {
26+
feed: globalFeed.articles
27+
};
3128
}
3229
}
3330

src/store/modules/users.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getModule, Module, Mutation, MutationAction, VuexModule } from 'vuex-module-decorators';
1+
import { getModule, Module, MutationAction, VuexModule } from 'vuex-module-decorators';
22
import store from '@/store';
33
import { Profile, User, UserSubmit } from '../models';
44
import { fetchProfile, loginUser } from '../api';
@@ -10,18 +10,9 @@ import { fetchProfile, loginUser } from '../api';
1010
dynamic: true,
1111
})
1212
class UsersModule extends VuexModule {
13-
user: User | null = null
14-
profile: Profile | null = null
13+
user: User | null = null;
14+
profile: Profile | null = null;
1515

16-
@Mutation
17-
setUser(user: User) {
18-
this.user = user;
19-
}
20-
21-
@Mutation
22-
setProfile(profile: Profile) {
23-
this.profile = profile;
24-
}
2516

2617
get username() {
2718
return (this.user && this.user.username) || null;

src/views/Home.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,17 @@
5353
import { Vue, Component } from 'vue-property-decorator';
5454
import ArticlePreview from '@/components/article/ArticlePreview.vue';
5555
import articles from '@/store/modules/articles';
56-
import { Article } from '@/store/models';
5756
5857
@Component({
5958
components: {
6059
ArticlePreview,
6160
},
6261
})
6362
export default class extends Vue {
64-
feed: Article[] = [];
63+
get feed() { return articles.feed }
6564
66-
created() {
67-
articles.refreshFeed('global').then(() => {
68-
this.feed = articles.feed;
69-
});
65+
async created() {
66+
await articles.refreshFeed('global')
7067
}
7168
}
7269
</script>

0 commit comments

Comments
 (0)