-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29343 from Sidnioulz/sidnioulz/component-entry-ta…
…gs-intersection Manager: Add tags property to ComponentEntry objects
- Loading branch information
Showing
6 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default <T>(a: T[], b: T[]): T[] => { | ||
// no point in intersecting if one of the input is ill-defined | ||
if (!a || !b) { | ||
return []; | ||
} | ||
|
||
return a.reduce((acc: T[], aValue) => { | ||
if (b.includes(aValue)) { | ||
acc.push(aValue); | ||
} | ||
|
||
return acc; | ||
}, []); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
import intersect from '../lib/intersect'; | ||
|
||
describe('Manager API utilities - intersect', () => { | ||
it('returns identity when intersecting identity', () => { | ||
const a = ['foo', 'bar']; | ||
expect(intersect(a, a)).toEqual(a); | ||
}); | ||
|
||
it('returns a when b is a superset of a', () => { | ||
const a = ['foo', 'bar']; | ||
const b = ['a', 'foo', 'b', 'bar', 'c', 'ter']; | ||
expect(intersect(a, b)).toEqual(a); | ||
}); | ||
|
||
it('returns b when a is a superset of b', () => { | ||
const a = ['a', 'foo', 'b', 'bar', 'c', 'ter']; | ||
const b = ['foo', 'bar']; | ||
expect(intersect(a, b)).toEqual(b); | ||
}); | ||
|
||
it('returns an intersection', () => { | ||
const a = ['a', 'bar', 'b', 'c']; | ||
const b = ['foo', 'bar', 'ter']; | ||
expect(intersect(a, b)).toEqual(['bar']); | ||
}); | ||
|
||
it('returns an empty set when there is no overlap', () => { | ||
const a = ['a', 'b', 'c']; | ||
const b = ['foo', 'bar', 'ter']; | ||
expect(intersect(a, b)).toEqual([]); | ||
}); | ||
|
||
it('returns an empty set if a is undefined', () => { | ||
const b = ['foo', 'bar', 'ter']; | ||
expect(intersect(undefined as unknown as [], b)).toEqual([]); | ||
}); | ||
|
||
it('returns an empty set if b is undefined', () => { | ||
const a = ['foo', 'bar', 'ter']; | ||
expect(intersect(a, undefined as unknown as [])).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters