This file contains hidden or 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
import calculate from '../utils/calculate.js' | |
describe('Calculate', () => { | |
let expression; | |
it ('evaluates the expression correctly', () => { | |
expression = '2+3+4-4*3' | |
expect(calculate(expression)).toBe(-3); | |
expression = '0+3+4' | |
expect(calculate(expression)).toBe(7); |
This file contains hidden or 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
export default (expression) => { | |
const matched = (new RegExp('([\\d]+\\.?[\\d]*)?([-+/*][\\d]+\\.?[\\d]*)*')).exec(expression) | |
if (!matched) { | |
return 0; | |
} | |
if (/^[*+\/]/.test(expression)){ | |
return () => { |
This file contains hidden or 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
import { createStore, combineReducers } from 'redux'; | |
import calculateReducer from './reducers/calculateReducer' | |
const rootReducer = combineReducers({ | |
calculator: calculateReducer | |
}) | |
export default createStore( | |
rootReducer, | |
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() |
This file contains hidden or 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
import * as types from '../types'; | |
import calculate from '../../utils/calculate' | |
let initialState = { | |
expression: '', | |
total: 0 | |
} | |
function setExpression({ expression, total}, action) { |
This file contains hidden or 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
export const SET_EXPRESSION = 'SET_EXPRESSION'; | |
export const CLEAR_EXPRESSION = 'CLEAR_EXPRESSION'; | |
export const DELETE_LAST_EXPRESSION_ENTRY = 'DELETE_LAST_EXPRESSION_ENTRY'; | |
export const EVALUATE_EXPRESSION = 'EVALUATE_EXPRESSION'; |
This file contains hidden or 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
import * as types from '../types'; | |
export const calculate = (key) => { | |
return { | |
type: types.SET_EXPRESSION, | |
payload: key | |
} | |
} | |
This file contains hidden or 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
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import './index.css'; | |
import App from './App'; | |
import { Provider } from 'react-redux'; | |
import store from './store'; | |
ReactDOM.render( | |
<Provider store={store}> | |
<App /> | |
</Provider>, |
This file contains hidden or 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
import React, { Component } from 'react' | |
import { connect } from 'react-redux' | |
import { calculate, deleteLastEntry, clear, evaluateExpression } from './store/actions/calculate' | |
import Calculator from './components/calculator' | |
import * as fromCalculator from './store' | |
import './App.css' | |
export class App extends Component { | |
componentDidMount () { |
This file contains hidden or 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
import Screen from './Screen' | |
import Keypad from './Keypad' | |
import Button from './Button' | |
export default { | |
Screen, | |
Keypad, | |
Button | |
} |
This file contains hidden or 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
import React from 'react'; | |
import { Textfit } from 'react-textfit'; | |
export default (props) => { | |
return ( | |
<div className="screen--container"> | |
<Textfit | |
max={40} | |
throttle={60} | |
mode="single" | |
className="screen-top" |
OlderNewer