All Projects → peterluhub → Xsm

peterluhub / Xsm

State Management made eXtraordinarily simple and effective for Angular, React, and Vue

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Xsm

Mobx State Tree
Full-featured reactive state management without the boilerplate
Stars: ✭ 6,317 (+4477.54%)
Mutual labels:  state-management, mobx
Vue State Management Alternative
Vuex state management alternative for both Vue 1.x & 2.x
Stars: ✭ 67 (-51.45%)
Mutual labels:  vuex, state-management
Vue Entity Adapter
Package to maintain entities in Vuex.
Stars: ✭ 20 (-85.51%)
Mutual labels:  vuex, state-management
Blue Chip
Normalizes GraphQL and JSON:API payloads into your state management system and provides ORM selectors to prepare data to be consumed by components
Stars: ✭ 332 (+140.58%)
Mutual labels:  state-management, mobx
Vuex Pathify
Vue / Vuex plugin providing a unified path syntax to Vuex stores
Stars: ✭ 1,281 (+828.26%)
Mutual labels:  vuex, state-management
Ngrx Actions
⚡️ Actions and Reducer Utilities for NGRX
Stars: ✭ 348 (+152.17%)
Mutual labels:  state-management, ngrx
Duix
A State Manager focused on KISS and Pareto's Principle
Stars: ✭ 48 (-65.22%)
Mutual labels:  vuex, state-management
Usm
🏖 A concise & flexible state model for Redux/MobX/Vuex, etc.
Stars: ✭ 270 (+95.65%)
Mutual labels:  vuex, mobx
React Atom
A simple way manage state in React, inspired by Clojure(Script) and reagent.cljs
Stars: ✭ 133 (-3.62%)
Mutual labels:  state-management, mobx
Compare React State Management
React createContext vs Apollo vs MobX vs Redux in a simple todo app.
Stars: ✭ 81 (-41.3%)
Mutual labels:  state-management, mobx
Store
🚀 NGXS - State Management for Angular
Stars: ✭ 3,191 (+2212.32%)
Mutual labels:  state-management, ngrx
Datx
DatX is an opinionated JS/TS data store. It features support for simple property definition, references to other models and first-class TypeScript support.
Stars: ✭ 111 (-19.57%)
Mutual labels:  state-management, mobx
React Coat
Structured React + Redux with Typescript and support for isomorphic rendering beautifully(SSR)
Stars: ✭ 290 (+110.14%)
Mutual labels:  state-management, mobx
Vuex
🗃️ Centralized State Management for Vue.js.
Stars: ✭ 27,115 (+19548.55%)
Mutual labels:  vuex, state-management
Mobx Keystone
A MobX powered state management solution based on data trees with first class support for Typescript, support for snapshots, patches and much more
Stars: ✭ 284 (+105.8%)
Mutual labels:  state-management, mobx
Platform
Reactive libraries for Angular
Stars: ✭ 7,020 (+4986.96%)
Mutual labels:  state-management, ngrx
dotto.x
A tiny state manager for React, Svelte, Vue and vanilla JS
Stars: ✭ 104 (-24.64%)
Mutual labels:  state-management, svelte
micro-observables
A simple Observable library that can be used for easy state management in React applications.
Stars: ✭ 78 (-43.48%)
Mutual labels:  state-management, mobx
Flutter Boilerplate Project
A boilerplate project created in flutter using MobX and Provider.
Stars: ✭ 1,194 (+765.22%)
Mutual labels:  state-management, mobx
Reactstatemuseum
A whirlwind tour of React state management systems by example
Stars: ✭ 1,294 (+837.68%)
Mutual labels:  state-management, mobx

XSM

Minified + gzip package size for xsm in KB Build Status npm version install size License: MIT

XSM - State Management made eXtraordinarily simple and effective for Angular, React, Vue, and Svelte.

🏠 Homepage

Demos

Angular      React      Svelte      Vue

Realworld Example App with react-xsm

Highlights

  • Incredibly easy to use, developer friendly and minimum learning curve
  • Reactive, unintrusive
  • Automatic re-rendering and state data removal, efficient memory management
  • Super simple async handling
  • Same API for Angular, React, Vue, and Svelte, code reuse, framework agnostic
  • Small size for fast download, no framework specific plugins needed.
