Why does getter not return the value
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a getter that returns array of objects. The porblem is that I need past and actual warnings in different components.
It return only actual warning and ignoring past. But when I removing the map method it works correctly.
P.S I tried to split this getter in two getters
getPastOrActualWarnings: state => type => {
const now = +new Date()
let warnings
if (type === 'actual') {
warnings = state.warnings.filter(item => item.time * UNIX_TIMESTAMP > now)
} else if (type === 'past') {
warnings = state.warnings.filter(item => item.time * UNIX_TIMESTAMP < now)
} else {
warnings =
}
return warnings.map(dateToString)
}
function dateToString (item) {
item.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
return item
}
javascript vue.js vuex vuex-modules
add a comment |
I have a getter that returns array of objects. The porblem is that I need past and actual warnings in different components.
It return only actual warning and ignoring past. But when I removing the map method it works correctly.
P.S I tried to split this getter in two getters
getPastOrActualWarnings: state => type => {
const now = +new Date()
let warnings
if (type === 'actual') {
warnings = state.warnings.filter(item => item.time * UNIX_TIMESTAMP > now)
} else if (type === 'past') {
warnings = state.warnings.filter(item => item.time * UNIX_TIMESTAMP < now)
} else {
warnings =
}
return warnings.map(dateToString)
}
function dateToString (item) {
item.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
return item
}
javascript vue.js vuex vuex-modules
It looks like you no issue. Did you tried debugging type value. Try console.log(type);
– Sameer
Nov 23 '18 at 6:25
@SameerAhmad I invoke the function like thatgetPastWarnings () { return this.$store.getters.getPastOrActualWarnings('past') }
– Никита Лебедев
Nov 23 '18 at 6:31
@SameerAhmad the problem is in thewarnings.map(dateToString). It works correctly without map
– Никита Лебедев
Nov 23 '18 at 6:32
add a comment |
I have a getter that returns array of objects. The porblem is that I need past and actual warnings in different components.
It return only actual warning and ignoring past. But when I removing the map method it works correctly.
P.S I tried to split this getter in two getters
getPastOrActualWarnings: state => type => {
const now = +new Date()
let warnings
if (type === 'actual') {
warnings = state.warnings.filter(item => item.time * UNIX_TIMESTAMP > now)
} else if (type === 'past') {
warnings = state.warnings.filter(item => item.time * UNIX_TIMESTAMP < now)
} else {
warnings =
}
return warnings.map(dateToString)
}
function dateToString (item) {
item.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
return item
}
javascript vue.js vuex vuex-modules
I have a getter that returns array of objects. The porblem is that I need past and actual warnings in different components.
It return only actual warning and ignoring past. But when I removing the map method it works correctly.
P.S I tried to split this getter in two getters
getPastOrActualWarnings: state => type => {
const now = +new Date()
let warnings
if (type === 'actual') {
warnings = state.warnings.filter(item => item.time * UNIX_TIMESTAMP > now)
} else if (type === 'past') {
warnings = state.warnings.filter(item => item.time * UNIX_TIMESTAMP < now)
} else {
warnings =
}
return warnings.map(dateToString)
}
function dateToString (item) {
item.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
return item
}
javascript vue.js vuex vuex-modules
javascript vue.js vuex vuex-modules
edited Nov 23 '18 at 6:19
charlietfl
143k1391126
143k1391126
asked Nov 23 '18 at 6:13
Никита ЛебедевНикита Лебедев
154
154
It looks like you no issue. Did you tried debugging type value. Try console.log(type);
– Sameer
Nov 23 '18 at 6:25
@SameerAhmad I invoke the function like thatgetPastWarnings () { return this.$store.getters.getPastOrActualWarnings('past') }
– Никита Лебедев
Nov 23 '18 at 6:31
@SameerAhmad the problem is in thewarnings.map(dateToString). It works correctly without map
– Никита Лебедев
Nov 23 '18 at 6:32
add a comment |
It looks like you no issue. Did you tried debugging type value. Try console.log(type);
– Sameer
Nov 23 '18 at 6:25
@SameerAhmad I invoke the function like thatgetPastWarnings () { return this.$store.getters.getPastOrActualWarnings('past') }
– Никита Лебедев
Nov 23 '18 at 6:31
@SameerAhmad the problem is in thewarnings.map(dateToString). It works correctly without map
– Никита Лебедев
Nov 23 '18 at 6:32
It looks like you no issue. Did you tried debugging type value. Try console.log(type);
– Sameer
Nov 23 '18 at 6:25
It looks like you no issue. Did you tried debugging type value. Try console.log(type);
– Sameer
Nov 23 '18 at 6:25
@SameerAhmad I invoke the function like that
getPastWarnings () { return this.$store.getters.getPastOrActualWarnings('past') }– Никита Лебедев
Nov 23 '18 at 6:31
@SameerAhmad I invoke the function like that
getPastWarnings () { return this.$store.getters.getPastOrActualWarnings('past') }– Никита Лебедев
Nov 23 '18 at 6:31
@SameerAhmad the problem is in the
warnings.map(dateToString). It works correctly without map– Никита Лебедев
Nov 23 '18 at 6:32
@SameerAhmad the problem is in the
warnings.map(dateToString). It works correctly without map– Никита Лебедев
Nov 23 '18 at 6:32
add a comment |
1 Answer
1
active
oldest
votes
The problem is that you are modifying the state directly with your getter, which is something you should never do. The following line modifies item.time, which you previously used to sort the items. item is a reference to the object that is stored in the state.
item.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
To solve the issue, you can do one of two things:
Use a different name for your rendered time
item.renderedTime = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
(Shallow) copy the item so you are modifying a local copy, rather than the one in the state
function dateToString(item) {
const localItem = { ...item };
localItem.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString(
"ru-RU"
);
return localItem;
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441455%2fwhy-does-getter-not-return-the-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The problem is that you are modifying the state directly with your getter, which is something you should never do. The following line modifies item.time, which you previously used to sort the items. item is a reference to the object that is stored in the state.
item.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
To solve the issue, you can do one of two things:
Use a different name for your rendered time
item.renderedTime = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
(Shallow) copy the item so you are modifying a local copy, rather than the one in the state
function dateToString(item) {
const localItem = { ...item };
localItem.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString(
"ru-RU"
);
return localItem;
}
add a comment |
The problem is that you are modifying the state directly with your getter, which is something you should never do. The following line modifies item.time, which you previously used to sort the items. item is a reference to the object that is stored in the state.
item.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
To solve the issue, you can do one of two things:
Use a different name for your rendered time
item.renderedTime = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
(Shallow) copy the item so you are modifying a local copy, rather than the one in the state
function dateToString(item) {
const localItem = { ...item };
localItem.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString(
"ru-RU"
);
return localItem;
}
add a comment |
The problem is that you are modifying the state directly with your getter, which is something you should never do. The following line modifies item.time, which you previously used to sort the items. item is a reference to the object that is stored in the state.
item.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
To solve the issue, you can do one of two things:
Use a different name for your rendered time
item.renderedTime = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
(Shallow) copy the item so you are modifying a local copy, rather than the one in the state
function dateToString(item) {
const localItem = { ...item };
localItem.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString(
"ru-RU"
);
return localItem;
}
The problem is that you are modifying the state directly with your getter, which is something you should never do. The following line modifies item.time, which you previously used to sort the items. item is a reference to the object that is stored in the state.
item.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
To solve the issue, you can do one of two things:
Use a different name for your rendered time
item.renderedTime = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString('ru-RU', DATE_OPTIONS)
(Shallow) copy the item so you are modifying a local copy, rather than the one in the state
function dateToString(item) {
const localItem = { ...item };
localItem.time = new Date(item.time * UNIX_TIMESTAMP).toLocaleDateString(
"ru-RU"
);
return localItem;
}
answered Nov 23 '18 at 9:17
Sumurai8Sumurai8
14k83564
14k83564
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441455%2fwhy-does-getter-not-return-the-value%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It looks like you no issue. Did you tried debugging type value. Try console.log(type);
– Sameer
Nov 23 '18 at 6:25
@SameerAhmad I invoke the function like that
getPastWarnings () { return this.$store.getters.getPastOrActualWarnings('past') }– Никита Лебедев
Nov 23 '18 at 6:31
@SameerAhmad the problem is in the
warnings.map(dateToString). It works correctly without map– Никита Лебедев
Nov 23 '18 at 6:32