Skip to content

Commit

Permalink
fix(intg): set lastPassedEntry manually
Browse files Browse the repository at this point in the history
- `lastPassedEntry was previously `rightEntry`
- `lastPassedEntry` used to be a `computed` value
  • Loading branch information
lemredd committed Jan 16, 2023
1 parent ca03111 commit 8b50c60
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/components/CalculatorContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,10 @@ const operation = ref<Operations|null>(null)
const previousResult = ref("0")
const previousExpressionEvaluated = ref("")
const evaluation = ref<Evaluations|null>(null)
const lastPassedEntry = ref<number|null>(null)
const historyList = ref<HistoryList>([])
const hasPreviousEntry = computed(() => Boolean(previousEntry.value) && Boolean(operation.value))
const rightEntry = computed(() => {
let entry: number|null = null
const [ unusedLeftOperand, rightOperand ] = previousExpressionEvaluated.value.split(operation.value as Operations)
const mayIdentifyRightEntry = previousExpressionEvaluated.value && rightOperand
if (mayIdentifyRightEntry) entry = Number(rightOperand)
return entry
})
const expressionToEvaluate = computed({
get() {
let value = ""
Expand All @@ -59,7 +51,7 @@ const expressionAndPreviousResultInformation = reactive({
operation,
previousEntry,
previousResult,
rightEntry
rightEntry: lastPassedEntry
})
function popOneDigit() {
Expand Down Expand Up @@ -143,8 +135,12 @@ function retrieveEvaluationResults(newEvaluation: Evaluations, result: number) {
|| newEvaluation === ""
|| newEvaluation === ""
if (!previousExpressionEvaluated.value) previousExpressionEvaluated.value = expressionToEvaluate.value
if (hasSavedPreviousResult.value) expressionToEvaluate.value = `${previousResult.value}${operation.value}${rightEntry.value}`
previousExpressionEvaluated.value = expressionToEvaluate.value
if (!lastPassedEntry.value) {
const [ leftOperand, unusedRightOperand ] = previousExpressionEvaluated.value.split(operation.value as Operations)
lastPassedEntry.value = Number(leftOperand)
}
if (hasSavedPreviousResult.value) expressionToEvaluate.value = `${previousResult.value}${operation.value}${lastPassedEntry.value}`
if (mustSaveCurrentEntry) previousEntry.value = Number(entry.value)
evaluation.value = newEvaluation
Expand Down

0 comments on commit 8b50c60

Please sign in to comment.