# `beat.editor` Developer Guide

## Additional System Requirements
#### Testing
- Up-to-date Chrome browser for Chrome headless testing support (doesn't work on Chromium yet)
- Up-to-date Firefox browser for Firefox headless testing support

#### Editor Support
- Make sure to pick up JS & JSX syntax highlighting for your editor!
- The provided `.tern-project` file is configuration for Tern.js, a JS code analysis tool (autocompletion, etc.).
- Linting via ESLint should be configured to use the local installation (from `node_modules/`) - *not* a global installation. This lets ESLint properly find all the plugins on a per-project basis.
- Linting CSS via Stylelint should be configured similarly to ESLint. Since this linter is relatively new, your linting engine/editor probably won't pick it up automatically.

#### Development
- You'll probably want the [React devtools](https://github.com/facebook/react-devtools) and [Redux devtools](https://github.com/zalmoxisus/redux-devtools-extension) browser plugins to sanely debug and inspect React/Redux code.
- You might need to enable/configure sourcemaps in your browser manually.
- The server file is `server.py`. To start it, you need the proper dependendencies in the python environment you use to run the server (see the `server.py` header for more info).
- You'll probably want Webpack's dev server (`npm start`) running in a separate terminal window/tab, as Webpack will automatically rebuild/update your project when files change (served at `localhost:9101`. However, changes to the webpack config or other configuration files may not be watched. In general, anything under `src/` should be hot-reloaded, while anything else may not be. If there's issues with the app when running the dev server that you don't expect or don't make sense (especially if the issue came up after a hot reload), try refreshing the page (`ctrl-r`) - sometimes the hot reloader doesn't properly handle complex changes (such as state management or async functionality).
- When changing/updating dependencies, you'll want to install/update flow types for them. You'll need a globally-installed `flow-typed` (`npm install -g flow-typed`) to run `flow-typed install` in the root of the project.
- If you're quickly iterating test code, you can run the testing daemon in a tmux/byobu pane with the `test-start` npm script. This lets you quickly trigger tests again with `karma run` (via a global `karma-cli` installation through npm) since it won't have to start up the daemon each time you want to run the tests. It will also rerun tests when the files change (this is configurable). The daemon is a bit buggy, so if you are getting unexpected errors, try to restart it.

## NPM Scripts Explanations
| Script | Target | Purpose |
| :----: | :----: | :------ |
| `start` | `src/main.jsx` | Your actual project |
| `prebuild` | `dist/` | Clears `dist/` of old files |
| `build` | `src/main.js` | Builds the whole app for production into `dist/` |
| `test` | `karma.conf.js` | Runs tests in `test/` via Karma |
| `test-start` | `karma.conf.js` | Runs tests in `test/` via Karma and keeps the test daemon running in the foreground.  |
| `lint` | | Checks your JS, JSX, and CSS files for any errors |
| `lint:fix` | | Fixes any easier linting issues in your JS & JSX files |
| `flow` | `.flowconfig` | Checks your project's flow type annotations (static analysis) |
| `prepush` | `karma.conf.js` | Automatically runs before pushing (Git hook integration provided by `husky`) |

## Technology Breakdown

### Python dependencies

| Package | Purpose | Simple Explanation |
| :------ | :------ | :---------- |
| simplejson | JSON handling | |
| flask | web server | |
| flask_restful | REST utilities for flask | |
| flask_cors | CORS support for flask | |

### Runtime Dependencies

| Package | Purpose | Simple Explanation |
| :------ | :------ | :---------- |
| ajv | JSON schema validator | Uses [JSON schemas](http://json-schema.org/) to validate JSON objects |
| bootstrap | CSS source for `reactstrap` | Provides Bootstrap's styling to the `reactstrap` dependency |
| classnames | Manages complex class name logic for HTML elements | |
| d3 | Data viz library | Gives us already-prepared logic for handling user interactions with SVG elements for the graphical toolchain editor |
| fuse.js | Fuzzy-search library | |
| fast-levenshtein | Fast implementation of the levenshtein string distance algorithm | Compares and scores the similarity of two strings |
| prop-types | Runtimes React prop type checking | |
| react | UI library | JS framework for defining the user interface & overall UX |
| react-contextmenu | React wrapper for context menus | Lets us provide custom right-click menus in a "React" way |
| react-dom | DOM compat for React | Lets React run in the browser |
| react-popper | React adaptor for `popper.js` | Dependency of `reactstrap` |
| react-redux | React integration for Redux | |
| react-router-dom | Routing for React | Gives us React-like APIs for managing navigation in Single Page Apps (SPAs) |
| react-transition-group | Helpers for writing transitions across React lifecycles | Dependency of `reactstrap` |
| reactstrap | Native React implementation of Bootstrap 4 | |
| redux | State Management library | Gives us a clear way to manage state across the entire app |
| redux-thunk | Redux action support for async operations | Lets Redux use async code (e.g. fetching from our server) |
| reselect | Memoized Redux selectors | Lets us calculate intermediate values from the Redux store once, even if the same calculation is used several places |

### Development Dependencies

| Package | Purpose | Simple Explanation |
| :------ | :------ | :----------------- |
| babel-core | Compiler | Core of Babel, an ecosystem for compiling JS code (e.g. transforming new features to older features to support old browsers) |
| babel-eslint | Compiler support for linter | Lets ESLint parse advanced features that aren't built into ESLint's default parser |
| babel-loader | Compiler support for Webpack | Lets Webpack pass JS files through Babel when building |
| babel-plugin-dynamic-import-webpack | Compiler support for dynamic `import`s | Lets Webpack process `import`s called anywhere in code |
| babel-plugin-istanbul | Babel support for Istanbul | Lets Babel track which code is being ran as it's being compiled |
| babel-plugin-syntax-dynamic-import | Babel support for the dynamic import syntax | Lets Babel parse `import` statements in arbitrary places |
| babel-plugin-syntax-object-rest-spread | Babel support for the object spread syntax | Lets Babel parse using spread syntax (`...`) for objects as well as arrays |
| babel-plugin-transform-object-rest-spread | Babel support for transforming object spread | Lets Babel transform the object spread syntax into something compatible with older JS engines |
| babel-preset-env | Babel support for dynamic targeting via browserslist syntax | Lets Babel dynamically change what code it changes based on your configuration |
| babel-preset-react | Babel support for JSX, Flow types, and other react things | Lets Babel understand & process idiomatic React code |
| chai | Assertion library | Provides tools for `assert`ing things in tests |
| chai-enzyme | Enzyme integration into chai | Lets you use enzyme assertion/testing functionality in chai statements instead of complex enzyme queries |
| cross-env | Cross-environment variable support | Transforms environment variable definitions written in Linux format to the current platform |
| css-loader | Webpack CSS loader | Lets Webpack parse references to CSS files |
| enzyme-adapter-react-16 | Enzyme support for React 16 | |
| enzyme | React test utilities | Adds helpers for testing React code, especially Components |
| eslint | JS Linter | Statically analyzes JS code according to your configuration |
| eslint-plugin-compat | ESLint support for browserslist | Lets ESLint check if the JS APIs you use are supported by the browsers set in your configuration |
| eslint-plugin-flowtype | ESLint support for flow | Lets ESLint check flow type annotations (across files too!) |
| eslint-plugin-import | ESLint support for dynamic `import`s | Lets ESLint parse `import`s anywhere in JS code |
| eslint-plugin-react | ESLint support for React | Lets ESLint parse & lint React code & JSX |
| flow-bin | Flow type annotation linting/checking support | Adds support for Flow type annotations in your code (opt-in static typing for JS!) |
| flow-typed | Tool to use type defs from `flow-typed` | Lets you download & use high-quality community-written flow type definitions for libraries |
| html-webpack-harddisk-plugin | Lets HtmlWebpackPlugin always write to disk | |
| html-webpack-plugin | Generates `index.html` files with all chunks included | |
| husky | Calls npm scripts on git hooks | |
| karma | Test runner | Runs tests on a certain environment according to configuration and reports on results |
| karma-chrome-launcher | Karma support for Chrome browser | Lets Karma run tests in the Chrome browser, if installed |
| karma-coverage | Karma support for coverage instrumentation | Lets karma read output from Istanbul |
| karma-firefox-launcher | Karma support for Firefox browser | Lets Karma run tests in the Firefox browser, if installed |
| karma-mocha | Karma support for mocha | Lets Karma understand tests written in the Mocha testing framework |
| karma-mocha-reporter | Karma support for mocha reporters | Lets Karma use mocha reporters |
| karma-sourcemap-loader | Karma support for sourcemaps | Errors during testing are shown on the actual line they came from, not the line in the compiled files |
| karma-webpack | Karma support for webpack | Lets Karma run test files through webpack before running tests |
| mocha | Unit Test Framework | Lets us run unit tests |
| postcss | CSS compiler | Like Babel, but for CSS |
| postcss-cli | CLI for PostCSS | Lets us run PostCSS in the commandline not just in JS |
| postcss-cssnext | PostCSS support for latest CSS features | Lets us use new CSS features that may not be available in all browsers |
| postcss-loader | Webpack support for PostCSS | Lets Webpack run CSS through PostCSS |
| postcss-smart-import | Smarter importing logic for CSS | |
| rimraf | Small helper for emptying a directory | |
| sinon | Spies, stubs, mocks for JS testing | Lets you test callbacks, stub libraries with "fake" functions, mock server data |
| style-loader | Supports embedding styles in JS code |  |
| stylelint | CSS Linter | Like ESLint, but checks our CSS code instead of JS |
| stylelint-config-standard | Stylelint standard config | Gives sane default for Stylelint |
| svg-inline-loader | Webpack support for SVG files | Makes Webpack resolve `import <file>.svg` statements with the actually string from the SVG file |
| uglifyjs-webpack-plugin | Webpack plugin for minification | Makes webpack remove unused code and shrink it |
| webpack | Build system | Processes & bundles your source files and dependencies together |
| webpack-dev-server | Serves a webpack project on a port & rebuilds when necessary | |
| webpack-visualizer-plugin | Visualizer for webpack chunks | Provides a webpage for inspecting the contents of the generated webpack chunks |
| worker-loader | Webpack support for shared/service workers | Lets you use JS files that will be executed in a worker |
