Skip to content

mom

MobX micro-stores for React — organized the HMVVM way

Why mom?

Modern React apps mix state, logic, and rendering inside components. As apps grow, this leads to bloated components, tangled prop drilling, and hard-to-test logic buried in hooks and effects.

Mom fixes this by extracting all state and logic into small, observable stores (ViewModels) that are fully decoupled from your React views. Your components become thin mapping layers — easy to read, easy to swap, easy to test.

Full View / Model Decoupling

All state and logic lives in stores. React components only map data to UI — no useState, no useEffect, no business logic in JSX. Views become trivial to read and refactor.

Testability Without the DOM

Since all logic is in plain TypeScript stores, you test with vitest/jest directly — no DOM emulation, no React Testing Library gymnastics. Tests are fast, deterministic, and cover the code that matters.

Readability & Maintainability

Prescriptive conventions (one folder per store, standardized file names) make large codebases navigable. New developers — and AI tools — know exactly where to find things.

Progressive Application Loading

Stores load on demand via the IoC container. Only the code your user needs ships to the browser — the rest loads when first requested.

Composability

Stores compose hierarchically: parent stores mount children, coordinate them, react to their changes. Build complex UIs from small, focused pieces that snap together.

Reusable Models, Swappable Views

The same store can power different React components — a desktop layout and a mobile layout, a full editor and a read-only summary. Change the view without touching the logic.

Type Safety

Full TypeScript inference across stores, params, models, and views. No manual generics — define your types once and they flow everywhere.

Built-in Dependency Inversion

Swap real browser APIs for fakes in tests. Inject different service implementations per context. All powered by asimo’s IoC containers.

What mom adds to MobX

MobX provides the reactive observable engine. Mom adds the structure to organize it at scale:

  • Lifecycle management — stores follow a clear INITIALIZING → READY → DISPOSING → DISPOSED state machine, with onInit and onDispose hooks to create and tear down hierarchies of micro-stores
  • Async initialization and disposal — stores can fetch data or acquire resources asynchronously at init, and clean up gracefully on dispose
  • Async code loading — store implementations can be loaded on demand through the IoC container, enabling code splitting (coming soon)
  • Strong typings — models are exposed as DeepReadOnly outside the store scope, preventing accidental mutations from views or parent stores
  • Simple conventions — standardized file structure and naming patterns (store.ts, store.types.ts, store.view.tsx, XxxDef, XxxStore, XxxIID) make codebases predictable

Quick Install

Terminal window
pnpm add @asimojs/mom mobx mobx-react-lite react

Hello World

Define a store — all state and logic in one place:

counter/store.ts
import { defineStore } from "@asimojs/mom";
export const Counter = defineStore((store) => {
const model = store.initModel({
value: 0,
increment() {
model.value++;
},
});
return model;
});

The view just maps data to UI:

counter/store.view.tsx
import { observer } from "mobx-react-lite";
export const CounterView = observer(({ store }: { store: ReturnType<typeof Counter> }) => (
<div>
<span>{store.value}</span>
<button onClick={() => store.increment()}>+1</button>
</div>
));

Mount it in your app:

import { createStore } from "@asimojs/mom";
import { Counter } from "./counter/store";
import { CounterView } from "./counter/store.view";
import { useState } from "react";
function App() {
const [store] = useState(() => createStore(Counter));
return <CounterView store={store} />;
}

Get started → · Core Concepts →