bugfix: allow cache to merge resource #558
This MR introduce one change to the store: when we cache a resource, if it already exists, we merge existing data with the new one.
To test, 2 scenarios:
Scenario 1
- We load
user-1
in the 1rstsib-display
which has acity
(city-1
), with aname
. - We also load
city-1
in the 3rdsib-display
which only has aname
. The 3rdsib-display
should show aname
, that's all we know aboutcity-1
- We click on Set source "user-2". It loads a
user-2
in the 2ndsib-display
which also hascity-1
. But this time, it has azipcode
. - We click Refresh. The
zipcode
appears in the3rdsib-display
. Datas fromcity-1
contained inuser-2
graph has been merged.
<sib-display
data-src="user-1.jsonld"
fields="name"
></sib-display>
<sib-display
id="user2"
fields="name"
></sib-display>
<button id="first">Set source "user-2"</button>
<sib-display
id="city"
data-src="city-1.jsonld"
fields="name, zipcode"
></sib-display>
<button id="second">Refresh</button>
<script>
first.onclick = () => document.getElementById('user2').dataset.src = "user-2.jsonld";
second.onclick = () => document.getElementById('city').dataset.src = document.getElementById('city').dataset.src;
</script>
with the following datas in jsonld files:
{
"@id": "user-1.jsonld",
"name": "John",
"city": {
"@id": "city-1.jsonld",
"name": "Rennes"
},
"@context": "https://cdn.happy-dev.fr/owl/hdcontext.jsonld"
}
{
"@id": "user-2.jsonld",
"name": "Jack",
"city": {
"@id": "city-1.jsonld",
"zipcode": "35000"
},
"@context": "https://cdn.happy-dev.fr/owl/hdcontext.jsonld"
}
{
"@id": "city-1.jsonld",
"name": "Rennes",
"@context": "https://cdn.happy-dev.fr/owl/hdcontext.jsonld"
}
Scenario 2
- we load
users/matthieu/circles
in the 1rstsib-display
, which has manycircle-members/X
, all with acircle
property - click on Set source circle-members. It loads
circle-members/118
in the 3rdsib-display
from the cache (it has been cached by the 1rst request). Thecircle
property appears - click on Set source members. It loads in the 2nd
sib-display
:circles/13/members
, which has manycircle-members/X
withuser
property. It will cache or merge all thesecircle-members/X/
- click on refresh. The 3rd
sib-display
should now also show theuser
property which has been loaded by the 2nd sib-display
(depending on your account, you may change the src values)
<sib-display
id="circles"
data-src="https://api.alpha.happy-dev.fr/users/matthieu/circles/"
fields="@id"
></sib-display>
<sib-display
id="members"
fields="@id"
></sib-display>
<sib-display
id="circle-members"
fields="circle, user"
></sib-display>
<button id="first">Set source circle-members</button>
<button id="second">Set source members</button>
<button id="third">Refresh</button>
<script>
first.onclick = () => document.getElementById('circle-members').dataset.src = "https://api.alpha.happy-dev.fr/circle-members/118/";
second.onclick = () => document.getElementById('members').dataset.src = "https://api.alpha.happy-dev.fr/circles/13/members/";
third.onclick = () => document.getElementById('circle-members').dataset.src = document.getElementById('circle-members').dataset.src;
</script>
Edited by Matthieu Fesselier