Skip to content

inoyakaigor/mobx-store-inheritance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mobx store inheritance

What is this?

The makeAutoObservable function does not supporting subclassing. It is described in the Mobx docs.

This package fixes the issue with subclassing.

The code in this package is a slightly modified version from an answer about inheritance in Mobx.

It has been tested in production on a few different projects.

How to use?

It is easy: use makeAutoObservable in constructor of inherited store.

import makeAutoObservable from 'mobx-store-inheritance'

class BaseStore {
  theField = 1

  theMethod() {
    return this.theField
  }
}

class InheritedStore extends BaseStore {
  constructor() {
    makeAutoObservable(this)
  }

  theProperty = 'Ineritance is good'
}

About

Inheritance for Mobx stores

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published