
mvvm-development
by bretuobay
Web Loom is a lightweight, framework-agnostic toolkit offering MVVM architecture, state stores, event bus utilities, and headless UI behaviors for modern web apps.
SKILL.md
name: mvvm-development
description: Explain how to implement and evolve MVVM features using the repo’s @web-loom/mvvm-core, the shared models/view-models packages, and the reference MVVM apps (React/Angular/Vue). Use when Codex is asked about MVVM wiring, state management, or integrating the core packages with framework-specific UIs.
MVVM development guidance
Use this skill whenever MVVM is the primary pattern in play—new view models, model validation, or wiring UI components to observable commands.
Core packages
packages/mvvm-coreimplements the foundational concepts (BaseModel, RestfulApiModel, BaseViewModel, commands, observable collections, QueryStateModel, DI container). Refer to references/mvvm-core-overview.md for the current shape of each export and the RxJS/Zod patterns the library enforces.packages/modelsandpackages/view-modelsbuild onmvvm-coreand publish workspace-friendly entry points (@repo/models,@repo/view-models). Whenever you create new data shapes or view logic, keep them under these packages so multiple apps can import from the same build outputs.
Model helpers (packages/mvvm-core/src/models)
BaseModelcentralizesdata$,isLoading$, anderror$observables plussetData,setLoading,setError, and avalidatehelper wired to a Zod schema. Every shared model should inherit from it to get consistent state tracking and disposal semantics.RestfulApiModelwrapsFetcher,baseUrl,endpoint,schema, andinitialData. Itsfetch,create,update, anddeletemethods reuse theexecuteApiRequest/optimistic flows fromBaseModel, so you do not re-implement loading/error handling or validation.QueryStateModel,ObservableCollection, and the other helpers inpackages/mvvm-core/src/modelslayer on top when you need caching, pagination, or custom change events for lists of entities.
ViewModel helpers (packages/mvvm-core/src/viewmodels)
BaseViewModelexposes the underlying model’s observables and mapserror$into avalidationErrors$stream. UseaddSubscription+dispose()to keep RxJS subscriptions disciplined.RestfulApiViewModelwires aRestfulApiModelinto consumabledata$,isLoading$,error$,selectedItem$, and CRUDCommands (fetch,create,update,delete). Each command already exposesexecute(),isExecuting$, andcanExecute$, so hook those observables to buttons/spinners.- The factory
createReactiveViewModel(andViewModelFactoryConfig) keeps view model setup consistent—feed it the same config object you use for theRestfulApiModel, and it instantiates the pair for you.
Concrete CRUD example
Every new feature should follow the pattern captured in references/mvvm-crud-flow.md: export a shared model config, pass it to createReactiveViewModel, and let each app subscribe to data$/isLoading$ while triggering fetchCommand.execute() inside lifecycle hooks (see apps/mvvm-react/src/components/Dashboard.tsx). This keeps shared packages reusable and apps focused on rendering observable updates.
Application integration
- The React, Angular, Vue, and vanilla MVVM starter apps under
apps/mvvm-*all subscribe to observables exposed by view models.apps/mvvm-react/README.mdcontains a concrete Dashboard example: use the provideduseObservablehook, callfetchCommand.execute()on mount, and dispose of the view model when the component unmounts. See references/mvvm-react-example.md for the distilled workflow. - Match the React example for other frameworks: the View should only subscribe to ViewModel streams (
data$,isLoading$,error$, computed observables) and trigger commands (fetchCommand,createCommand, etc.). Keep models/test suites decoupled from view-layer hooks so you can reuse them across apps.
Practices & verification
- Always call
dispose()on view models when a component, page, or route is torn down to clean up subscriptions and commands. - Favor Zod schemas defined next to the model for compile-time and runtime validation; pass them into BaseModel/RestfulApiModel constructors to get automatic error handling.
- Commands (
Command,fetchCommand,createCommand, etc.) exposecanExecute$andisExecuting$. Wire UI states (disabled buttons, loading spinners) directly to those observables for consistent UX. - For tests, rely on the workspace Vitest setup (
apps/mvvm-react/vitest.config.ts) so the same alias map (React component → shared view models) is used invitest run. Mock fetchers or provide stubbed RxJS subjects when exercising models/view models.
When extending the pattern
- Add new model/view model packages under
packages/*; export them via the existingexportsfields and keeppackage.jsonscripts consistent (build,test,check-types,lint). - Update any consuming app’s Vite/Vitest alias map so
@repo/modelsand@repo/view-modelsresolve to../../packages/.../srcduring development and testing. - Keep the MVVM core README (and this skill) in sync when you change base behaviors (new observables, command features, etc.).
Leverage the reference files for concrete snippets, and re-run npm run test/turbo run dev after wiring a new view model to ensure observables and commands behave as expected.
Score
Total Score
Based on repository quality metrics
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
1ヶ月以内に更新
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
Reviews
Reviews coming soon
