forked from coryhouse/react-slingshot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"stage": 2, | ||
"env": { | ||
"development": { | ||
"plugins": [ | ||
"react-transform" | ||
], | ||
"extra": { | ||
"react-transform": { | ||
"transforms": [{ | ||
"transform": "react-transform-hmr", | ||
"imports": ["react"], | ||
"locals": ["module"] | ||
}] | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": "eslint:recommended", | ||
"plugins": [ | ||
"react" | ||
], | ||
"env": { | ||
"es6": true, | ||
"browser": true, | ||
"node": true, | ||
"jquery": true, | ||
"mocha": true | ||
}, | ||
"ecmaFeatures": { | ||
"jsx": true, | ||
"modules": true | ||
}, | ||
"rules": { | ||
"quotes": 0, | ||
"semi": [1, "always"], | ||
"no-trailing-spaces": 0, | ||
"eol-last": 0, | ||
"no-unused-vars": 0, | ||
"no-underscore-dangle": 0, | ||
"no-alert": 0, | ||
"no-lone-blocks": 0, | ||
"jsx-quotes": 1, | ||
"react/display-name": [ 1, {"acceptTranspilerName": true }], | ||
"react/forbid-prop-types": [1, {"forbid": "any"}], | ||
"react/jsx-boolean-value": 1, | ||
"react/jsx-closing-bracket-location": 0, | ||
"react/jsx-curly-spacing": 1, | ||
"react/jsx-indent-props": [1, "tab"], | ||
"react/jsx-key": 1, | ||
"react/jsx-max-props-per-line": 0, | ||
"react/jsx-no-bind": 1, | ||
"react/jsx-no-duplicate-props": 1, | ||
"react/jsx-no-literals": 0, | ||
"react/jsx-no-undef": 1, | ||
"react/jsx-pascal-case": 1, | ||
"react/jsx-sort-prop-types": 0, | ||
"react/jsx-sort-props": 0, | ||
"react/jsx-uses-react": 1, | ||
"react/jsx-uses-vars": 1, | ||
"react/no-danger": 1, | ||
"react/no-did-mount-set-state": 1, | ||
"react/no-did-update-set-state": 1, | ||
"react/no-direct-mutation-state": 1, | ||
"react/no-multi-comp": 1, | ||
"react/no-set-state": 1, | ||
"react/no-unknown-property": 1, | ||
"react/prefer-es6-class": 1, | ||
"react/prop-types": 1, | ||
"react/react-in-jsx-scope": 1, | ||
"react/require-extension": 1, | ||
"react/self-closing-comp": 1, | ||
"react/sort-comp": 1, | ||
"react/wrap-multilines": 1 | ||
}, | ||
"globals": { | ||
"jQuery": true, | ||
"$": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"name": "react-slingshot", | ||
"version": "1.0.0", | ||
"description": "Starter kit for creating apps with React and Redux", | ||
"scripts": { | ||
"prestart": "npm run remove-dist", | ||
"start": "parallelshell \"npm run test\" \"npm run open\"", | ||
"open": "node tools/server.js", | ||
"lint": "eslint src", | ||
"lint:watch": "watch 'npm run lint' src", | ||
"clean-dist": "npm run remove-dist && npm run create-dist", | ||
"remove-dist": "node_modules/.bin/rimraf ./dist", | ||
"create-dist": "mkdir dist && cd dist && mkdir js && mkdir styles", | ||
"build:html": "node tools/buildHtml.js", | ||
"build:sass": "node-sass --quiet --output dist/styles src/styles/styles.scss --source-map true --output-style compressed", | ||
"prebuild": "npm run clean-dist && npm run build:html && npm run build:sass", | ||
"build": "npm run build:verbose -- -s", | ||
"build:verbose": "node tools/build.js", | ||
"test": "cross-env NODE_ENV=test mocha --watch --reporter progress --compilers js:babel/register --recursive \"./src/**/*.spec.js\"" | ||
}, | ||
"author": "Cory House", | ||
"license": "MIT", | ||
"dependencies": { | ||
"react": "^0.14.0", | ||
"react-dom": "^0.14.0", | ||
"react-redux": "^4.0.0", | ||
"redux": "^3.0.4" | ||
}, | ||
"devDependencies": { | ||
"babel": "^5.8.23", | ||
"babel-eslint": "^4.1.6", | ||
"babel-loader": "^5.1.4", | ||
"babel-plugin-react-display-name": "^2.0.0", | ||
"babel-plugin-react-transform": "^1.1.0", | ||
"browser-sync": "^2.10.0", | ||
"chai": "^3.3.0", | ||
"cheerio": "^0.19.0", | ||
"colors": "^1.1.2", | ||
"cross-env": "^1.0.6", | ||
"css-loader": "^0.23.0", | ||
"eslint": "^1.10.3", | ||
"eslint-loader": "^1.1.1", | ||
"eslint-plugin-react": "^3.10.0", | ||
"file-loader": "^0.8.5", | ||
"mocha": "^2.3.3", | ||
"node-sass": "^3.4.2", | ||
"parallelshell": "^2.0.0", | ||
"react-transform-catch-errors": "^1.0.0", | ||
"react-transform-hmr": "^1.0.1", | ||
"redbox-react": "^1.2.0", | ||
"rimraf": "^2.5.0", | ||
"sass-loader": "^3.1.2", | ||
"style-loader": "^0.12.3", | ||
"watch": "^0.16.0", | ||
"webpack": "^1.12.9", | ||
"webpack-dev-middleware": "^1.4.0", | ||
"webpack-hot-middleware": "^2.6.0", | ||
"yargs": "^3.31.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as types from '../constants/ActionTypes'; | ||
|
||
export function saveFuelSavings(settings) { | ||
return { type: types.SAVE_FUEL_SAVINGS, settings }; | ||
} | ||
|
||
export function calculateFuelSavings(settings, fieldName, value) { | ||
return { type: types.CALCULATE_FUEL_SAVINGS, settings, fieldName, value }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default class DateHelper { | ||
//See tests for desired format. | ||
static getFormattedDateTime(date) { | ||
return `${date.getMonth() + 1}/${date.getDate()} ${date.getHours()}:${this.padLeadingZero(date.getMinutes())}:${this.padLeadingZero(date.getSeconds())}`; | ||
} | ||
|
||
static padLeadingZero(value) { | ||
return value > 9 ? value : '0' + value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import chai from 'chai'; | ||
import DateHelper from './dateHelper'; | ||
|
||
chai.should(); | ||
|
||
describe('Date Helper', () => { | ||
describe('getFormattedDateTime', () => { | ||
it('returns mm/dd hh:mm:ss formatted time when passed a date', () => { | ||
//arrange | ||
//The 7 numbers specify the year, month, day, hour, minute, second, and millisecond, in that order | ||
let date = new Date(99,0,24,11,33,30,0); | ||
|
||
//assert | ||
DateHelper.getFormattedDateTime(date).should.equal('1/24 11:33:30'); | ||
}); | ||
|
||
it('pads single digit minute and second values with leading zeros', () => { | ||
//arrange | ||
//The 7 numbers specify the year, month, day, hour, minute, second, and millisecond, in that order | ||
let date = new Date(99,0,4,11,3,2,0); | ||
|
||
//assert | ||
DateHelper.getFormattedDateTime(date).should.equal('1/4 11:03:02'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import mathHelper from './mathHelper'; | ||
import NumberFormatter from './numberFormatter'; | ||
|
||
//This file uses the factory function pattern instead of a class. | ||
//Just showing an alternative to using a class. | ||
//This declares a function with a private method. | ||
//The public function returns an object literal. | ||
//Could arguably be called FuelSavingCalculatorFactory. | ||
let fuelSavingsCalculator = function() { | ||
//private | ||
let calculateMonthlyCost = function(milesDrivenPerMonth, ppg, mpg) { | ||
let gallonsUsedPerMonth = milesDrivenPerMonth / mpg; | ||
return gallonsUsedPerMonth * ppg; | ||
}; | ||
|
||
//public | ||
return { | ||
calculateMilesDrivenPerMonth: function(milesDriven, milesDrivenTimeframe) { | ||
const monthsPerYear = 12; | ||
const weeksPerYear = 52; | ||
|
||
switch (milesDrivenTimeframe) { | ||
case 'week': | ||
return (milesDriven * weeksPerYear) / monthsPerYear; | ||
case 'month': | ||
return milesDriven; | ||
case 'year': | ||
return milesDriven / monthsPerYear; | ||
default: | ||
throw 'Unknown milesDrivenTimeframe passed: ' + milesDrivenTimeframe; | ||
} | ||
}, | ||
|
||
calculateSavingsPerMonth: function(settings) { | ||
if (!settings.milesDriven) { | ||
return 0; | ||
} | ||
|
||
let milesDrivenPerMonth = this.calculateMilesDrivenPerMonth(settings.milesDriven, settings.milesDrivenTimeframe); | ||
let tradeFuelCostPerMonth = calculateMonthlyCost(milesDrivenPerMonth, settings.tradePpg, settings.tradeMpg); | ||
let newFuelCostPerMonth = calculateMonthlyCost(milesDrivenPerMonth, settings.newPpg, settings.newMpg); | ||
let savingsPerMonth = tradeFuelCostPerMonth - newFuelCostPerMonth; | ||
|
||
return mathHelper.roundNumber(savingsPerMonth, 2); | ||
}, | ||
|
||
|
||
necessaryDataIsProvidedToCalculateSavings: function(settings) { | ||
return settings.newMpg > 0 | ||
&& settings.tradeMpg > 0 | ||
&& settings.newPpg > 0 | ||
&& settings.tradePpg > 0 | ||
&& settings.milesDriven > 0; | ||
}, | ||
|
||
calculateSavings: function(settings) { | ||
let monthlySavings = this.calculateSavingsPerMonth(settings); | ||
return { | ||
monthly: NumberFormatter.getCurrencyFormattedNumber(monthlySavings), | ||
annual: NumberFormatter.getCurrencyFormattedNumber(monthlySavings * 12), | ||
threeYear: NumberFormatter.getCurrencyFormattedNumber(monthlySavings * 12 * 3) | ||
}; | ||
} | ||
}; | ||
}; | ||
|
||
export default fuelSavingsCalculator; |
Oops, something went wrong.