Skip to content

Instantly share code, notes, and snippets.

@breeko
breeko / setOperand.js
Created July 20, 2018 10:53
setOperand function for OpenCalc
setOperand(op: Operation): ?Operation {
let newNumber: ?string;
if (!Validator.validDigit(op.stringVal, this.queue)) {
return null;
}
let lastOp: ?Operation = lastOrNull(this.queue);
if (lastOp && (
this.cleared ||
@breeko
breeko / setOperand.js
Created July 20, 2018 10:53
setOperand function for OpenCalc
setOperand(op: Operation): ?Operation {
let newNumber: ?string;
if (!Validator.validDigit(op.stringVal, this.queue)) {
return null;
}
let lastOp: ?Operation = lastOrNull(this.queue);
if (lastOp && (
this.cleared ||
@breeko
breeko / OperationTypes.js
Last active July 20, 2018 10:07
Operation Types and SubTypes for OpenCalc
//@flow
export const OperationType = Object.freeze({
'Constant': 1, // a constant value (e.g. 2, 5, pi)
'Operation': 2, // can be calculated based on inputs (e.g. cos, +, !)
'Equals': 3, // clears and evaluates the queue
'Clear': 4, // clears the queue
'Parenthesis': 5, // parenthesis
});
export const OperationSubType = Object.freeze({
@breeko
breeko / CalculatorBrain.js
Created July 20, 2018 01:17
Calculator Brain for OpenCalc
//@flow
import {Operation, newOperation} from './Operations';
import {OperationType, OperationSubType, OperationArgs} from './OperationTypes';
import {zipWithIndexTwice, lastOrNull, isInArray, numberWithCommas, isNumeric} from '../utils/Utils';
import CalcUtils from '../utils/CalculatorUtils';
import Validator from '../utils/Validator';
export default class CalculatorBrain {
@breeko
breeko / Operations.js
Created July 10, 2018 11:14
Operations file for OpenCalc
//@flow
import {isInArray, multiply} from '../utils/Utils';
import {OperationType, OperationSubType, OperationArgs} from './OperationTypes';
const OperationsOverloaded = Object.freeze({
'−': Object.freeze({
UnaryOp: 'neg',
BinaryOp: '−'
})
});
@breeko
breeko / CalculatorResponse.js
Last active July 4, 2018 12:34
Calculator response component for OpenCalc
//@flow
import React, {Component} from 'react';
import {SafeAreaView, Text, ScrollView, StyleSheet, TouchableHighlight, Alert, Clipboard, Dimensions} from 'react-native';
import Colors from '../constants/Colors';
import Constants from '../constants/Constants'
import { isNumeric } from '../utils/Utils';
type Props = {
topDisplay: string,
@breeko
breeko / CalculatorButton.js
Created July 4, 2018 12:24
Calculator Button for OpenCalc
//@flow
import React, {Component} from 'react';
import {Text, StyleSheet, TouchableOpacity} from 'react-native';
import Colors from '../constants/Colors';
import Constants from '../constants/Constants'
type Props = {
operator: string,
handleButtonPress: (string) => any,
}
@breeko
breeko / CalculatorButtonsContainer.js
Created July 4, 2018 12:19
Calculator button layout for OpenCalc
//@flow
import React, {Component} from 'react';
import {View, StyleSheet} from 'react-native';
import CalculatorButton from './CalculatorButton';
type Props = {
handleButtonPress: (string) => any,
reset: () => any,
deleteLast: () => any,
switchButton: () => any,
@breeko
breeko / index.js
Created June 30, 2018 14:44
Index.js for OpenCalc
import { AppRegistry } from 'react-native';
import App from './app/App';
import { YellowBox } from 'react-native';
AppRegistry.registerComponent('OpenCalc', () => App);
YellowBox.ignoreWarnings(['Warning: isMounted(...) is deprecated', 'Module RCTImageLoader','Class RCTCxxModule']);
@breeko
breeko / App.js
Last active July 4, 2018 12:05
App.js for OpenCalc
//@flow
import React, {Component} from 'react';
import {StyleSheet, View, Clipboard} from 'react-native';
import CalculatorResponse from './components/CalculatorResponse';
import CalculatorBrain from './core/CalculatorBrain';
import Colors from './constants/Colors';
import Constants from './constants/Constants'