Skip to content

Commit 4302524

Browse files
committed
INF is here
0 parents  commit 4302524

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1758
-0
lines changed

.babelrc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"stage": 0,
3+
"env": {
4+
"development": {
5+
"plugins": [
6+
"react-transform"
7+
],
8+
"extra": {
9+
"react-transform": {
10+
"transforms": [{
11+
"transform": "react-transform-hmr",
12+
"imports": ["react"],
13+
"locals": ["module"]
14+
}]
15+
}
16+
}
17+
}
18+
}
19+
}

.editorconfig

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.eslintrc

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": "eslint:recommended",
4+
"plugins": [
5+
"react"
6+
],
7+
"env": {
8+
"es6": true,
9+
"browser": true,
10+
"node": true,
11+
"jquery": true,
12+
"mocha": true
13+
},
14+
"ecmaFeatures": {
15+
"jsx": true,
16+
"modules": true
17+
},
18+
"rules": {
19+
"quotes": 0,
20+
"no-debugger": 1,
21+
"semi": [1, "always"],
22+
"no-trailing-spaces": 0,
23+
"eol-last": 0,
24+
"no-unused-vars": 0,
25+
"no-underscore-dangle": 0,
26+
"no-alert": 0,
27+
"no-lone-blocks": 0,
28+
"jsx-quotes": 1,
29+
"react/display-name": [ 1, {"acceptTranspilerName": true }],
30+
"react/forbid-prop-types": [1, {"forbid": "any"}],
31+
"react/jsx-boolean-value": 1,
32+
"react/jsx-closing-bracket-location": 0,
33+
"react/jsx-curly-spacing": 1,
34+
"react/jsx-indent-props": 0,
35+
"react/jsx-key": 1,
36+
"react/jsx-max-props-per-line": 0,
37+
"react/jsx-no-bind": 0,
38+
"react/jsx-no-duplicate-props": 1,
39+
"react/jsx-no-literals": 0,
40+
"react/jsx-no-undef": 1,
41+
"react/jsx-pascal-case": 1,
42+
"react/jsx-sort-prop-types": 0,
43+
"react/jsx-sort-props": 0,
44+
"react/jsx-uses-react": 1,
45+
"react/jsx-uses-vars": 1,
46+
"react/no-danger": 1,
47+
"react/no-did-mount-set-state": 1,
48+
"react/no-did-update-set-state": 1,
49+
"react/no-direct-mutation-state": 1,
50+
"react/no-multi-comp": 1,
51+
"react/no-set-state": 1,
52+
"react/no-unknown-property": 1,
53+
"react/prefer-es6-class": 1,
54+
"react/prop-types": 1,
55+
"react/react-in-jsx-scope": 1,
56+
"react/require-extension": 1,
57+
"react/self-closing-comp": 1,
58+
"react/sort-comp": 1,
59+
"react/wrap-multilines": 1
60+
},
61+
"globals": {
62+
}
63+
}

