Skip to content

Commit

Permalink
fix(findInField): return plot instead of row
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Jul 23, 2023
1 parent d2baa86 commit 58ae656
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,20 @@ export const getPriceEventForCrop = cropItem => ({
getCropLifecycleDuration(cropItem) - PRICE_EVENT_STANDARD_DURATION_DECREASE,
})

/**
* @param {Array.<Array.<?farmhand.plotContent>>} field
* @param {function(?farmhand.plotContent): boolean} condition
* @returns {?farmhand.plotContent}
*/
export const findInField = memoize(
(field, condition) => field.find(row => row.find(condition)) || null,
/**
* @param {(?farmhand.plotContent)[][]} field
* @param {function(?farmhand.plotContent): boolean} condition
* @returns {?farmhand.plotContent}
*/
(field, condition) => {
const [plot = null] =
field.find(row => {
return row.find(condition)
}) ?? []

return plot
},
{
serializer: memoizationSerializer,
}
Expand Down
5 changes: 3 additions & 2 deletions src/utils/memoize.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/** @typedef {import("fast-memoize").Options} MemoizeOptions */

import fastMemoize from 'fast-memoize'

import { MEMOIZE_CACHE_CLEAR_THRESHOLD } from '../constants'
Expand Down Expand Up @@ -42,8 +44,7 @@ export class MemoizeCache {
/**
* @template {(...args: any[]) => any} T Copied from https://github.com/caiogondim/fast-memoize.js/blob/5cdfc8dde23d86b16e0104bae1b04cd447b98c63/typings/fast-memoize.d.ts#L1
* @param {T} fn
* @param {Object} [config]
* @param {number} [config.cacheSize]
* @param {MemoizeOptions & Partial<{ cacheSize: number }>} [config]
* @returns T
* @see https://github.com/caiogondim/fast-memoize.js
*/
Expand Down

0 comments on commit 58ae656

Please sign in to comment.