flauwekeul/honeycomb

Issues with each() and map()

flauwekeul opened this issue · 3 comments

For some reason, I cannot use map() here:
https://github.com/vfonic/honeycomb/blob/gh-pages/playground/index.ts#L74-L79

I'm also using hexagonsOrdered array instead of doing grid.each().run(), as I've been having issues using that.

Originally posted by @vfonic in #67 (comment)

I've cloned your repo and tried to figure things out, but I'm sorry man, it's too convoluted 🍝 😅 You already said your code is only a proof of concept and that's ok, but this too much for me.

A general tip to make it easier to debug: don't use global variables. For example index.ts has grid and selectedHexKey defined in module scope, but they're used in multiple functions. Currently it's very hard to know what is updating those variables at which moment.

Instead of grid.each().run() you could also use grid.hexes().

You already said your code is only a proof of concept and that's ok, but this too much for me.

That's right. :D

Actually, there might not be too much of a code to figure. There are some callbacks, but the majority of stuff happens in gatherAndRender.

What I'm stuck with is: I'm trying to modify a hex of the grid. So far I wasn't successful. I tried using: update(), map() and each(). None of them worked.

I do have grid and selectedHexKey (string) as globals. grid is always only one (global), so that shouldn't be an issue.
But, somehow, calling each() too many times gets the grid global variable out of sync with the latest changes I make to the grid hexes. :/

You can check that every time I use grid variable, I assign it back to grid global variable so that I have the latest grid:

grid = grid....

...but for whatever reason, this doesn't always work and it's difficult to make a small test, because I'm calling grid = grid... many times in several places in the code.

Thanks again for trying out the alpha version. I assume you're done with Honeycomb for now, so I'm closing this.