How to use the remx.setters 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
};

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

remx

Opinionated mobx

MIT
Latest version published 3 months ago

Package Health Score

73 / 100
Full package analysis