npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

mobx-vue-helper

v0.2.5

Published

MobX Class & JSX helpers for Vue 3 components, providing seamless integration with MobX state management for both class and function components.

Readme

MobX-Vue-helper

MobX Class & JSX helpers for Vue 3 components, providing seamless integration with MobX state management for both class and function components.

NPM publishing NPM License: LGPL v2.1

Features

  • 🎯 Universal Support: Works with both class and function components
  • 🔄 Auto Reactivity: Automatically tracks and reacts to MobX observable state changes
  • Reaction Decorator: @reaction() decorator for declarative side effects on observable changes
  • 🎨 TypeScript First: Full TypeScript support with type definitions
  • 🚀 Easy to Use: Simple @observer decorator API, similar to mobx-react
  • 💪 Vue 3 Compatible: Built for Vue 3 with composition API support

Installation

npm install mobx mobx-vue-helper vue-facing-decorator

Usage

Class Components

import { Vue, Component, toNative } from 'vue-facing-decorator';
import { observer } from 'mobx-vue-helper';

import counterStore from './models/Counter';

@Component
@observer
class MyMobX extends Vue {
  render() {
    return <button onClick={() => counterStore.increment()}>Count: {counterStore.count}</button>;
  }
}
export default toNative(MyMobX);

Function Components

import { observer } from 'mobx-vue-helper';

import counterStore from './models/Counter';

export const MyMobX = observer(() => (
  <button onClick={() => counterStore.increment()}>Count: {counterStore.count}</button>
));

MobX Store Example

import { observable } from 'mobx';

export class CounterStore {
  @observable
  accessor count = 0;

  increment() {
    this.count++;
  }

  decrement() {
    this.count--;
  }
}

export default new CounterStore();

Using @reaction() Decorator

The @reaction() decorator allows you to define side effects that run when specific observable values change. It's based on MobX's reaction().

import { Vue, Component, toNative } from 'vue-facing-decorator';
import { observer, reaction } from 'mobx-vue-helper';

import counterStore from './models/Counter';

@Component
@observer
class MyComponent extends Vue {
  // This method will be called whenever count changes
  @reaction(() => counterStore.count)
  handleCountChange(newValue: number, oldValue: number) {
    console.log(`Count changed from ${oldValue} to ${newValue}`);
  }

  render() {
    return <button onClick={() => counterStore.increment()}>Count: {counterStore.count}</button>;
  }
}
export default toNative(MyComponent);

Note: The @reaction() decorator should be used with the @observer decorator on the class. Reactions are automatically disposed when the component is unmounted.

How It Works

The @observer decorator wraps your component's render function with MobX's <Observer /> component from mobx-vue-lite. This enables automatic tracking of observable access during render and triggers re-renders when tracked observables change.

  • For class components: The decorator uses class inheritance to extend your original component, wrapping the render() method and managing MobX reactions lifecycle
  • For function components: The wrapper creates a Vue component with a setup function that wraps your functional component

The @reaction() decorator allows you to define MobX reactions directly on class methods. These reactions are automatically initialized when the component mounts and disposed when it unmounts.

Limits

As the implementation of Vue 3 & Vue-facing-decorator are dependent on Proxy API, and MobX 6+ & ES Decorator stage-3 are dependent on accessor properties (which is used the Private Field inside), it'll throw errors when they are working together, so we can't put @observable on fields of class components directly as React & WebCell do.

There're 2 alternatives to work around this:

  1. create a separate store class with @observable properties and use it inside your Vue class component.

    import { Vue, Component, toNative } from 'vue-facing-decorator';
    import { observable } from 'mobx';
    import { observer } from 'mobx-vue-helper';
    
    class State {
      @observable
      accessor count = 0;
    
      increment() {
        this.count++;
      }
    
      decrement() {
        this.count--;
      }
    }
    
    @Component
    @observer
    class MyMobX extends Vue {
      state = new State();
    
      render() {
        const { state } = this;
    
        return <button onClick={() => state.increment()}>Count: {state.count}</button>;
      }
    }
    export default toNative(MyMobX);
  2. use makeAutoObservable(this) in the constructor of your Vue class component to make all properties observable.

    import { Vue, Component, toNative } from 'vue-facing-decorator';
    import { observer } from 'mobx-vue-helper';
    import { makeAutoObservable } from 'mobx';
    
    @Component
    @observer
    class MyMobX extends Vue {
      count = 0;
    
      constructor() {
        super();
        makeAutoObservable(this);
      }
    
      increment() {
        this.count++;
      }
    
      decrement() {
        this.count--;
      }
    
      render() {
        return <button onClick={() => this.increment()}>Count: {this.count}</button>;
      }
    }
    export default toNative(MyMobX);

Requirements

  • TypeScript 5.x
  • Vue 3.x
  • MobX 6.x
  • Vue-facing-decorator 4.x

Credits

This package is part of the idea2app ecosystem and is inspired by the observer pattern from mobx-react.

Related projects

  1. https://github.com/idea2app/MobX-React-helper
  2. https://github.com/idea2app/Vue-MobX-Prime-ts