And we're going to add two additional methods.
SetCurrentThingForCurrentImage, and setCurrentImageForCurrentThing.
And so, the purpose of these two functions is that,
based on what the current image is what should be the current thing.
And then the opposite,
based on what the current thing is, what should be the current image.
So clearly, one is going to be called versus the other,
depending on which index we're changing.
So when we're changing current image, conceptually,
we want to call set the current thing for the current image.
We just changed the current image.
And then, if we're setting the current thing.
You got it.
Conceptually, we want to set the CurrentImage for the CurrentThing.
However, we're not always going to want to do that,
because we'd end up in an endless loop.
If we change the image, we change the thing, we change the thing let's change
the image, so let's add a concept of skipping the thing update.
If the color of this method is wise enough to know
there's such a thing as skipping a thing, they have the option of passing in a true.
But what we don't know about this concept,
we will evaluate not true and we will do the update.
So essentially when we call from the components the way we've been doing
the skip thing will evaluate to a non true value and
we will end up updating the current image.
And the same thing for set current thing.
We want to provide the option to skip updating the image if they supply
skip image.
We want certain callers of this method to be knowledgeable of this interdependency
and be able to turn off update of the other side.
And the methods that are knowledgeable about this interdependency,
is this setCurrentThingForCurrentImage and setCurrentImageForCurrentThing.
All right let me walk you through with us if I'm going to set the current thing for
the current image the first thing I need is the current image and if my
current image doesn't have a thing then our current thing index should be null.
Otherwise if thing ID is not null then we get work to do well maybe.
Let's go find out what current thing is because if we are already pointing at
the current thing then we have nothing to do.
However if we're not pointing at a current thing, or the current things ID is not
the ID of what the image is referencing we obviously do have work to do.
We have to find that current thing.
Well before we find it, let's null out the index.
So no one thinks that the previous current thing is still the current thing.
Let's null that out as soon as possible and
let's use just a simple loop to loop through the list of things to peek at each
one of the things to see if it's the thing we're looking for.
And if it is the thing we're looking for, then let's call setCurrentThing,
the same method that our components are calling, providing an index.
Except we pass in this extra true, which says, to skip updating the current index
for the image, because that's the reason this method was called to begin with.
Then of course when we have completed that,
there's nothing more to do so let's get out.
So if we hit refresh, let me display my things and
display my images and there's one small problem, let's make sure we address that.
That by default these are mis matching,
if I click on Boded Harbor place, water taxi is associated with that.
If I click on blue blubber jellies, then it's the national aquarium.
If I click on the front entrance of The Hyatt then it's the Hyatt.