EZ
Calculator
Calculator is based on the following primary technologies:
- react
- mobx
- webpack
- postcss
- eslint
- typescript
- webassembly
- rust
Application structured in a way that allows us to write js code for frontend and rust code for webassembly at the same time and demonstrates some techniques how to write client-side code. In particular we use commands, events and appropriate handlers to achieve our goals.
Demo
https://ezhivitsa.github.io/calculator/
How to start development
Type the following command to install dependencies:
$ make depsTo run webpack build of the rust and js files type the following command:
$ make devAnd open in the browser http://localhost:8080
How to make a build
To make a final build type the following command:
$ make buildHow to start tests
To start tests type the following command:
$ make testExplanations of the files structure.
- src/wasm - this folder contains
Rustcodebase. We compilewasmfile using this code. - src/client/adapters - this folder contains code with interface which is based on another interface (adapter or wrapper pattern). Particularly we create
calculator-adapterto organize communication betweenjsandwasm. - src/client/components/global - global
Reactcomponents which can be used everywhere in the application. For example,Button,Toggle. - src/client/components/pages -
Reactcomponents for particular page. Here we have only one page with calculator itself. - src/client/lib - folder with common functions where we can do some common actions, for example transformations or validations. This functions help us to avoid copy-paste of functionality.
- src/client/providers - contains
Reactcontext providers - src/client/services - folder with business logic
- src/client/services/app - services where we can place some logic and send command which we will handle in another layer
- src/client/services/command-handlers - this folder contains command handlers and state logic. Using state we can determine what event should we trigger. The main purpose of this handlers is to make validations and trigger or not trigger appropriate events.
- src/client/services/event-handlers - folder with event handlers where we change current data. Here we call methods of adapter to update data structure in Rust code.
- src/client/stores -
MobXstores. Here we use stores and add logic to handle application events and change store data in an appropriate way. - src/client/styles - global styles and css variables
- src/client/texts - static texts
Important things to keep in mind
- Logical components should be tightly coupled. Keep all component related files, such as images, styles, sub components as close as possible to the component. Do not put component into the
globalsfolder for the future use. - Two separate page components should be loosely coupled. If there is two page components which use same image - keep two copies of every image within every page. Do not create generic images folder, as all images belong to some ui components.
Conventions
- Name of all files for components should start from lowercase letter and words should be separated by a dash (
date-range,multi-action-button). - Code style (eslint, typescript).
License
Calculator is released under the MIT License.
On this page
Languages
TypeScript68.2%Rust18.7%CSS6.6%JavaScript5.4%Makefile0.9%HTML0.3%Shell0.0%
Contributors
MIT License
Created May 18, 2020
Updated October 26, 2025