Installation
mobx-sentinel is three packages. Each builds on the one before it, so install only as far as you need.
@mobx-sentinel/core
Section titled “@mobx-sentinel/core”Core functionality like Watcher and Validator. Runs on Node.js and in the browser.
npm i @mobx-sentinel/corepnpm add @mobx-sentinel/coreyarn add @mobx-sentinel/core@nestedannotation for tracking nested models.@nestedannotation supports objects, boxed observables, arrays, sets, and maps.@nested.hoistannotation can be used to hoist sub-fields in a nested model to the parent model.StandardNestedFetcher(low-level API) provides a simple but powerful mechanism for tracking and retrieving nested models. Allowing other modules (even your own code) to integrate nested models into their logic without hassle.
Watcherdetects changes in models automatically.- All
@observableand@computedannotations are automatically watched by default. @watchannotation can be used where@observableis not applicable, e.g., on private fields:@watch #private = observable.box(0)@watch.refannotation can be used to watch values with identity comparison, in contrast to the default behavior which uses shallow comparison.@unwatchannotation andunwatch(() => ...)function disable change detection when you need to modify values silently.
- All
ValidatorandmakeValidatableprovides reactive model validation.- Composable from multiple sources.
- Both sync and async validations are supported.
- Async validations feature smart job scheduling and are cancellable with AbortSignal.
@mobx-sentinel/form
Section titled “@mobx-sentinel/form”Form and bindings. Runs on Node.js and in the browser.
npm i @mobx-sentinel/formpnpm add @mobx-sentinel/formyarn add @mobx-sentinel/form- Asynchronous submission
- Composable from multiple sources.
- Cancellable with AbortSignal.
- Nested and dynamic (array) forms
- Works by mutating models directly.
- Forms are created independently; they don't need to be aware of each other.
- Custom bindings
- Flexible and easy-to-create.
- Most cases can be implemented in less than 50 lines.
- Smart error reporting
- Validation is always up to date; reporting decides when users see the errors.
- Errors wait until the user leaves a field or pauses typing, then follow every fix.
- Fields and sub-forms that appear later start clean, even after the whole form has been reported.
@mobx-sentinel/react
Section titled “@mobx-sentinel/react”Standard bindings and hooks for React. Runs in the browser.
npm i @mobx-sentinel/reactpnpm add @mobx-sentinel/reactyarn add @mobx-sentinel/react- React hooks that automatically handle component lifecycle under the hood.
- Standard bindings for most common form elements.