Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remx

Package Overview
Dependencies
Maintainers
0
Versions
1254
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remx

Opinionated mobx

  • 4.0.112
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
520
decreased by-43.84%
Maintainers
0
Weekly downloads
 
Created
Source

SWUbanner

remx Build Status

Remx is opinionated state-management library for React apps.

Website with getting started and docs: https://wix.github.io/remx/

  • Remx takes the redux (flux) architecture and enforces it using a small, simple, clean, and strict API:
    • state
    • setters
    • getters
    • observe
    • useConnect
  • almost zero boilerplate
  • zero impact on tests
    • can be added/removed as a plugin
    • does not impact any design decisions
  • implemented with mobx, thus benefits from all the performance you get with
    • memoization
    • avoiding unnecessary re-renders
  • uses es6 Proxies (where possible)
    • avoids mobx's Observable wrappers which can cause weird behaviour and bugs

Installation

npm install remx

API

  • Create state

remx.state(initialState)

import * as remx from "remx";

const initialState = {
  loading: true,
  posts: {},

  selectedPosts: [],
};

const state = remx.state(initialState);
  • Define setters and getters

remx.getters(...)

import * as remx from "remx";

const setters = remx.setters({
  setLoading(isLoading) {
    state.loading = isLoading;
  },

  addPost(post) {
    state.posts.push(post);
  },
});

const getters = remx.getters({
  isLoading() {
    return state.loading;
  },

  getPostsByIndex(index) {
    return state.posts[index];
  },
});

export const store = {
  ...setters,
  ...getters,
};
  • Use observer to force a component to re-render if store data was used during previous render.

remx.observer(MyComponent)

import { observer } from "remx";

class SomeComponent extends React.Component {
  render() {
    return <div>{store.getPostById(this.props.selectedPostId)}</div>;
  }
}

export default observer(SomeComponent);

Also, works with functional components:

import { observer } from "remx";

export default observer((props) => (
  <div>{store.getPostById(props.selectedPostId)}</div>
));

Keywords

FAQs

Package last updated on 22 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc