Skip to content

Commit

Permalink
prefere explicit over generic
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed May 26, 2023
1 parent 5345104 commit fced79d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/html/walker.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@
<p data-elb-generic="k:v"></p>
<p data-elb-*="g:v"></p>
<p data-elb-generic="o:v"></p>
<!-- <p data-elb-*="o:x"></p> -->
<p data-elb-*="o:x"></p>
</div>
</div>
2 changes: 1 addition & 1 deletion src/__tests__/walker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('Walker', () => {
);
});

test.only('Generic properties', () => {
test('Generic properties', () => {
expect(getEvents(getElem('generic'), Walker.Trigger.Click)).toMatchObject([
{
entity: 'generic',
Expand Down
11 changes: 8 additions & 3 deletions src/lib/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,25 @@ function getEntity(
)}],[${getElbAttributeName(prefix, '\\*')}]`;

// Get matching properties from the element and its parents
let [data, context] = getThisAndParentProperties(
let [parentProps, context] = getThisAndParentProperties(
origin || element,
entitySelector,
prefix,
type,
);

// Get properties
let data: Walker.Properties = {};
let genericProps: Walker.Properties = {};
element.querySelectorAll<HTMLElement>(entitySelector).forEach((child) => {
// Eventually override closer peroperties
data = assign(data, getElbValues(prefix, child, '*')); // Generic
data = assign(data, getElbValues(prefix, child, type)); // Explicit
genericProps = assign(genericProps, getElbValues(prefix, child, '*'));
data = assign(data, getElbValues(prefix, child, type));
});

// Merge properties with the hirarchy data > generic > parent
data = assign(parentProps, assign(genericProps, data));

// Get nested entities
const nested: Walker.Entities = [];
element
Expand Down

0 comments on commit fced79d

Please sign in to comment.