You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flagon.apache.org by GitBox <gi...@apache.org> on 2022/11/02 17:21:31 UTC

[GitHub] [incubator-flagon-useralejs] Jyyjy commented on issue #266: Provide a means for users to easily log HTML elements data attributes

Jyyjy commented on issue #266:
URL: https://github.com/apache/incubator-flagon-useralejs/issues/266#issuecomment-1300964306

   I am working with @poorejc on adding this feature. I started with @EandrewJones buildDatasets() function. I tested it, it worked, and then there was a discussion on what information we actually want in the log messages. Right now this is where we are at:
   
   - We want all attributes, not just dataset attributes.
   - We only want attributes of the event target.
   - We want to parse JSON values
   
   I wanted to share this code snippet that does the above, and see what others think should be included in a log.
   
   `
   /**
    * Builds an object containing all attributes of an element.
    * Attempts to parse all attribute values as JSON text.
    * @param  {Object} e Event from which the attributes should be extracted from.
    * @return {Object} Object with all element attributes as key value pairs.
    */
    export function buildAttrs(e) {
     let attributes = {};
     if(e.target && e.target instanceof Element) {
       let i = 0;
       let attrs = e.target.attributes;
       while(i < attrs.length) {
         let val = attrs[i].value;
         try {
           val = JSON.parse(val);
         } catch (error) {}
         attributes[attrs[i].name] = val;
         i++;
       }
     }
     return attributes;
   }
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@flagon.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org