Skip to content

Commit 47db21a

Browse files
committed
fix: export
1 parent 60e1599 commit 47db21a

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

src/getAttribute.js

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
import { processOperators } from "./utility";
1+
import { processOperators } from "./operators";
22

33
// Store a reference to the original getAttribute function
44
const originalGetAttribute = Element.prototype.getAttribute;
5+
6+
// Map to store attribute details
57
const attributes = new Map();
68

9+
// Add an event listener for storage events to update attributes
710
window.addEventListener("storage", updateAttributes);
11+
// Custom event to update attributes
812
window.addEventListener("updateAttributes", function (e) {
913
updateAttributes(e.detail);
1014
});
1115

16+
/**
17+
* Function to update attributes based on specific storage keys
18+
* @param {Object} e - The event object containing key and newValue
19+
*/
1220
function updateAttributes(e) {
1321
const keys = ["organization_id", "user_id", "clientId", "session_id"];
1422
if (keys.includes(e.key)) {
@@ -19,8 +27,24 @@ function updateAttributes(e) {
1927
}
2028
}
2129

22-
// Override the getAttribute function
30+
/**
31+
* Custom getAttribute function that processes the attribute value
32+
* @param {Element} element - The element from which to get the attribute
33+
* @param {string} name - The attribute name
34+
* @returns {string} - The processed attribute value
35+
*/
36+
function getAttribute(element, name) {
37+
if (!(element instanceof Element)) {
38+
throw new Error("First argument must be an Element");
39+
}
40+
let value = originalGetAttribute.call(element, name);
41+
return processOperators(element, value);
42+
}
43+
44+
// Override the getAttribute method on Element prototype
2345
Element.prototype.getAttribute = function (name) {
24-
let value = originalGetAttribute.call(this, name);
25-
return processOperators(this, value);
46+
return getAttribute(this, name); // Use the custom getAttribute function
2647
};
48+
49+
// Export the custom getAttribute function
50+
export { getAttribute };

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { getAttribute } from "./getAttribute";
2424
import { setValue } from "./setValue";
2525
import { getValue } from "./getValue";
2626
import { queryElements } from "./queryElements";
27-
import { processOperators } from "./utility";
27+
import { processOperators } from "./operators";
2828

2929
export default {
3030
getAttribute,

src/queryElements.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
import utils from "@cocreate/utils";
22

3-
Element.prototype.queryElements = function (options = {}) {
3+
/**
4+
* Custom method to query elements in the context of a specific DOM element.
5+
*
6+
* @param {Object} options - Options to customize the query.
7+
* @returns {NodeListOf<Element>} - A list of elements found based on the query criteria.
8+
*/
9+
function queryElements(options = {}) {
10+
// Use `this` as the element context and pass additional options to utils.queryElements
411
return utils.queryElements({ element: this, ...options });
5-
};
12+
}
13+
14+
// Attach the method to Element's prototype to allow its use as an instance method
15+
Element.prototype.queryElements = queryElements;
16+
17+
// Export the function for direct use in other parts of your application
18+
export { queryElements };

0 commit comments

Comments
 (0)