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.
https://ezhivitsa.github.io/calculator/
Type the following command to install dependencies:
$ make deps
To run webpack build of the rust and js files type the following command:
$ make dev
And open in the browser https://localhost:8080
To make a final build type the following command:
$ make build
To start tests type the following command:
$ make test
- src/wasm - this folder contains
Rust
codebase. We compilewasm
file 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-adapter
to organize communication betweenjs
andwasm
. - src/client/components/global - global
React
components which can be used everywhere in the application. For example,Button
,Toggle
. - src/client/components/pages -
React
components 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
React
context 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 -
MobX
stores. 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
- 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
globals
folder 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.
- 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).
Calculator is released under the MIT License.