github.com/manicqin/nomad@v0.9.5/ui/app/utils/remove-record.js (about)

     1  // Unlinks a record from all its relationships and unloads it from
     2  // the store.
     3  export default function removeRecord(store, record) {
     4    // Collect relationship property names and types
     5    const relationshipMeta = [];
     6    record.eachRelationship((key, { kind }) => {
     7      relationshipMeta.push({ key, kind });
     8    });
     9  
    10    // Push an update to this record with the relationships nulled out.
    11    // This unlinks the relationship from the models that aren't about to
    12    // be unloaded.
    13    store.push({
    14      data: {
    15        id: record.get('id'),
    16        type: record.constructor.modelName,
    17        relationships: relationshipMeta.reduce((hash, rel) => {
    18          hash[rel.key] = { data: rel.kind === 'hasMany' ? [] : null };
    19          return hash;
    20        }, {}),
    21      },
    22    });
    23  
    24    // Now that the record has no attachments, it can be safely unloaded
    25    // from the store.
    26    store.unloadRecord(record);
    27  }