Skip to content

Commit

Permalink
Merge pull request #219 from tidepool-org/jebeck/redux
Browse files Browse the repository at this point in the history
migrate state management to redux
  • Loading branch information
jebeck committed Feb 11, 2016
2 parents 99bf9d2 + b61cc6e commit eaf12e9
Show file tree
Hide file tree
Showing 206 changed files with 9,833 additions and 3,775 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
stage: 0
}
26 changes: 26 additions & 0 deletions .bookignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
build/
config/
dist/
fonts/
images/
lib/**/*.js
lib/**/*.jsx
lib/carelink/
lib/components/
lib/core/
lib/dexcom/
lib/insulet/
lib/redux/
lib/state/
lib/tandem/
node_modules/
scripts/
styles/
test/
**/*.js
.eslintrc
.travis.yml
description.txt
LICENSE
manifest.json
package.json
3 changes: 2 additions & 1 deletion .config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ function stringToArray(str, defaultValue) {
}

module.exports = {
// this is to always have the Bows logger turned on!
// NB: it is distinct from our own "debug mode"
DEBUG: stringToBoolean(process.env.DEBUG, true),
// the defaults for these need to be pointing to prod
API_URL: process.env.API_URL || 'https://api.tidepool.org',
UPLOAD_URL: process.env.UPLOAD_URL || 'https://uploads.tidepool.org',
BLIP_URL: process.env.BLIP_URL || 'https://blip.tidepool.org',
CARELINK: stringToBoolean(process.env.CARELINK, true),
DEFAULT_TIMEZONE: process.env.DEFAULT_TIMEZONE || 'America/Los_Angeles',
DEFAULT_CARELINK_DAYS: process.env.DEFAULT_CARELINK_DAYS || '180'
};
54 changes: 54 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
// I want to use babel-eslint for parsing!
"parser": "babel-eslint",
"ecmaFeatures": {
"jsx": true,
"classes": true,
"modules": true,
},
"env": {
// I write for browser
"browser": true,
// in CommonJS
"node": true
},
"globals": {
"expect": false,
"process": false,
"require": false,
"define": false,
"console": false,
"__MOCK__": false,
"__MOCK_PARAMS__": false,
"__UPLOAD_API__": false,
"__API_HOST__": false,
"__SHOW_ACCEPT_TERMS__": false,
"__PASSWORD_MIN_LENGTH__": false,
"__INVITE_KEY__": false
},
// To give you an idea how to override rule options:
"rules": {
"quotes": [2, "single"],
"strict": [2, "never"],
"eol-last": 0,
"no-mixed-requires": 0,
"no-underscore-dangle": 0,
"wrap-iife": [2, "inside"],
"no-caller": 2,
"no-undef": 2,
"new-cap": 2,
"semi": 2,
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2,
// uploader specific
"camelcase": 0,
"eqeqeq": 0,
"no-bitwise": 0,
// TODO: either try to fix this globally or use an embedded .eslintrc for drivers
"no-use-before-define": 0
},
"plugins": [
"react"
]
}
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ pids
logs
results
config/*
!config/mock.sh
!config/device-debug.sh
!config/local.sh
!config/ui-debug.sh
build
dist
dist.zip

test/carelink/overlaps/test-account.csv
test/node/carelink/overlaps/test-account.csv
test/carelink/testRemoveOverlapsFullTestFile.js
test/node/carelink/testRemoveOverlapsFullTestFile.js

tmp
npm-debug.log
Expand All @@ -28,4 +31,7 @@ bower_components
.DS_Store
.idea
*.iml
.com.apple.timemachine.*
.com.apple.timemachine.*

_book/
web/
20 changes: 0 additions & 20 deletions .jshintrc

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ node_js:
- "0.12"
- "stable"
script:
- npm run jshint
- npm run lint
- npm test

matrix:
Expand Down
75 changes: 69 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://travis-ci.org/tidepool-org/chrome-uploader.png)](https://travis-ci.org/tidepool-org/chrome-uploader)

This is a Chrome App that acts as an uploader client for Tidepool. It is intended to allow you to plug devices into the USB port and automatically load the data stored on them up to the Tidepool cloud.
This is a [Chrome App](https://developer.chrome.com/apps/about_apps) that acts as an uploader client for Tidepool. It is intended to allow you to plug diabetes devices into the USB port and automatically load the data stored on them up to the Tidepool cloud.


## How to set it up
Expand All @@ -15,6 +15,7 @@ This is a Chrome App that acts as an uploader client for Tidepool. It is intende
1. Click "Load Unpacked Extension".
1. Choose the directory where you cloned the repository and click OK.
1. To run it, you can choose "Launch" from the chrome://extensions page. You can also run it from the Chrome App Launcher, which Chrome may install for you whether you want it or not.
1. To open the JavaScript console/Chrome Dev Tools, click on the `index.html` link in the section of chrome://extensions devoted to the uploader. (Note: this link will only appear after you've launched the uploader.)
1. If you're developing, you may find that the only way it runs properly is to hit the "Reload" link in chrome://extensions after each change to the source. You will definitely need to reload any time you change the manifest.


Expand All @@ -27,13 +28,75 @@ $ source config/local.sh
$ npm start
```

### Debug Mode
### Debug Mode(s)

The environment variable `DEBUG_ERROR` (boolean) controls whether or not errors are caught and an error message displayed in the UI (the production setting) or whether they are thrown in the console (much more useful for local development because then the file name and line number of the error are easily accessible, along with a stack trace). Debug mode is turned on by default in `config/debug.sh`.
For ease of development we have several debug features that developers can turn on and off at will (and to suit various development use cases, such as working on a new device driver versus working on the app's UI). Each of these debug features is set with an environment variable, but rather than being loaded through `.config.js` (as we do for production configuration variables, see above), we load these through the webpack `DefinePlugin` (see [Pete Hunt's webpack-howto](https://github.com/petehunt/webpack-howto#6-feature-flags) for an example, although note Hunt uses the term 'feature flag').

## How to run the tests
#### `DEBUG_ERROR`

```npm test```
The environment variable `DEBUG_ERROR` (boolean) controls whether or not errors sourced in device drivers are caught and an error message displayed in the UI (the production setting) or whether they are thrown in the console (much more useful for local development because then the file name and line number of the error are easily accessible, along with a stack trace). `DEBUG_ERROR` mode is turned on by default in `config/device-debug.sh`.

#### `REDUX_LOG`

The environment variable `REDUX_LOG` (boolean) controls whether or not the [redux logger middleware](https://github.com/fcomb/redux-logger/blob/master/README.md) is included. This middleware logs all redux actions in the Chrome developer console, including the (entire) previous and following app state trees. It is primarily useful when working on the UI of the app, and in fact can be quite performance-expensive (especially when uploading a device, due to the fact that every update to the progress bar constitutes an action), so it is not recommended to turn it on while working on device code.

#### `REDUX_DEV_UI`

The environment variable `REDUX_DEV_UI` (boolean) controls whether or not the [redux dev tools UI](https://github.com/gaearon/redux-devtools/blob/master/README.md) is included. The redux dev tools add a UI interface for exploring - and, to a limited extent, manipulating - app actions and state. Even when `REDUX_DEV_UI` is `true`, we have the dev tools hidden by default: the key combination `ctrl + h` will toggle their visibility. The key combination `ctrl + q` will rotate (clockwise) the location at which the dev tools are anchored; the default is for them to be anchored at the bottom of the app. Similarly to the redux logger middleware, the redux dev tools UI is also quite performance expensive and only recommended for use while working on UI code.

`REDUX_LOG` and `REDUX_DEV_UI` are both turned on by default in `config/ui-debug.sh`.

### Local Development w/o Debug Mode(s)

All debug options are turned *off* by default in `config/local.sh`.


## Tests

There are two sets of (unit) tests for the code in this repository.

The tests for all device and data-processing code currently run in the [nodejs](https://nodejs.org/en/) server-side JavaScript environment. (We plan to eventually migrate these tests to run in-browser since the code itself runs in-browser in the Chrome App.)

The tests for all the UI code run using the [Karma test runner](https://karma-runner.github.io/0.13/index.html) in [the headless WebKit browser PhantomJS](http://phantomjs.org/) or the Chrome browser.

To run the tests in this repository as they are run on Travis CI, use:

```bash
$ npm test
```

To run just the UI tests in both PhantomJS and Chrome *locally*, use:

```bash
$ npm run browser-tests
```

To run just the device and data-processing tests in node, use:

```bash
$ npm run node-tests
```

To run just the UI tests in PhantomJS with webpack & Karma watching all files for changes and both rebundling the app and re-running the tests on every change, use:

```bash
$ npm run karma-watch
```


## Linting & Code Style

We use [ESLint](http://eslint.org/) to lint our JavaScript code. We try to use the same linting options across all our client apps, but there are a few exceptions in this application, noted with comments in the `.eslintrc` configuration file.

To run the linter (which also runs on Travis CI with every push, along with `npm test`), use:

```
$ npm run lint
```

Aside from the (fairly minimal) JavaScript code style options we *enforce* through the linter, we ask that internal developers and external contributors try to match the style of the code in each module being modified. New modules should look to similar modules for style guidance. In React component code, use existing ES6/ES2015 components (not legacy ES5 components) as the style model for new components.

**NB: Please keep ES5 and ES6/ES2015 code distinct. Do *NOT* use ES6/ES2105 features in ES5 modules (most easily recognizable by the use of `require` rather than `import`).**


## Publishing (to the devel/staging testing & development Chrome store account or production)
Expand All @@ -48,4 +111,4 @@ Assuming you've already merged any changes to master and are on master locally..
1. Make sure you are using node v0.12.0 and install fresh dependencies with `npm install`.
1. Build the `dist.zip` file with `npm run build`. Look for the "**Using the default environment, which is now production**" message at the beginning of the build process. (You can check the success of a build (prior to publishing) by pointing 'Load unpacked extension' from chrome://extensions to the `dist/` subdir.)
1. Follow instructions in secrets for actually publishing to the Chrome store.
1. Fill out the release notes for the tag on GitHub. If the tag is known to *not* be a release candidate, mark as a pre-release.
1. Fill out the release notes for the tag on GitHub. If the tag is known to *not* be a release candidate, mark it as a pre-release.
29 changes: 29 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Summary

* [application state](docs/state/README.md)
* [Example state tree](docs/state/ExampleStateTree.md)
* [Glossary of state tree terms](docs/state/StateTreeGlossary.md)
* [Custom middleware](docs/state/CustomMiddleware.md)

* ["bootstrapping" to UTC (BtUTC)](docs/BootstrappingToUTC.md)

* [checklist TEMPLATES](docs/checklisttemplates/README.md)
* [BGM Checklist](docs/checklisttemplates/BGMChecklist.md)
* [CGM Checklist](docs/checklisttemplates/CGMChecklist.md)
* [Insulin Pump Checklist](docs/checklisttemplates/PumpChecklist.md)

* [checklists](lib/drivers/docs/README.md)
* [Abbott FreeStyle](lib/drivers/docs/abbottFreeStyleLite.md)
* [Abbott Precision Xtra](lib/drivers/docs/abbottPrecisionXtra.md)
* [Animas Ping and Vibe Insulin Pumps](lib/drivers/docs/animasPingAndVibe.md)
* [Bayer Contour Next](lib/drivers/docs/bayerContourNext.md)
* [Dexcom CGM](lib/drivers/docs/dexcom.md)
* [CareLink (CGM data)](lib/drivers/docs/carelinkCGM.md)
* [CareLink (insulin pump data)](lib/drivers/docs/carelinkPumpData.md)
* [Insulet OmniPod](lib/drivers/docs/insuletOmniPod.md)
* [Tandem Insulin Pumps](lib/drivers/docs/tandem.md)

* [miscellaneous](docs/misc/README.md)
* [PWD "simulators"](docs/misc/PWDSimulators.md)
* [challenges of flat basal profiles](docs/misc/FlatRateBasals.md)
* [2015.06 CareLink CSV updates](docs/misc/2015.06.29CareLinkCSVChanges.md)
2 changes: 2 additions & 0 deletions browser.tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var context = require.context('./test/browser', true, /\.js$|\.jsx$/); // Load files in /test/browser/ with filename matching * .js
context.keys().forEach(context);
2 changes: 2 additions & 0 deletions config/debug.sh → config/device-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export API_URL='http://localhost:8009'
export UPLOAD_URL='http://localhost:9122'
export BLIP_URL='http://localhost:3000'
export DEBUG_ERROR=true
export REDUX_LOG=false
export REDUX_DEV_UI=false
2 changes: 2 additions & 0 deletions config/local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export API_URL='http://localhost:8009'
export UPLOAD_URL='http://localhost:9122'
export BLIP_URL='http://localhost:3000'
export DEBUG_ERROR=false
export REDUX_LOG=false
export REDUX_DEV_UI=false
6 changes: 6 additions & 0 deletions config/ui-debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export API_URL='http://localhost:8009'
export UPLOAD_URL='http://localhost:9122'
export BLIP_URL='http://localhost:3000'
export DEBUG_ERROR=false
export REDUX_LOG=true
export REDUX_DEV_UI=true
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions docs/checklisttemplates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Templates of checklists for implementations of drivers to read data from diabetes devices.

- [blood glucose meters (BGMs)](BGMChecklist.md)
- [continuous glucose monitors (CGMs)](CGMChecklist.md)
- [insulin pumps](PumpChecklist.md)
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions docs/misc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Miscellaneous technical documents.

- guidance documentation for ["simulator" modules](PWDSimulators.md) accompanying our insulin pump drivers
- technical explanation of the challenges of ["flat" basal profiles (on insulin pumps)](FlatRateBasals.md)
- documentation of [updates to the CareLink CSV export format made late June 2015](2015.06.29CareLinkCSVChanges.md)
11 changes: 11 additions & 0 deletions docs/state/CustomMiddleware.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Custom Middleware

One of the great benefits of [redux](http://redux.js.org/) is the easy path it provides for writing middleware to perform various actions in response to some or all of the redux actions that are the source of all changes to the application's state tree. The open-source community provides some great middleware options like the [redux logger](https://github.com/fcomb/redux-logger) that we include behind an environment variable to assist in development.

In the Tidepool Uploader, we also include two custom middlewares: one for making calls to our metrics API and one for logging application errors.

The source for the metrics middleware is found in `lib/redux/utils/metrics.js`. It performs a call to the Tidepool metrics API for any redux action that includes a `metric` property inside its `meta` property.

The source of the error-logging middleware is found in `lib/redux/utils/errors.js`. It performs a call to the Tidepool server-side error logging for any redux action that has the boolean flag `error` as true and a JavaScript `Error` object as its `payload`.

If the source code of our custom middlewares confuses more than it answers questions, we recommended reading the excellent [intro to middleware](http://redux.js.org/docs/advanced/Middleware.html) included in the redux documentation.
Loading

0 comments on commit eaf12e9

Please sign in to comment.