
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
There are many ways to add Reval into your project.
The easiest option is to pull it from a CDN:
<script src="https://unpkg.com/revaljs"></script>
Or for better load time, consider downloading the library from our releases page.
And then get the necessary functions:
const { el, mount, unmount, setState } = Reval;
You can also just install it through npm
:
npm i revaljs
And then get the required functions like this:
const { el, mount, unmount, setState } = require("revaljs");
There is a handy dandy function called el
to create HTML elements:
Syntax: el(tagName, props, childNodes)
Example:
const hello = el("p", { id: "Hello" }, [
"Hello, World!", // You can use normal text
el("br")
]);
HTML equivalent:
<p id="Hello">
Hello, World!
<br/>
</p>
Note that in props
, you can also assign event handlers, for example:
const hello = el("p", { id: "Hello": onclick: () => alert("You clicked me!") }, el("br"));
You can mount an HTML element or a Reval component to another HTML element (container):
mount(document.body, hello);
It will mount hello
to document.body
, so you will see Hello, World!
rendered on the browser.
You can also unmount that element:
unmount(document.body, hello);
You can mount the element before a specified element:
mount(parent, child, before);
To re-render an element, pass in true
as the fourth argument.
mount(parent, child, before, true);
Reval components all have a basic form like this:
class ComponentName {
// this.render() returns an HTML element
render() {
return /* code goes here */;
}
}
const componentName = new ComponentName();
// mount the component
mount(parent, componentName);
// unmount the component
unmount(parent, componentName);
You can manage components' state using the state
prop:
this.state = {}
and change the state with setState
:
setState(component, { state: value });
The HTML element got re-rendered every time state is changed.
Be careful when you pass in handlers for events, because if you use arrow functions, the scope will be inside the component's class, but if you use normal functions, the scope will be the HTML element itself with this
pointed to the element.
There are three lifecycle events in a Reval's component - onmount
- when the component is mounted to a container, onunmount
- when the component is unmounted from a container, and onremount
- when a component is remounted to a different container.
You can pass in handlers for each events as methods of the component's class:
onmount() {
// Gets triggered when component is mounted
}
onunmount() {
// Gets triggered when component is unmounted
}
onremount() {
// Gets triggered when component is remounted to another
// parent or to the same parent with a different position
}
Basically, we will create a Counter
component, set the counter
state to 1
. render()
should return an HTML element with a list of child nodes consists of the current value of the counter, a button for incrementing the counter, a button for decrementing the counter. We will use setState
to change the value of counter
and re-render the element. Finally, we will create an instance of Counter
called counter
and mount it to document.body
.
class Counter {
constructor() {
this.state = {
counter: 1
};
}
render() {
return el("h1", {}, [
this.state.counter,
el("br"),
el("button", {
onclick: () => setState(this, { counter: this.state.counter + 1 })
}, "Increment"),
el("button", {
onclick: () => setState(this, { counter: this.state.counter - 1 })
}, "Decrement")
]);
}
}
const counter = new Counter();
mount(document.body, counter);
You can just use the ternary operator to do conditional rendering:
render() {
return 1 === 1 ? el("p", {}, "I'm fine") : el("p", {}, "I'm crazy");
}
Rendering a list of elements can be done easily with map
and the spread operator.
render() {
return el("ul", {}, [
...[1, 2, 3].map(item => el("li", {}, item))
]);
}
This would generate:
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
FAQs
React-based front-end library code golf
The npm package revaljs receives a total of 23 weekly downloads. As such, revaljs popularity was classified as not popular.
We found that revaljs demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.