diff options
| author | Sam Wilkins <samuel_wilkins@brown.edu> | 2019-06-11 13:29:48 -0400 |
|---|---|---|
| committer | Sam Wilkins <samuel_wilkins@brown.edu> | 2019-06-11 13:29:48 -0400 |
| commit | c789df5ae7a9e364f0d95b54f4a2f330b536a393 (patch) | |
| tree | f7e32d53c8d6b87b0ddb860104b288107666e89c /src/client/views/collections | |
| parent | 79b37db46fda36cd779645256b03d9d074141eb6 (diff) | |
some inline documentation and new template skeletons
Diffstat (limited to 'src/client/views/collections')
| -rw-r--r-- | src/client/views/collections/CollectionBaseView.tsx | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/client/views/collections/CollectionBaseView.tsx b/src/client/views/collections/CollectionBaseView.tsx index 734669893..a3019f23e 100644 --- a/src/client/views/collections/CollectionBaseView.tsx +++ b/src/client/views/collections/CollectionBaseView.tsx @@ -106,14 +106,19 @@ export class CollectionBaseView extends React.Component<CollectionViewProps> { } if (!this.createsCycle(doc, props.Document)) { //TODO This won't create the field if it doesn't already exist - const value = Cast(props.Document[props.fieldKey], listSpec(Doc)); + const childDocs = DocListCast(props.Document[props.fieldKey]); let alreadyAdded = true; - if (value !== undefined) { - if (allowDuplicates || !value.some(v => v instanceof Doc && v[Id] === doc[Id])) { + if (childDocs !== undefined) { + // if this is not the first document added to the collection + if (allowDuplicates || !childDocs.some(v => v instanceof Doc && v[Id] === doc[Id])) { alreadyAdded = false; - value.push(doc); + childDocs.push(doc); } + // if we're here, we've tried to add a duplicate } else { + // if we are the first, set up a new list for this and all + // future child documents stored in the associated collection document at the fieldKey (likely .data) + // passed in via props alreadyAdded = false; Doc.SetOnPrototype(this.props.Document, this.props.fieldKey, new List([doc])); } |