.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
# Compiled binary addons (http://nodejs.org/api/addons.html)
23+
build/Release
24+
25+
# Dependency directory
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27+
node_modules
28+
29+
#dist folder
30+
dist
31+
32+
#Webstorm metadata
33+
.idea
34+
35+
# Mac files
36+
.DS_Store

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-exact=true

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Cory House
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# INF
2+
3+
Based on React Slingshot. Tech includes:
4+
5+
| **Tech** | **Description** |**Learn More**|
6+
|----------|-------|---|
7+
| [React](https://facebook.github.io/react/) | Fast, composable client-side components. | [Pluralsight Course](https://www.pluralsight.com/courses/react-flux-building-applications) |
8+
| [Redux](http://redux.js.org) | Enforces unidirectional data flows and immutable, hot reloadable store. Lean alternative to [Facebook's Flux](https://facebook.github.io/flux/docs/overview.html).| [Tutorial](https://egghead.io/series/getting-started-with-redux) |
9+
| [Babel](http://babeljs.io) | Compiles ES6 to ES5. Enjoy the new version of JavaScript today. | [ES6 REPL](https://babeljs.io/repl/), [ES6 vs ES5](http://es6-features.org), [ES6 Katas](http://es6katas.org), [Pluralsight course](https://www.pluralsight.com/courses/javascript-fundamentals-es6) |
10+
| [Webpack](http://webpack.github.io) | Bundles npm packages and our JS into a single file. Includes hot reloading via [react-transform-hmr](https://www.npmjs.com/package/react-transform-hmr). | [Pluralsight Course](https://www.pluralsight.com/courses/webpack-fundamentals)|
11+
| [Browsersync](https://www.browsersync.io/) | Lightweight development HTTP server that supports synchronized testing and debugging on multiple devices. | [Intro vid](https://www.youtube.com/watch?time_continue=1&v=heNWfzc7ufQ)|
12+
| [Mocha](http://mochajs.org) | Automated tests with [Chai](http://chaijs.com/) for assertions and [Cheerio](https://www.npmjs.com/package/cheerio) for DOM testing without a browser using Node. | [Pluralsight Course](https://www.pluralsight.com/courses/testing-javascript) |
13+
| [TrackJS](https://trackjs.com/) | JavaScript error tracking. | [Free trial](https://my.trackjs.com/signup)|
14+
| [ESLint](http://eslint.org/)| Lint JS. Reports syntax and style issues. Using [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react) for additional React specific linting rules. | |
15+
| [SASS](http://sass-lang.com/) | Compiled CSS styles with variables, functions, and more. | [Pluralsight Course](https://www.pluralsight.com/courses/better-css)|
16+
| [Editor Config](http://editorconfig.org) | Enforce consistent editor settings (spaces vs tabs, etc). | [IDE Plugins](http://editorconfig.org/#download) |
17+
| [npm Scripts](https://docs.npmjs.com/misc/scripts)| Glues all this together in a handy automated build. | [Pluralsight course](https://www.pluralsight.com/courses/npm-build-tool-introduction) |
18+
19+
The starter kit includes a working example app that puts all of the above to use.
20+
21+
## Get Started
22+
1. **Initial Machine Setup**. First time running the starter kit? Then complete the [Initial Machine Setup](https://github.com/coryhouse/react-slingshot#initial-machine-setup).
23+
2. **Clone the project**. `git clone https://github.com/coryhouse/react-slingshot.git`.
24+
3. **Install Node packages**. `npm install`
25+
4. **Run the example app**. `npm start -s`
26+
This will run the automated build process, start up a webserver, and open the application in your default browser. When doing development with this kit, you'll want to keep the command line open at all times so that your code is rebuilt and tests run automatically every time you hit save. Note: The -s flag is optional. It enables silent mode which supresses unnecessary messages during the build.
27+
5. **Review the example app.** This starter kit includes a working example app that calculates fuel savings. Note how all source code is placed under /src. Tests are placed alongside the file under test. The final built app is placed under /dist. These are the files you run in production.
28+
6. **Delete the example app files.** Once you're comfortable with how the example app works, you can [delete those files and begin creating your own app](https://github.com/coryhouse/react-slingshot#i-just-want-an-empty-starter-kit). You can always refer to this repo for the example app code that you deleted.
29+
30+
| **Script** | **Description** |
31+
|----------|-------|
32+
| prestart | Runs automatically before start. Calls remove-dist script which deletes the dist folder. This helps remind you to run the build script before committing since the dist folder will be deleted if you dont. ;) |
33+
| start | Runs tests, lints, starts dev webserver, and opens the app in your default browser. |
34+
| open | Opens the app in your default browser. |
35+
| lint | Runs ESLint. |
36+
| lint:watch | Runs ESLint and watches all files so that they are automatically linted upon save. |
37+
| clean-dist | Removes everything from the dist folder. |
38+
| remove-dist | Deletes the dist folder. |
39+
| create-dist | Creates the dist folder and the necessary subfolders. |
40+
| build:html | Adds trackJS tracking script and copies to /dist. |
41+
| build:sass | Compiles SASS, minifies, generates sourcemap, and stores in /dist. |
42+
| prebuild | Runs automatically before build script (due to naming convention). Cleans dist folder, builds html, and builds sass. |
43+
| build | Bundles all JavaScript using webpack and writes it to /dist. |
44+
| build:verbose | Same as above, but verbose so you can see all the details happening including warnings. |
45+
| test | Runs tests (files ending in .spec.js) using Mocha and outputs results to the command line. Watches all files so tests are re-run upon save. |

package.json

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "INF",
3+
"version": "1.0.0",
4+
"description": "INF - calculate real cost of company purchases",
5+
"scripts": {
6+
"prestart": "npm run remove-dist",
7+
"start": "parallelshell \"npm run test:watch\" \"npm run open\"",
8+
"open": "node tools/server.js",
9+
"lint": "eslint src",
10+
"lint:watch": "watch 'npm run lint' src",
11+
"clean-dist": "npm run remove-dist && npm run create-dist",
12+
"remove-dist": "node_modules/.bin/rimraf ./dist",
13+
"create-dist": "mkdir dist && cd dist && mkdir js && mkdir styles",
14+
"build:html": "node tools/buildHtml.js",
15+
"build:sass": "node-sass --quiet --output dist/styles src/styles/styles.scss --source-map true --output-style compressed",
16+
"prebuild": "npm run clean-dist && npm run build:html && npm run build:sass",
17+
"build": "npm run test && npm run build:verbose -- -s",
18+
"build:verbose": "node tools/build.js",
19+
"test": "cross-env NODE_ENV=test mocha --reporter progress --compilers js:babel/register --recursive \"./src/**/*.spec.js\"",
20+
"test:watch": "npm run test -- --watch"
21+
},
22+
"author": "Piotr Machowski",
23+
"license": "MIT",
24+
"dependencies": {
25+
"normalize.css": "3.0.3",
26+
"react": "0.14.0",
27+
"react-dom": "0.14.0",
28+
"react-redux": "4.0.0",
29+
"redux": "3.0.4"
30+
},
31+
"devDependencies": {
32+
"babel": "5.8.23",
33+
"babel-eslint": "4.1.6",
34+
"babel-loader": "5.1.4",
35+
"babel-plugin-react-display-name": "2.0.0",
36+
"babel-plugin-react-transform": "1.1.1",
37+
"browser-sync": "2.10.0",
38+
"chai": "3.3.0",
39+
"cheerio": "0.19.0",
40+
"colors": "1.1.2",
41+
"cross-env": "1.0.6",
42+
"css-loader": "0.23.0",
43+
"eslint": "1.10.3",
44+
"eslint-loader": "1.1.1",
45+
"eslint-plugin-react": "3.10.0",
46+
"file-loader": "0.8.5",
47+
"mocha": "2.3.3",
48+
"node-sass": "3.4.2",
49+
"parallelshell": "2.0.0",
50+
"react-transform-catch-errors": "1.0.0",
51+
"react-transform-hmr": "1.0.1",
52+
"redbox-react": "1.2.0",
53+
"rimraf": "2.5.0",
54+
"sass-loader": "3.1.2",
55+
"style-loader": "0.12.3",
56+
"watch": "0.16.0",
57+
"webpack": "1.12.9",
58+
"webpack-dev-middleware": "1.4.0",
59+
"webpack-hot-middleware": "2.6.0",
60+
"yargs": "3.31.0"
61+
}
62+
}

src/actions/infAppActions.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as actionTypes from '../constants/actionTypes';
2+
3+
export function saveCalculation() {
4+
return { type: actionTypes.SAVE_CALCULATION };
5+
}
6+
7+
export function deleteCalculation(key) {
8+
return { type: actionTypes.DELETE_CALCULATION, key };
9+
}
10+
11+
export function changeCalculationName(key, name) {
12+
return { type: actionTypes.CHANGE_CALCULATION_NAME, key, name };
13+
}
14+
15+
export function calculatePrice(key, value) {
16+
return { type: actionTypes.CALCULATE_PRICE, key, value };
17+
}
18+
19+
export function filterCalculations(filter) {
20+
return { type: actionTypes.FILTER_CALCULATIONS, filter };
21+
}

src/actions/infAppActions.spec.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import * as actions from './infAppActions';
2+
import * as actionTypes from '../constants/actionTypes';
3+
4+
import chai from 'chai';
5+
chai.should();
6+
7+
describe('Actions', () => {
8+
it('should create an action to save calculation', () => {
9+
const expectedAction = {
10+
type: actionTypes.SAVE_CALCULATION
11+
};
12+
13+
//assert
14+
actions.saveCalculation().should.deep.equal(expectedAction);
15+
});
16+
17+
it('should create an action to delete calculation', () => {
18+
const key = 'key';
19+
const expectedAction = {
20+
type: actionTypes.DELETE_CALCULATION,
21+
key
22+
};
23+
24+
//assert
25+
actions.deleteCalculation(key).should.deep.equal(expectedAction);
26+
});
27+
28+
it('should create an action to change calculation name', () => {
29+
const key = 'key';
30+
const name = 'name';
31+
const expectedAction = {
32+
type: actionTypes.CHANGE_CALCULATION_NAME,
33+
key,
34+
name
35+
};
36+
37+
//assert
38+
actions.changeCalculationName(key, name).should.deep.equal(expectedAction);
39+
});
40+
41+
it('should create an action to calculate the price', () => {
42+
const key = 'key';
43+
const value = 12;
44+
const expectedAction = {
45+
type: actionTypes.CALCULATE_PRICE,
46+
key,
47+
value
48+
};
49+
50+
//assert
51+
actions.calculatePrice(key, value).should.deep.equal(expectedAction);
52+
});
53+
54+
it('should create an action to filter calculation list', () => {
55+
const filter = 'filter';
56+
const expectedAction = {
57+
type: actionTypes.FILTER_CALCULATIONS,
58+
filter
59+
};
60+
61+
//assert
62+
actions.filterCalculations(filter).should.deep.equal(expectedAction);
63+
});
64+
});

src/businessLogic/infCalculator.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import mathHelper from '../helpers/mathHelper';
2+
import NumberFormatter from '../helpers/numberFormatter';
3+
4+
export default function infCalculator() {
5+
//private
6+
function calculateCost (price, tax, vat) {
7+
let net = price / (1 + vat);
8+
let cost = net * (1 - tax);
9+
return cost;
10+
}
11+
12+
//public
13+
return {
14+
calculateCost: calculateCost
15+
};
16+
}

0 commit comments

Comments
 (0)