github.com/hernad/nomad@v1.6.112/ui/app/utils/remove-record.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 // Unlinks a record from all its relationships and unloads it from 7 // the store. 8 export default function removeRecord(store, record) { 9 // Collect relationship property names and types 10 const relationshipMeta = []; 11 record.eachRelationship((key, { kind }) => { 12 relationshipMeta.push({ key, kind }); 13 }); 14 15 // Push an update to this record with the relationships nulled out. 16 // This unlinks the relationship from the models that aren't about to 17 // be unloaded. 18 store.push({ 19 data: { 20 id: record.get('id'), 21 type: record.constructor.modelName, 22 relationships: relationshipMeta.reduce((hash, rel) => { 23 hash[rel.key] = { data: rel.kind === 'hasMany' ? [] : null }; 24 return hash; 25 }, {}), 26 }, 27 }); 28 29 // Now that the record has no attachments, it can be safely unloaded 30 // from the store. 31 store.unloadRecord(record); 32 }