Library Minzipped Size
XSM Minified + gzip package size for xsm in KB
Redux Minified + gzip package size for redux in KB
react-Redux Minified + gzip package size for react-redux in KB
mobx Minified + gzip package size for mobx in KB
mobx-react Minified + gzip package size for mobx-react in KB
Vuex Minified + gzip package size for vuex in KB
RXJS Minified + gzip package size for rxjs in KB

Benchmark Results

XSM is performant according to Stefan Krause's js-framework-benchmark. As shown below, Benchmarks.

The code for the benchmarks is in this repo.

How-to's

Install
npm install xsm
Usage in Brief
  • Tell XSM which framework to use
  setup({'framework': 'React'})
  • Bind the component state to XSM
  bindState(this, {key: val, key2: val2, ...})
  • When you are ready to update the state(sync or async)
  set('key', val)

Component will be re-rendered automatically.

Debug and Trace

Both debug and trace can be selectively turn on and off at any point

setup({debug: true})  //debug on
setup({debug: false}) //debug off
setup({trace: true})  //trace on
setup({trace: false}) //trace off

Why XSM

To answer why, let's start by answering another question, what is XSM? It consists of a global store and the machinary to re-render the component when the state is updated. The store is just a javascript object with key and value pairs. By binding the instance reference, this, to the store, each component can react to the changes of the store whether it is re-render or unmount. It is really this simple, no need to use HOC, provider, reducer, decorator, observer, action, dispatcher, etc. Hence, all the three most popular frameworks work the same way in XSM and that's why we can keep the code size very small and support the three frameworks without framework specific modules. Svelte is very different from other frameworks. It is this less. The state object becomes this.

API

bindState - binds a component's this and optionally state to the store. The state is an object with key and value pairs. For Svelte, the value is a fuction that wraps the assignment of the value.

 bindState(this, state) //Angular, React, Vue
 bindState(state) //Svelte is this less, state is {key: val => stateVariable = val}

unbindState - If a component is mounted and unmounted repeatedly, you need to unbind the component state from the store when the component unmounts to prevent memory leak. This is needed for Svelte only. The unbinding is done aotumatically with the other frameworks by XSM.

 unbindState(state) //Svelte only

get - gets the value of a given key from the store.

 get(key)

set - updates the store with the value for a given key and re-renders the component(s).

 set(key, value)

setMany - updates the store for the given key and value pairs and re-renders the component(s).

 setMany({key1: value1, key2, value2, ...})

setup - It takes an object as an argument and is used for telling XSM which framework you app uses and optionally for binding the state of all components of the app to the store as well as turning the debug and trace on and off.

 setup(
    {framework: frameworkValue, 
     bindings: {ComponentName: {key1: value1,...},
             ComponentName1: {key1: value1,...},
            ...},
     debug: true/false,
     trace: true/false
    }
 )
  • frameworkValue: Angular, React, Vue, or Svelte
  • ComponentName: It is the class name for React and Angular. It is the registered component name for Vue. Does not apply to Svelte.
  • bindings: It serves two purposes. One is to bind the state of each component to the store and you don't need to binState in this case. Another is to tell XSM that which piece of data is shared by more than one components and the shared data will not be deleted even if the the components are unmounted. Does not apply to Svelte.

setcfg - It is an alias of setup.

User Guide

To use XSM to manage you app state, here are the steps to follow:

  • Use setup to bind XSM to a framework. Currently, XSM supports Angular, Reatc, Vue, and Svelte.

  • Bind the component state to the store with bindState to enble the auto re-rendering when the state is updated. The value of each bound key can be accessed in the component with this.keyname. For example, you want to bind a key and value pair of {title: 'XSM'} to a component,

  • For Angular and React, it is done in the constructor.

    constructor() {
        super()
        bindState(this, {title: 'XSM'})
    }
    
  • For Vue, it can be done in the created life cycle hook.

    created() {
        bindState(this, {title: 'XSM'})
    }
    
  • For Svelte, it can be done inside the script tag of a component.

    let title;
    let bindings = {title: val => title = val};
    bindState(bindings);
    //if needed
    onDestroy(() => unbindState(bindings));
    
  • When it's time to update the state, use set when and where your state data is available whether it's in the await function, promise.then callback, plain old callback, or anywhere in your code path. XSM does not get in the way.

  • Besides the demos, you can find more code examples in this repository. A realworld example(implementing the Realworld Example Specs using XSM with React is in this repo. Angular and Vue verions will be implemented soon.

Author

👤 Peter Lu

Show your support

Give a ⭐️ if this project helped you !

📝 License

This project is MIT licensed.


This README was originally generated with readme-md-generator

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].