-
Notifications
You must be signed in to change notification settings - Fork 25
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
8 changed files
with
79 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 @@ | ||
/** @typedef {import("../index").farmhand.plotContent} farmhand.plotContent */ | ||
import { memoize } from './memoize' | ||
|
||
import { memoizationSerializer } from './' | ||
|
||
export const findInField = memoize( | ||
/** | ||
* @param {(?farmhand.plotContent)[][]} field | ||
* @param {function(?farmhand.plotContent): boolean} condition | ||
* @returns {?farmhand.plotContent} | ||
*/ | ||
(field, condition) => { | ||
for (const row of field) { | ||
for (const plot of row) { | ||
if (condition(plot)) { | ||
return plot | ||
} | ||
} | ||
} | ||
|
||
return null | ||
}, | ||
{ | ||
serializer: memoizationSerializer, | ||
} | ||
) |
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,33 @@ | ||
/** | ||
* @typedef {import("../components/Farmhand/Farmhand").farmhand.state['field']} farmhand.state.field | ||
*/ | ||
|
||
import { carrot, pumpkin } from '../data/crops' | ||
|
||
import { findInField } from './findInField' | ||
|
||
const carrotPlot = { | ||
itemId: carrot.id, | ||
fertilizerType: 'NONE', | ||
} | ||
|
||
describe('findInField', () => { | ||
/** @type farmhand.state.field} */ | ||
const field = [[null, carrotPlot, null]] | ||
|
||
test('returns the desired plot from the field', () => { | ||
const foundPlot = findInField(field, plot => { | ||
return plot?.itemId === carrot.id | ||
}) | ||
|
||
expect(foundPlot).toEqual(carrotPlot) | ||
}) | ||
|
||
test('yields null if desired plot is not in the field', () => { | ||
const foundPlot = findInField(field, plot => { | ||
return plot?.itemId === pumpkin.id | ||
}) | ||
|
||
expect(foundPlot).toEqual(null) | ||
}) | ||
}) |
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
3b58a14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
farmhand – ./
farmhand.vercel.app
farmhand-jeremyckahn.vercel.app
farmhand-git-main-jeremyckahn.vercel.app
www.farmhand.life
farmhand.life