Skip to content

Commit

Permalink
fix mapGetters, mapState and mapActions
Browse files Browse the repository at this point in the history
  • Loading branch information
bippan1407 committed May 6, 2024
1 parent 6da1b61 commit 09aeb8b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/codemod.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ class Codemod {

addSyntaxInOrder = () => {
let order = [
"imports",
"head",
"imports",
"layout",
"emits",
"props",
Expand All @@ -347,6 +346,7 @@ class Codemod {
"methods",
"lifecycleHooks",
"provide",
"head",
"codeToMigrateManually",
];
let newUpdatedSyntax = "\n";
Expand Down
4 changes: 2 additions & 2 deletions src/vueProperties/getVuexActionNames/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const transform = ({ root, j }) => {
if (getterNameIndex !== -1) {
names.forEach((data) => {
const currentName = data.value.value;
let asName = data.key.name;
let asName = data.key.name ?? data?.key?.value;
if (asName === currentName) {
asName = undefined;
}
Expand All @@ -66,7 +66,7 @@ const transform = ({ root, j }) => {
names.forEach((data) => {
let [storeName, currentActionName] = data.value.value.split("/");
let options = { isMapped: true };
options.as = data.key.name;
options.as = data.key.name ?? data?.key?.value;
if (options.as === currentActionName) {
options.as = undefined;
}
Expand Down
5 changes: 5 additions & 0 deletions src/vueProperties/getVuexActionNames/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ test("get all vuex actions in vue file", () => {
document: [{ name: "newDocument", isMapped: true, as: "document" }],
guest: [
{ name: "isInterested", isMapped: true, as: "isGuest" },
{
name: "isNotInterested",
as: "userNotInterested",
isMapped: true,
},
{ name: "username" },
{ name: "name", params: "'jerry'" },
{ name: "age", params: "10" },
Expand Down
3 changes: 2 additions & 1 deletion src/vueProperties/getVuexActionNames/test.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ export default {
...mapActions('documents', ['requiredDocuments']),
...mapActions('documents', ['requiredDocuments', 'oldDocument']),
...mapActions({
user: "user/isPremium",
'user': "user/isPremium",
document: "document/newDocument",
}),
...mapActions('guest', {
isGuest: "isInterested",
'userNotInterested': "isNotInterested",
}),
click() {
this.$store.commit('app/newApplication')
Expand Down
4 changes: 2 additions & 2 deletions src/vueProperties/getVuexGetterNames/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const transform = ({ root, j }) => {
getterNames.forEach((getterName) => {
const options = {};
let currentName = getterName.value.value;
let asName = getterName.key.name;
let asName = getterName?.key?.name ?? getterName?.key?.value;
if (asName !== currentName) {
options.as = asName;
}
Expand All @@ -94,7 +94,7 @@ const transform = ({ root, j }) => {
const options = {};
let [storeName, currentGetterName] =
getterName?.value?.value?.split("/") ?? [];
let asName = getterName?.key?.name;
let asName = getterName?.key?.name ?? getterName?.key?.value;
if (asName !== currentGetterName) {
options.as = asName;
}
Expand Down
4 changes: 2 additions & 2 deletions src/vueProperties/getVuexGetterNames/test.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export default {
...mapGetters('documents', ['requiredDocuments']),
...mapGetters('documents', ['requiredDocuments', 'oldDocument']),
...mapGetters({
user: "user/isPremium",
'user': "user/isPremium",
document: "document/newDocument",
app: "apps/app"
}),
...mapGetters('guest', {
isGuest: "isInterested",
'isGuest': "isInterested",
newApplication: 'newApplication'
}),
},
Expand Down

0 comments on commit 09aeb8b

Please sign in to comment.