Skip to content

Commit

Permalink
remove os from the state tree since it never changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jebeck committed Feb 11, 2016
1 parent ac4252e commit 8a0e9fb
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 72 deletions.
2 changes: 0 additions & 2 deletions docs/state/ExampleStateTree.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,13 @@ The JSON that follows on this page represents a snapshot of the Tidepool Uploade
}
},
"dropdown": true,
"os": "mac",
"page": "MAIN",
"unsupported": false,
"blipUrls": {
"forgotPassword": "http://localhost:3000/request-password-from-uploader",
"signUp": "http://localhost:3000/signup",
"viewDataLink": "http://localhost:3000/patients/4a86ec44ff/data"
},
"version": "0.245.0",
"working": {
"checkingVersion": false,
"fetchingUserInfo": false,
Expand Down
4 changes: 0 additions & 4 deletions docs/state/StateTreeGlossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ The properties of each "device" in `devices` should be fairly self-explanatory.

*The Tidepool Uploader inclues a dropdown menu, which is accessible after logging in by clicking on the area where the logged-in user's name is displayed in the upper-right corner. The property `dropdown` in the state tree encodes whether this menu is currently in its open (dropped-down) state (`true`) or closed and hidden (`false`).*

#### `os`

*The property `os` encodes the operating system environment the Tidepool Uploader is running inside. This value is determined at runtime as part of the app initialization step through the `chrome.runtime.getPlatformInfo` function.*

#### `page`

*The property `page` encodes the current "page" of the application that is active. Possible values are, for example, `SETTINGS` for the device selection "page" and `MAIN` for the main upload interface shown in [the app snapshot](./ExampleStateTree.md).*
Expand Down
13 changes: 10 additions & 3 deletions entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
* == BSD2 LICENSE ==
*/

/* global chrome */

require('./styles/main.less');

var _ = require('lodash');
var React = require('react');
var ReactDOM = require('react-dom');
window.React = React;
Expand All @@ -25,6 +28,10 @@ window.DEBUG = config.DEBUG;
// Important: need to require App after setting `window.DEBUG` to enable logging
var Root = require('./lib/containers/root/Root');

window.app = ReactDOM.render(
React.createElement(Root), document.getElementById('app')
);
chrome.runtime.getPlatformInfo(function (platformInfo) {
if (!_.isEmpty(platformInfo.os)) {
ReactDOM.render(
React.createElement(Root, {os: platformInfo.os}), document.getElementById('app')
);
}
});
3 changes: 1 addition & 2 deletions lib/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class App extends Component {
this.log = bows('App');
this.handleClickChooseDevices = this.handleClickChooseDevices.bind(this);
this.handleDismissDropdown = this.handleDismissDropdown.bind(this);
this.props.async.doAppInit(config, {
this.props.async.doAppInit(Object.assign({}, config, {os: props.os}), {
api: props.api,
carelink,
device,
Expand Down Expand Up @@ -313,7 +313,6 @@ export default connect(
dropdown: state.dropdown,
loggedInUser: state.loggedInUser,
loginErrorMessage: state.loginErrorMessage,
os: state.os,
page: state.page,
targetUsersForUpload: state.targetUsersForUpload,
unsupported: state.unsupported,
Expand Down
2 changes: 1 addition & 1 deletion lib/containers/root/Root.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class Root extends Component {
return (
<Provider store={store}>
<div className='DevTools-container'>
<App api={api} version={version} />
<App api={api} os={this.props.os} version={version} />
<div className='DevTools'>
<DevTools store={store} />
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/containers/root/Root.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class Root extends Component {
render() {
return (
<Provider store={store}>
<App api={api} version={version} />
<App api={api} os={this.props.os} version={version} />
</Provider>
);
}
Expand Down
26 changes: 8 additions & 18 deletions lib/redux/actions/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,26 @@ let daysForCareLink = null;
* ASYNCHRONOUS ACTION CREATORS
*/

export function doAppInit(config, servicesToInit) {
export function doAppInit(opts, servicesToInit) {
return (dispatch, getState) => {
services = servicesToInit;
versionInfo.semver = config.version;
versionInfo.name = config.namedVersion;
daysForCareLink = config.DEFAULT_CARELINK_DAYS;
versionInfo.semver = opts.version;
versionInfo.name = opts.namedVersion;
daysForCareLink = opts.DEFAULT_CARELINK_DAYS;
const { api, carelink, device, localStore, log } = services;

dispatch(syncActions.initRequest());
dispatch(syncActions.hideUnavailableDevices(opts.os));

function initializeLocalStore(cb) {
log('Initializing local store.');
localStore.init(localStore.getInitialState(), () => { cb(); });
}
function getOs(cb) {
if (typeof chrome !== 'undefined') {
chrome.runtime.getPlatformInfo((platformInfo) => {
dispatch(syncActions.setOs(platformInfo.os));
log('Retrieved operating system info:', platformInfo.os);
dispatch(syncActions.hideUnavailableDevices(platformInfo.os));
cb();
});
}
}
function initializeDevice(cb) {
log('Initializing device');
device.init({
api,
version: config.namedVersion
version: opts.namedVersion
}, cb);
}
function initializeCareLink(cb) {
Expand All @@ -80,15 +71,14 @@ export function doAppInit(config, servicesToInit) {
}
function setApiHosts(cb) {
log('Setting all api hosts');
api.setHosts(_.pick(config, ['API_URL', 'UPLOAD_URL', 'BLIP_URL']));
api.setHosts(_.pick(opts, ['API_URL', 'UPLOAD_URL', 'BLIP_URL']));
dispatch(syncActions.setForgotPasswordUrl(api.makeBlipUrl(paths.FORGOT_PASSWORD)));
dispatch(syncActions.setSignUpUrl(api.makeBlipUrl(paths.SIGNUP)));
cb();
}

async.series([
initializeLocalStore,
getOs,
initializeDevice,
initializeCareLink,
initializeApi,
Expand All @@ -97,7 +87,7 @@ export function doAppInit(config, servicesToInit) {
if (err) {
return dispatch(syncActions.initFailure(err));
}
let session = results[4];
let session = results[3];
if (session === undefined) {
dispatch(syncActions.setPage(pages.LOGIN));
dispatch(syncActions.initSuccess());
Expand Down
8 changes: 0 additions & 8 deletions lib/redux/actions/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,6 @@ export function setForgotPasswordUrl(url) {
};
}

export function setOs(os) {
return {
type: actionTypes.SET_OS,
payload: { os },
meta: {source: actionSources[actionTypes.SET_OS]}
};
}

export function setPage(page, actionSource = actionSources[actionTypes.SET_PAGE]) {
return {
type: actionTypes.SET_PAGE,
Expand Down
18 changes: 3 additions & 15 deletions test/browser/redux/actions/async.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('Asynchronous Actions', () => {
describe('doAppInit [no session token in local storage]', () => {
it('should dispatch SET_VERSION, INIT_APP_REQUEST, SET_OS, HIDE_UNAVAILABLE_DEVICES, SET_FORGOT_PASSWORD_URL, SET_SIGNUP_URL, SET_PAGE, INIT_APP_SUCCESS, VERSION_CHECK_REQUEST, VERSION_CHECK_SUCCESS actions', (done) => {
const config = {
os: 'test',
version: '0.100.0',
API_URL: 'http://www.acme.com'
};
Expand Down Expand Up @@ -88,11 +89,6 @@ describe('Asynchronous Actions', () => {
type: actionTypes.INIT_APP_REQUEST,
meta: {source: actionSources[actionTypes.INIT_APP_REQUEST]}
},
{
type: actionTypes.SET_OS,
payload: {os: 'test'},
meta: {source: actionSources[actionTypes.SET_OS]}
},
{
type: actionTypes.HIDE_UNAVAILABLE_DEVICES,
payload: {os: 'test'},
Expand Down Expand Up @@ -137,6 +133,7 @@ describe('Asynchronous Actions', () => {
describe('doAppInit [with session token in local storage]', () => {
it('should dispatch SET_VERSION, INIT_APP_REQUEST, SET_OS, HIDE_UNAVAILABLE_DEVICES, SET_FORGOT_PASSWORD_URL, SET_SIGNUP_URL, INIT_APP_SUCCESS, VERSION_CHECK_REQUEST, VERSION_CHECK_SUCCESS, SET_USER_INFO_FROM_TOKEN, SET_BLIP_VIEW_DATA_URL, RETRIEVING_USERS_TARGETS, SET_PAGE actions', (done) => {
const config = {
os: 'test',
version: '0.100.0',
API_URL: 'http://www.acme.com'
};
Expand Down Expand Up @@ -174,11 +171,6 @@ describe('Asynchronous Actions', () => {
type: actionTypes.INIT_APP_REQUEST,
meta: {source: actionSources[actionTypes.INIT_APP_REQUEST]}
},
{
type: actionTypes.SET_OS,
payload: {os: 'test'},
meta: {source: actionSources[actionTypes.SET_OS]}
},
{
type: actionTypes.HIDE_UNAVAILABLE_DEVICES,
payload: {os: 'test'},
Expand Down Expand Up @@ -240,6 +232,7 @@ describe('Asynchronous Actions', () => {
describe('doAppInit [with error in api init]', () => {
it('should dispatch SET_VERSION, INIT_APP_REQUEST, SET_OS, HIDE_UNAVAILABLE_DEVICES, INIT_APP_FAILURE actions', (done) => {
const config = {
os: 'test',
version: '0.100.0',
API_URL: 'http://www.acme.com/'
};
Expand Down Expand Up @@ -268,11 +261,6 @@ describe('Asynchronous Actions', () => {
type: actionTypes.INIT_APP_REQUEST,
meta: {source: actionSources[actionTypes.INIT_APP_REQUEST]}
},
{
type: actionTypes.SET_OS,
payload: {os: 'test'},
meta: {source: actionSources[actionTypes.SET_OS]}
},
{
type: actionTypes.HIDE_UNAVAILABLE_DEVICES,
payload: {os: 'test'},
Expand Down
18 changes: 0 additions & 18 deletions test/browser/redux/actions/sync.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,6 @@ describe('Synchronous Actions', () => {
});
});

describe('setOs', () => {
const OS = 'mac';
it('should be an FSA', () => {
let action = syncActions.setOs(OS);

expect(isFSA(action)).to.be.true;
});

it('should create an action to set the operating system', () => {
const expectedAction = {
type: actionTypes.SET_OS,
payload: {os: OS},
meta: {source: actionSources[actionTypes.SET_OS]}
};
expect(syncActions.setOs(OS)).to.deep.equal(expectedAction);
});
});

describe('setPage', () => {
const PAGE = 'FOO';
it('should be an FSA', () => {
Expand Down

0 comments on commit 8a0e9fb

Please sign in to comment.