-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2200ab5
commit 885b5c2
Showing
2 changed files
with
45 additions
and
11 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
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,30 @@ | ||
// Example to demonstrate the advantages of a descritpve approach | ||
|
||
// Loop all entities | ||
queryScope(document.body, "[data-elb]", function (entity) { | ||
console.log(`------`); | ||
const entityName = entity.getAttribute("data-elb"); | ||
|
||
// Loop all acctions | ||
queryScope(entity, "[data-elbaction]", function (action) { | ||
const actionName = action.getAttribute("data-elbaction"); | ||
console.log("event", entityName, actionName); | ||
}); | ||
|
||
// Get all properties | ||
const properties = []; | ||
const propertyAttr = `data-elb-${entityName}`; | ||
queryScope(entity, `[${propertyAttr}]`, function (prop) { | ||
properties.push(prop.getAttribute(propertyAttr)); | ||
}); | ||
console.log("properties", properties); | ||
}); | ||
|
||
// Ugly helper functions, please just ignore it and look above | ||
function queryScope(scope, selector, func) { | ||
[scope, ...scope.querySelectorAll(selector)] | ||
.filter((el) => el.matches(selector)) | ||
.map((elem) => { | ||
func.call(scope, elem); | ||
}); | ||
} |