Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
};
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) {
state.posts = [...state.posts, post];
},
updatePost(post) {
state.posts = state.posts.map(item => {
if (item.id !== post.id) {
// This isn't the post we care about - keep it as-is
return item
}
// Otherwise, this is the one we want - return an updated value
return {
import _ from 'lodash';
import * as remx from 'remx';
const MAX_TOPICS_SELECTED = 3;
const state = remx.state({
loading: true,
topicsByUrl: {},
selectedTopicUrls: [],
finishedTopicsSelection: false
});
export const setters = remx.setters({
setTopics(topics) {
state.topicsByUrl = _.keyBy(topics, (t) => t.url);
state.loading = false;
},
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;
const remx = require('remx');
const state = remx.state({
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;
import _ from 'lodash';
import * as remx from 'remx';
const state = remx.state({
loading: true,
postsById: {},
selectedPostId: '',
currentFilter: 'all'
});
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() {
import * as remx from 'remx';
const state = remx.state({
myItems: ['nacho', 'burrito', 'hotdog']
});
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() {