aboutsummaryrefslogtreecommitdiff
path: root/src/fields/List.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields/List.ts')
-rw-r--r--src/fields/List.ts19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/fields/List.ts b/src/fields/List.ts
index 5cc4ca543..9c7794813 100644
--- a/src/fields/List.ts
+++ b/src/fields/List.ts
@@ -127,6 +127,9 @@ const listHandlers: any = {
this[Self].__realFields();
return this[Self].__fields.map(toRealField).join(separator);
},
+ lastElement() {
+ return this[Self].__realFields().lastElement();
+ },
lastIndexOf(valueToFind: any, fromIndex: number) {
if (valueToFind instanceof RefField) {
return this[Self].__realFields().lastIndexOf(valueToFind, fromIndex);
@@ -210,10 +213,10 @@ 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 {
+function listGetter(target: any, prop: string | symbol, receiver: any): any {
if (listHandlers.hasOwnProperty(prop)) {
return listHandlers[prop];
}
@@ -271,19 +274,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(pfields => promised.forEach(p => p.field.setValue(pfields[p.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);
}