Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// title: 'Post 1',
// text: 'Post 1 text',
// img: 'https://picsum.photos/200/200/?image=977'
// },
// {
// id: 2,
// title: 'Post 2',
// text: 'Post 2 text',
// img: 'https://picsum.photos/200/200/?image=1'
// }
// ]
};
const state = remx.state(initialState);
const getters = remx.getters({
getPosts() {
return state.posts;
},
getPost(id) {
const post = _find(state.posts, {id})
return post;
}
});
const setters = remx.setters({
setPosts(posts) {
state.posts = posts;
},
addPost(post) {
const setters = remx.setters({
setNewItemText(txt) {
state.newItemText = txt;
},
addItem() {
state.myItems = state.myItems.concat(getters.getNewItemText());
state.newItemText = '';
},
clear() {
state.myItems = [];
}
});
const getters = remx.getters({
getItems() {
return state.myItems;
},
getNewItemText() {
return state.newItemText || '';
}
});
export const store = {
...getters,
...setters
};
export const setters = remx.setters({
setPosts(posts) {
state.postsById = _.keyBy(posts, (p) => p.id);
state.loading = false;
},
selectPost(postId) {
state.selectedPostId = postId;
},
setFilter(filter) {
state.currentFilter = filter;
}
});
export const getters = remx.getters({
isLoading() {
return state.loading;
},
getFilteredPostsById() {
return _.pickBy(state.postsById, (post) => getters.isPostMatchesFilter(post));
},
getFilteredPostsIdsArray() {
return _.keys(getters.getFilteredPostsById());
},
getSelectedPost() {
return _.get(state.postsById, state.selectedPostId);
},
toggleTopic(topicUrl) {
if (getters.isTopicSelected(topicUrl)) {
state.selectedTopicUrls = _.without(state.selectedTopicUrls, topicUrl);
} else {
state.selectedTopicUrls.push(topicUrl);
state.selectedTopicUrls = _.takeRight(state.selectedTopicUrls, MAX_TOPICS_SELECTED);
}
},
finishTopicsSelection() {
state.finishedTopicsSelection = true;
}
});
export const getters = remx.getters({
isLoading() {
return state.loading;
},
getAllTopicsByUrl() {
return state.topicsByUrl;
},
getAllTopicsUrls() {
return _.keys(state.topicsByUrl);
},
isTopicSelected(topicUrl) {
return _.includes(state.selectedTopicUrls, topicUrl);
},
person: {
name: 'no name'
}
});
const setters = remx.setters({
setName(newName) {
state.person.name = newName;
},
setAge(age) {
state.person.age = age;
}
});
const getters = remx.getters({
getName() {
return state.person.name;
},
getAge() {
return state.person.age;
}
});
module.exports = {
setters,
getters
};