Currently only Vue written Class is supported because decorators are available.

This is a new state management library, from a bit of new ideas source address

The front end likes to make simple things complicated. Things that native code can already do. Must be in order to the current end of the network red, make some complex, big and useless things.

Now let’s get rid of Vuex, Flux, Redux, etc., which is complicated and mentally taxing. Pure object orientation is good enough to manage state, and better. Less mental burden, simpler public interface. You can see it at a glance.

usage

This Class needs to inherit the Vanx Class with two methods plus and minus, and a state: result Calls plus or minus will add or subtract one from result

import Vanx from 'vanx';

class Calcutor extends Vanx {
  protected result = 0;
  public plus() {
    this.result++;
  }
  public minus() {
    this.result--; }}// Instantiate and export the state management class
export const calcutor = new Calcutor();
Copy the code

And then in the Vue file

import { Component, Prop, Vue } from 'vue-property-decorator';
import { calcutor } from './store'; 

@Component
export default class HelloWorld extends Vue {
  // One method that uses the class you just exported is called a decorator. The argument is the variable name of the state you want to inject into the Vue
  @calcutor.decorator('result')
  privatecalcutorResult! :number;
  private plus() {
   // Then call the method of the state management class,
   // Vanx will tell vue to update the Dom
    calcutor.plus();
  }
  private minus(){ calcutor.minus(); }}Copy the code

If you want to try it, you can do it directly

npm install --save vanx
Copy the code