0.1.1 • Published 6 years ago

multiple-mobx-library v0.1.1

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

multiple-mobx-library

This is an experiment to understand how multiple instances of MobX can be avoided in an application that relies on a library that also needs MobX. See Mobx issue #1082 for details.

This project represents the library that needs MobX. Here I have added MobX and React as devDependencies as well as peerDependencies. Adding as devDependencies ensures that I can build/test the library without any problems. Adding as peerDependencies informs the clients of this library to include MobX and React as real dependencies.

"devDependencies": {
  "mobx": "^3.4.1",
  "mobx-react": "^4.3.5",
  "react": "^16.2.0",
  ...
},
"peerDependencies": {
  "mobx": "^3.x",
  "mobx-react": "^4.x",
  "react": "^16.x"
},

Note that the peer dependencies are intentionally lenient. This is to avoid unnecessary conflicts with the client or other libraries requiring MobX.

The library exposes a React component called Counter as well as a MobX store called CounterStore. The Counter component allows the user to increase or decrease a count. A sample client of this library can be found at multiple-mobx-client. The client not only uses the Counter component, but also creates its own component called NameForm that interacts with the CounterStore. I did this to make sure that both the client and the library are using the same CounterStore. Here's a screen shot of the client app:

Screen Shot

Comments and suggestions welcome!