-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(grid): change how a grid's store is set
Instead of having to pass a store manually when creating a grid, the grid always makes a store. When passed one or more traversers, the store is populated with the hexes that the traversers produce. When passed a store, the grid's store is set to that store and it use those hexes to traverse over. BREAKING CHANGE: Remove the of() static grid method, because it's a rather redundant as it does the same as the constructor. Also update the inStore function to be used directly as a grid iterator method callback (before change: `grid.each(inStore())`, after change: `grid.each(inStore)`). Remove setStore() because it's ambiguous how the store should be set: hexes could be removed/added/updated from the store.
- Loading branch information
1 parent
b505b2b
commit 2376845
Showing
7 changed files
with
94 additions
and
53 deletions.
There are no files selected for viewing
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,13 @@ | ||
import { createHex, createHexPrototype } from '../../hex' | ||
import { Grid } from '../grid' | ||
import { at } from '../traversers' | ||
import { inStore } from './inStore' | ||
|
||
test('returns whether the passed hex is present in the passed store', () => { | ||
const hexPrototype = createHexPrototype() | ||
const hex = createHex(hexPrototype, { q: 1, r: 2 }) | ||
|
||
expect(inStore(hex, new Grid(hexPrototype, new Map([[hex.toString(), hex]])))).toBe(true) | ||
expect(inStore(hex, new Grid(hexPrototype, at({ q: 3, r: 4 })))).toBe(false) | ||
expect(inStore(hex, new Grid(hexPrototype))).toBe(false) | ||
}) |
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import { Hex } from '../../hex' | ||
import { Grid } from '../grid' | ||
|
||
export const inStore = <T extends Hex>(store?: Map<string, T>) => (hex: T, grid: Grid<T>): boolean => | ||
!!(store ?? grid.store)?.get(hex.toString()) | ||
export const inStore = <T extends Hex>(hex: T, grid: Grid<T>) => grid.store.has(hex.toString()) |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from './flatTraverse' | ||
export * from './inStore' | ||
export * from './neighborOf' | ||
export * from './setStore' |
This file was deleted.
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