diff options
Diffstat (limited to 'src/fields/List.ts')
-rw-r--r-- | src/fields/List.ts | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/fields/List.ts b/src/fields/List.ts index edaa16003..1e1adc7a8 100644 --- a/src/fields/List.ts +++ b/src/fields/List.ts @@ -210,7 +210,7 @@ function toObjectField(field: Field) { } function toRealField(field: Field) { - return field instanceof ProxyField ? field.value() : field; + return field instanceof ProxyField ? field.value : field; } function listGetter(target: any, prop: string | number | symbol, receiver: any): any { @@ -271,25 +271,17 @@ class ListImpl<T extends Field> extends ObjectField { // this requests all ProxyFields at the same time to avoid the overhead // of separate network requests and separate updates to the React dom. private __realFields() { - const promised = this.__fields.filter(f => f instanceof ProxyField && f.promisedValue()).map(f => ({ field: f as any, promisedFieldId: f instanceof ProxyField ? f.promisedValue() : '' })); + const unrequested = this.__fields.filter(f => f instanceof ProxyField && f.needsRequesting).map(f => f as ProxyField<RefField>); // if we find any ProxyFields that don't have a current value, then // start the server request for all of them - if (promised.length) { - const batchPromise = DocServer.GetRefFields(promised.map(p => p.promisedFieldId)); + if (unrequested.length) { + const batchPromise = DocServer.GetRefFields(unrequested.map(p => p.fieldId)); // as soon as we get the fields from the server, set all the list values in one // action to generate one React dom update. - batchPromise.then( - action(pfields => { - for (let i = 0; i < promised.length; i++) { - promised[i].field.setValue(pfields[promised[i].promisedFieldId]); - } - }) - ); + const allSetPromise = batchPromise.then(action(pfields => unrequested.map(toReq => toReq.setValue(pfields[toReq.fieldId])))); // we also have to mark all lists items with this promise so that any calls to them // will await the batch request and return the requested field value. - // This assumes the handler for 'promise' in the call above being invoked before the - // handler for 'promise' in the lines below. - promised.forEach(p => p.field.setPromise(batchPromise.then(pfields => pfields[p.promisedFieldId]))); + unrequested.forEach(p => p.setExternalValuePromise(allSetPromise)); } return this.__fields.map(toRealField); } |