Home

Awesome

XSM

<p> <a href="https://bundlephobia.com/result?p=xsm"> <img src="https://flat.badgen.net/bundlephobia/minzip/xsm" alt="Minified + gzip package size for xsm in KB"> </a> <a href="https://travis-ci.com/peterluhub/xsm"> <img src="https://travis-ci.com/peterluhub/xsm.svg?branch=master" alt="Build Status"> </a> <a href="https://www.npmjs.com/package/xsm"> <img src="https://img.shields.io/npm/v/xsm.svg" alt="npm version"> </a> <a href="https://packagephobia.now.sh/result?p=xsm"> <img src="https://packagephobia.now.sh/badge?p=xsm" alt="install size"> </a> <a href="https://github.com/peterluhub/usm/blob/master/LICENSE"> <img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" target="_blank" /> </a> </p>

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

<table border="0"> <thead> <tr> <th>Library</th> <th>Minzipped Size</th> </tr> </thead> <tbody> <tr> <td>XSM</td> <td> <img src="https://flat.badgen.net/bundlephobia/minzip/xsm" alt="Minified + gzip package size for xsm in KB"> </td> </tr> <tr> <td>Redux</td> <td> <img src="https://flat.badgen.net/bundlephobia/minzip/redux" alt="Minified + gzip package size for redux in KB" class="badge--in-table"> </td> </tr> <tr> <td>react-Redux</td> <td> <img src="https://flat.badgen.net/bundlephobia/minzip/react-redux" alt="Minified + gzip package size for react-redux in KB" class="badge--in-table"> </td> </tr> <tr> <td>mobx</td> <td> <img src="https://flat.badgen.net/bundlephobia/minzip/mobx" alt="Minified + gzip package size for mobx in KB" class="badge--in-table"> </td> </tr> <tr> <td>mobx-react</td> <td> <img src="https://flat.badgen.net/bundlephobia/minzip/mobx-react" alt="Minified + gzip package size for mobx-react in KB" class="badge--in-table"> </td> </tr> <tr> <td>Vuex</td> <td> <img src="https://flat.badgen.net/bundlephobia/minzip/vuex" alt="Minified + gzip package size for vuex in KB" class="badge--in-table"> </td> </tr> <tr> <td>RXJS</td> <td> <img src="https://flat.badgen.net/bundlephobia/minzip/rxjs" alt="Minified + gzip package size for rxjs in KB" class="badge--in-table"> </td> </tr> <tbody> </table>

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
  setup({'framework': 'React'})
  bindState(this, {key: val, key2: val2, ...})
  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
    }
 )

setcfg - It is an alias of setup.

User Guide

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

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