You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What this SHOULD do is for each item in state.patients, resolve the query object using the reference function and fetch each patient.
But actually, it will only resolve the query object once, for the first patient, and thereafter re-use the same query object and return the same patient patients.length times.
The problem is that the get function expands references back into the closure variable, mutating it for the next call.
export function get(resourceType, query, options = {}, callback = false) {
return state => {
console.log('Preparing get operation...');
resourceType = expandReferences(resourceType)(state);
query = expandReferences(query)(state);
options = expandReferences(options)(state);
This means that on the first invocation of get, the query is a function. It will be called and its value returned to query. So on the second invocation, the query is a string, and its value will be re-used.
Other adaptors expand to a new variable and leave the closure alone, which is correct and good:
export function get(resourceType, query, options = {}, callback = false) {
return state => {
console.log('Preparing get operation...');
This problem forced @mtuchi to fall back to `fn()` and do all his iteration manually in vanilla JS.
We've identified this problematic pattern on other adaptor functions as well - they all need fixing. The fix is so significant it should cause a minor or even major version bump.
The text was updated successfully, but these errors were encountered:
This is huge. And hard to explain.
If nested in an
each
, thendhis2.get
will only resolve references on the first iteration.So this code breaks:
What this SHOULD do is for each item in
state.patients
, resolve the query object using the reference function and fetch each patient.But actually, it will only resolve the query object once, for the first patient, and thereafter re-use the same query object and return the same patient
patients.length
times.The problem is that the get function expands references back into the closure variable, mutating it for the next call.
This means that on the first invocation of
get
, the query is a function. It will be called and its value returned toquery
. So on the second invocation, the query is a string, and its value will be re-used.Other adaptors expand to a new variable and leave the closure alone, which is correct and good:
export function get(resourceType, query, options = {}, callback = false) {
return state => {
console.log('Preparing get operation...');
The text was updated successfully, but these errors were encountered: