npm install web-atoms-generator typescript -g
Sample Todo Application using Web Atoms MVVM contains following features.
- REST Service and Mock
- Small and Minimal Dependency Injection
- View Model and Reusable Components
- Unit Tests
Components are organized in app/views folder. Component generator uses
waconfig.json to convert HTML components into views.js, it also contains
views.js.d.ts so you can statically reference them in your typescript files.
TaskStatusCombodropdown is reusable dropdown that loads values fromConfigServiceTaskListViewis a main view that hosts list of tasks and button to add/remove tasks.NewTaskWindowis window components that will allow you to validate/edit and save task.
REST Services are kept in app/services folder. They are decorated with HTTP methods and
parameter bindings.
TaskServiceprovides CRUD operations on tasks.ConfigSericeprovides configuration lists such as status list etc.
In this folder, Task and ConfigItem models are stored, Task is a class where else ConfigItem is
just a type.
Components have corresponding View Model in app/view-models folder. Not every component needs ViewModel.
TaskListViewModelprovides list of tasks, which are loaded asynchronously fromTaskServiceininitmethod.- It provides
add/removemethod for task. - In
addmethod it opens new task window and awaits for result asynchronously.
NewTaskWindowViewModelprovides task model and validation for the model.- Validations are added as inline lambda expressions. Validation expression is evaluated automatically when any referenced property is modified.
- When you call
this.close(task)method, parametertaskis resolved in promise that was created when the task list opened a window.
We have created two unit tests.
- We will call
expectWindowonMockWindowService.instanceto register what window should open when we call a method. We will also provide result that we will expect to resolve in promise. - We will verify that second task in the list is the new task we were expecting from the window.
- We will call
expectAlertto notify test manager that we will expect an alert when we will try to save empty task. - We will call
expectAlertagain after setting label. - In end of test we will call
MockWindowService.instance.assert(), that will throw an error if any of expected alert/window was never called from the target methods.