Facts are immutable.
But sometimes we want to record the values of properties that can change over time.
To do so, define a new fact type representing a change to that value.
The name of a site should be allowed to change.
That is why we didn't include it as a field of the Site fact.
To model this, define a SiteName fact that refers to the site and stores the new value.
It should also refer to past SiteName facts that it replaces.
When we create the first instance of the site name fact, we have no prior names to replace.
So we pass in an empty array.
var siteName0 =await jinagaClient.Fact(newSiteName(site,"My Site",[]));
jinagaClient.RenderFacts(siteName0)
If the user changes the name of the site, then we record that with a new fact that replaces the first one.
var siteName1 =await jinagaClient.Fact(newSiteName(site,"My Blog",[siteName0]));
jinagaClient.RenderFacts(siteName1)
If they change it again, we only include the most recent value that we are replacing.
There is no need to list all of the past values, since some of them have already been replaced.
This forms a chain of values that the property took on over time.
var siteName2 =await jinagaClient.Fact(newSiteName(site,"My Journal",[siteName1]));
jinagaClient.RenderFacts(siteName2)
To find the current name of a site, we look for site names that have not been replaced.
Let's take this in two parts.
First, look for all of the names of a site.
This will include all past values.
var namesOfSite = Given<Site>.Match((site, facts)=>from name in facts.OfType<SiteName>()wherename.site == site
select name);var names =await jinagaClient.Query(namesOfSite, site);
names.Count()
3
Second, let's filter this history.
We only want the names for which there is no next value.
namesOfSite = Given<Site>.Match((site, facts)=>from name in facts.OfType<SiteName>()wherename.site == site
// Filter out names for which a next name existswhere!facts.Any<SiteName>(next => next.prior.Contains(name))select name);
names =await jinagaClient.Query(namesOfSite, site);
names.Count()