It is not strictly be design (that might be a bug if you can come up with a 
simple descriptive example that we can copy into elm-try or so), but it is 
easy to work-around.

What I do is make just an integer (some primitive value), and just 
increment it whenever the view should be updated (gotta be careful to catch 
all cases though), then use that as the key in a `lazy` call that then 
wraps the rest of the view, that way the view only updates when the integer 
key is incremented (I wrap it around at 2 billion just-in-case that ever is 
hit).

However that makes the diff compare only the key before checking everything 
else, and if the key integer is unchanged then the entire view is skipped 
for diffing, thus making it very fast.  :-)

You can add more keys and more lazy's for sections of the board as well if 
you need to get more fine grained.  Just always try to use a primitive as 
the key or a record that is passed verbatim from model update to model 
update.


On Wednesday, February 8, 2017 at 5:43:26 AM UTC-7, Julian wrote:
>
> Hi all!
>
> I've been working on a board game using elm and I'm using svg for 
> rendering. I render the game by first drawing the board in the background, 
> and then I render one square for each tile that can hold a game piece. When 
> implementing this, I created a svg symbol for every variation of the tiles 
> (empty, filled, mouse over,...) and for each tile rendered, I reference the 
> symbol to use with the *use* tag and *xlink:href* attribute.
>
> To start with, for unknown reason, chrome fires an event every time the 
> mouse moves over a tile even if I only register for mouseover events on the 
> tiles. This would be fine if it wasn't for the fact that the whole board is 
> being re-rendered on *every* mouseover event, even though the underlying 
> model never changes (mouse is only moving inside a tile, so ideally I 
> wouldn't have to redraw anything).
>
> When digging into the javascript code, I noticed that the diff mechanism 
> always marks the whole model as being changed, and therefor force a full 
> re-render. However, when I manually diff json representations of the model, 
> I see that they are identical. I noticed that when *diffFacts* is being 
> called with the use tags' attributes object (containing the *xlink:href*), 
> it always marks it as a change even if they are identical.
>
> For comparison, I made an isolated version where I compared rendering two 
> tiles using symbols vs just simply rendering rect tags directly (switching 
> the fill color). And as expected, for the non-symbol version, re-render is 
> only triggered when the model actually changes, and always triggered when 
> using symbols.
>
> Here is a gist for the isolated version 
> https://gist.github.com/Shump/bd778bde23af0dd3f8c95f92ec45fc33
>
> Any idea if this is expected behavior? Or is this a bug with the virtual 
> dom code?
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to