Skip to content

Commit

Permalink
Switch to search for singular containment ref
Browse files Browse the repository at this point in the history
  • Loading branch information
garethj2 committed Nov 27, 2024
1 parent 01bbbcd commit c7cfb06
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
10 changes: 4 additions & 6 deletions spec/core/HNamespace.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1938,11 +1938,9 @@ describe('HNamespace', function (): void {
})
}) // #getContainmentRefs()

describe('#findContainmentRefs()', function (): void {
it('returns a list of all the containment refs for a def', function (): void {
expect(
defs.findContainmentRefs('site').map((def) => def.defName)
).toEqual(['siteRef'])
describe('#findContainmentRef()', function (): void {
it('returns the containment ref for a def', function (): void {
expect(defs.findContainmentRef('site')?.defName).toEqual('siteRef')
})
}) // #findContainmentRefs()
}) // #findContainmentRef()
})
8 changes: 4 additions & 4 deletions src/core/HNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1659,18 +1659,18 @@ export class HNamespace {
}

/**
* Return all the containment refs for the specified def.
* Return the first containment ref def that matches the specified name.
*
* Please note, this will filter out any defs that are marked as deprecated.
*
* @param name The name of the def to search the ref for.
* @returns The containment defs.
* @returns The containment ref def.
*/
public findContainmentRefs(name: string | HSymbol): HDict[] {
public findContainmentRef(name: string | HSymbol): HDict | undefined {
return this.getContainmentRefs().filter(
(def) =>
!def.has('deprecated') &&
this.fits(name, def.get('containedBy') as HSymbol)
)
)[0]
}
}
8 changes: 4 additions & 4 deletions src/core/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,13 @@ export function addContainmentRefs(
dict.set('spaceRef', spaceRef)
}

const refName = namespace.findContainmentRefs(
namespace.reflect(parent).type.defName
)?.[0]?.defName
const refName =
namespace.findContainmentRef(namespace.reflect(parent).type.defName)
?.defName ?? ''

if (refName && !dict.has(refName)) {
dict.set(refName, parent.get('id') as HRef)
}

return refName ?? ''
return refName
}

0 comments on commit c7cfb06

Please sign in to comment.