Skip to content

Commit

Permalink
refactor(#491): use grape factory function
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Apr 15, 2024
1 parent 772abb9 commit 430cbcc
Showing 1 changed file with 36 additions and 29 deletions.
65 changes: 36 additions & 29 deletions src/data/crops/grape.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ export const isGrape = item => {
return 'cropFamily' in item && item.cropFamily === cropFamily.GRAPE
}

/**
* @param {Omit<farmhand.cropVariety, 'cropFamily'>} grapeProps
* @returns {Grape}
*/
const grape = grapeProps => {
const newGrape = {
...cropVariety({ ...grapeProps, cropFamily: cropFamily.GRAPE }),
}

if (!isGrape(newGrape)) {
throw new Error(`Invalid cropVariety props`)
}

return newGrape
}

/**
* @property farmhand.module:items.grapeSeed
* @type {farmhand.item}
Expand All @@ -44,119 +60,110 @@ export const grapeSeed = crop({

/**
* @property farmhand.module:items.grapeChardonnay
* @type {farmhand.cropVariety}
* @type {Grape}
*/
export const grapeChardonnay = cropVariety({
export const grapeChardonnay = grape({
...fromSeed(grapeSeed, {
variantIdx: grapeSeed.growsInto?.indexOf('grape-chardonnay'),
}),
name: 'Chardonnay Grape',
imageId: 'grape-green',
cropFamily: cropFamily.GRAPE,
})

/**
* @property farmhand.module:items.grapeSauvignonBlanc
* @type {farmhand.cropVariety}
* @type {Grape}
*/
export const grapeSauvignonBlanc = cropVariety({
export const grapeSauvignonBlanc = grape({
...fromSeed(grapeSeed, {
variantIdx: grapeSeed.growsInto?.indexOf('grape-sauvignon-blanc'),
}),
name: 'Sauvignon Blanc Grape',
imageId: 'grape-green',
cropFamily: cropFamily.GRAPE,
})

/**
* @property farmhand.module:items.grapePinotBlanc
* @type {farmhand.cropVariety}
* @type {Grape}
*/
// export const grapePinotBlanc = cropVariety({
// export const grapePinotBlanc = grape({
// ...fromSeed(grapeSeed, { variantIdx: grapeSeed.growsInto?.indexOf('grape-pinot-blanc') }),
// name: 'Pinot Blanc Grape',
// imageId: 'grape-green',
// cropFamily: cropFamily.GRAPE,
// })

/**
* @property farmhand.module:items.grapeMuscat
* @type {farmhand.cropVariety}
* @type {Grape}
*/
// export const grapeMuscat = cropVariety({
// export const grapeMuscat = grape({
// ...fromSeed(grapeSeed, { variantIdx: grapeSeed.growsInto?.indexOf('grape-muscat') }),
// name: 'Muscat Grape',
// imageId: 'grape-green',
// cropFamily: cropFamily.GRAPE,
// })

/**
* @property farmhand.module:items.grapeRiesling
* @type {farmhand.cropVariety}
* @type {Grape}
*/
// export const grapeRiesling = cropVariety({
// export const grapeRiesling = grape({
// ...fromSeed(grapeSeed, { variantIdx: grapeSeed.growsInto?.indexOf('grape-riesling') }),
// name: 'Riesling Grape',
// imageId: 'grape-green',
// })

/**
* @property farmhand.module:items.grapeMerlot
* @type {farmhand.cropVariety}
* @type {Grape}
*/
// export const grapeMerlot = cropVariety({
// export const grapeMerlot = grape({
// ...fromSeed(grapeSeed, { variantIdx: grapeSeed.growsInto?.indexOf('grape-merlot') }),
// name: 'Merlot Grape',
// imageId: 'grape-purple',
// cropFamily: cropFamily.GRAPE,
// })

/**
* @property farmhand.module:items.grapeCabernetSauvignon
* @type {farmhand.cropVariety}
* @type {Grape}
*/
export const grapeCabernetSauvignon = cropVariety({
export const grapeCabernetSauvignon = grape({
...fromSeed(grapeSeed, {
variantIdx: grapeSeed.growsInto?.indexOf('grape-cabernet-sauvignon'),
}),
name: 'Cabernet Sauvignon Grape',
imageId: 'grape-purple',
cropFamily: cropFamily.GRAPE,
})

/**
* @property farmhand.module:items.grapeSyrah
* @type {farmhand.cropVariety}
* @type {Grape}
*/
// export const grapeSyrah = cropVariety({
// export const grapeSyrah = grape({
// ...fromSeed(grapeSeed, { variantIdx: grapeSeed.growsInto?.indexOf('grape-syrah') }),
// name: 'Syrah Grape',
// imageId: 'grape-purple',
// cropFamily: cropFamily.GRAPE,
// })

/**
* @property farmhand.module:items.grapeTempranillo
* @type {farmhand.cropVariety}
* @type {Grape}
*/
export const grapeTempranillo = cropVariety({
export const grapeTempranillo = grape({
...fromSeed(grapeSeed, {
variantIdx: grapeSeed.growsInto?.indexOf('grape-tempranillo'),
}),
name: 'Tempranillo Grape',
imageId: 'grape-purple',
cropFamily: cropFamily.GRAPE,
})

/**
* @property farmhand.module:items.grapeNebbiolo
* @type {farmhand.cropVariety}
* @type {Grape}
*/
export const grapeNebbiolo = cropVariety({
export const grapeNebbiolo = grape({
...fromSeed(grapeSeed, {
variantIdx: grapeSeed.growsInto?.indexOf('grape-nebbiolo'),
}),
name: 'Nebbiolo Grape',
imageId: 'grape-purple',
cropFamily: cropFamily.GRAPE,
})

0 comments on commit 430cbcc

Please sign in to comment.