Comparisons
At it’s core Bunshi is a dependency injection framework, not a state management framework. It was designed to be complimentary to the ecosystem of state management tools and frontend frameworks.
Bunshi vs Jotai
Jotai takes an atomic approach to state management.
Molecules are similar to and inspired by Jotai atoms, but with a few important differences:
- Molecules can’t be async, but atoms can be.
- Molecules are read-only, but atoms can be writable.
- Molecules aren’t reactive, but you can subscribe to and listen to an atom.
Jotai and Bunshi both share the concept of “scope”, but they are very different.
- Molecule scopes can be interconnected, but atom scopes are “separate universes”.
- Molecules can depend on molecules AND scope, but atoms only depend on other atoms.
- You are unlikely to ever use Jotai scope, but you should definitely use Bunshi scope as much as possible.
Bunshi vs TSyringe
TSyringe is a lightweight dependency injection container for TypeScript/JavaScript.
Molecules in Bunshi are similar to Providers in TSyringe and accomplish a similar goal to dependency injection.
Pros for Bunshi:
- Bunshi has scoping
- Bunshi has React and Vue support
- Bunshi doesn’t rely on decorators. It is hard to use
reflect-metadata
with starters like CRA, Next.js etc. You need to eject or hack starters and it is far from ideal. - Bunshi doesn’t automatically handle classes
Pros for TSyringe:
- Support constructor injection on classes with decorators
- Disposable instances
- Circular dependencies
- Interception