Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@iconstorm/lol-element
Advanced tools
A base class for creating Web Components like you know what you're doing
A JavaScript base class for creating Web Components like you know what you're doing.
With npm (or similar):
npm install @iconstorm/lol-element
Via CDN, you can use a script tag:
<script src="https://unpkg.com/@iconstorm/lol-element"></script>
<script>
const { LOL, css, html } = lol // global window.lol is made available
</script>
or hotlink in your ES modules:
import { LOL, css, html } from 'https://unpkg.com/@iconstorm/lol-element?module'
Please go read the chapter dedicated to them on the great javascript.info site. Once you're familiar with custom elements in general, you'll be enjoying LOL within minutes.
Also the Classes chapter is a recommended read.
No build step or transpiling is necessary. All of this just works in the browser.
Define a component:
import { LOL, html, css } from 'https://unpkg.com/@iconstorm/lol-element'
class HelloWorld extends LOL {
static get attributes () {
return { name: 'with-exclamation-mark', boolean: true }
}
static get styles () {
return css`
span { font-size: 300%; }
`
}
template () {
return html`
<span>Hello World${this.withExclamationMark ? '!' : ''}</span>
`
}
}
customElements.define('lol-hello-world', HelloWorld)
Use it in your markup:
<lol-hello-world with-exclamation-mark></lol-hello-world>
LOL
classshadowOptions
static (getter or property)Define the Shadow DOM options being passed to the attachShadow()
call.
Defaults to { mode: 'open' }
. Use null
to not use Shadow DOM.
attributes
static (getter or property)Define the element's attributes to be observed with an array of names or config objects, with following keys:
name
string: The name of the attributereflect
boolean (default: true
): Whether the attribute should be reflected in a propertyboolean
boolean (default: false
): Whether the attribute is a boolean type of attributeread
function (default: x => x
): A function to process the property value being accessedwrite
function (default: x => x
): A function to process the value being set in the attributefallbackValue
: The value returned by the property getter when the attribute is missingExcept for name
, all options are optional.
An attribute being reflected means that for a given foo-bar
attribute, a fooBar
getter/setter property will be created. So assigning a value to fooBar
will set the same value to the foo-bar
attribute. LOL
has no observable/reactivity system, for simplicity's sake, it leverages the browser's via attributeChangedCallback
.
Attributes live in HTML, properties belong in JavaScript objects. If the different is not clear, stack overflow is your friend. This can create some confusion. This post by Rich Harris can be interesting (scroll down to part 6).
styles
static (getter or property)Define the styles for the component with CSS. The css``
template literal tag must be used.
import { css } from '@iconstorm/lol-element'
// ..
static get styles() {
return css`
:host {
font-size: 100%;
}
`
}
template()
methodDefine the markup of the component, the html``
template literal tag must be used.
Parameters:
host
object: The element instance🔥 This method is usually called render()
in many libraries and frameworks.
import { html } from '@iconstorm/lol-element'
// ..
template() {
return html`
<p>Loren ipsum</p>
`
}
changed()
methodFires every time an attribute is added, removed, or changed. This is only an alias for attributeChangedCallback
for the convenience of avoiding super.attributeChangedCallback()
.
Parameters:
name
string: The name of the attribute the changedoldValue
stringnewValue
string{propertyName}Changed()
methodAn individual callback for every observed attribute, when implemented. For example, every time the foo-bar
attribute changes, if there's a fooBarChanged()
method defined, it will be called.
Parameters:
oldValue
stringnewValue
stringemit()
methodA helper to dispatch custom events from within the element.
Parameters:
eventName
string: The name of the eventdetail
any: The thing being emitted, available in event.detail
options
object: any other options for the event, defaults to { bubbles: true, cancelable: true }
render()
methodCall this method to trigger a DOM update. You shouldn't need to implement this method.
renderRoot
propertyThe DOM node where rendering happens. This is either the element's shadowRoot
(when using Shadow DOM) or the host element itself (when not).
Apart from changed()
and {propertyName}Changed()
, no other lifecycle callbacks are provided other than the ones offered by default in HTMLElement:
constructor()
connectedCallback()
attributeChangedCallback()
disconnectedCallback()
See Using the lifecycle callbacks in MDN.
If you don't call super
on constructor
, connectedCallback
and attributeChangedCallback
, things will break.
class MyComponent extends LOL {
constructor() {
super()
// ..
}
connectedCallback() {
super.connectedCallback()
// ..
}
attributeChangedCallback() {
super.attributeChangedCallback()
// ..
}
}
More info: https://javascript.info/class-inheritance#overriding-a-method
See µhtml for now.
LOL
- extends LOLElement
,LOLElement
- extends HTMLELement
, render()
is not implementedcss
html
*svg
*import { LOL, LOLElement, css, html, svg } from '@iconstorm/lol-element'
*implementation may vary depending on flavor (more on this soon).
MIT
FAQs
A base class for creating Web Components like you know what you're doing
The npm package @iconstorm/lol-element receives a total of 1 weekly downloads. As such, @iconstorm/lol-element popularity was classified as not popular.
We found that @iconstorm/lol-element demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.