
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
add-named-elements-to-object
Advanced tools
So, I was using Riot.js for a while and my favorite feature was that any 'named' elements within your view would be accessible on the view scope by name. This eliminated ALL DOM traversal in my project. As any element that I needed a handle on for any re
So, I was using Riot.js for a while and my favorite feature was that any 'named' elements within your view would be accessible on the view scope by name. This eliminated ALL DOM traversal in my project. As any element that I needed a handle on for any reason, I could just name the element then it would be available to me by reference.
For example, if you had this in your template for a view:
<div name='ramaSlamaDingDong'> ... really important stuff </div>
Because you used the 'name' attribute, this element is now automatically accessible in your view as this.ramaSlamaDingDong
. No dom traversal necessary.
I loved this feature, and wanted to use it on other projects. So. I wrote this one.
This lib exports a single method that takes 2 arguments: the object you want to add the named elements to, and the root DOM node you want to traverse.
Something Like:
var addNamedElementsToObject = require('add-named-elements-to-object');
// After your view template is available, but Ideally before you put it in the DOM because we will be recursing it. Though, it will work fine if the document fragment is already in the DOM.
addNamedElementsToObject(this.elements, this.rootTemplate);
// Any named elements in the rootTemplate will be available by reference on this.elements;
So you want a handle on a bunch of elements, like a list of grid items, and you want to manipulate them all. This lib will stack them into a normal array accessible by name. (not a NODE LIST, so all array methods are available.)
For example,
<ul>
<li name='listItem'></li>
<li name='listItem'></li>
<li name='listItem'></li>
<li name='listItem'></li>
<li name='listItem'></li>
<li name='listItem'></li>
<li name='listItem'></li>
</ul>
Then in your view,
this.listItem.forEach(function() {});
// or
this.listItem.map(); // ...etc etc
FAQs
So, I was using Riot.js for a while and my favorite feature was that any 'named' elements within your view would be accessible on the view scope by name. This eliminated ALL DOM traversal in my project. As any element that I needed a handle on for any re
We found that add-named-elements-to-object demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.