How to use the remx.getters function in remx

To help you get started, we’ve selected a few remx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wix / react-native-crash-course / src / posts / posts.store.js View on Github external
//     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) {
github GantMan / ReactStateMuseum / React / simple-remx / src / remx / store.js View on Github external
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
};
github wix-incubator / react-dataflow-example / src / stores / posts / store.js View on Github external
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);
  },
github wix-incubator / react-dataflow-example / src / stores / topics / store.js View on Github external
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);
  },
github wix / react-native-navigation / integration / remx / MyStore.js View on Github external
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
};

remx

Opinionated mobx

MIT
Latest version published 2 months ago

Package Health Score

74 / 100
Full package analysis