Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
atomic-routes
Advanced tools
Decentralized nested client-side routing with Promises. Framework-agnostic, composable, simple: designed to work with component-based application UIs.
Decentralized nested client-side routing with Promises. Framework-agnostic, composable, simple: designed to work with component-based application UIs.
var rootNav = new RootRoute();
rootNav.when('/foo', function (fooNav) {
// create a container widget
console.log('entered "foo" state');
var rootDom = $('<div>Root View</div>').appendTo('body');
fooNav.whenDestroyed.then(function() {
// destroy the container widget
console.log('left "foo" state');
rootDom.remove();
});
fooNav.when('/bar', function (barNav) {
// create a sub-widget and attach to container
console.log('entered "foo/bar" state');
var fooDom = $('<div>FooBar View</div>').appendTo(rootDom);
barNav.whenDestroyed.then(function() {
// destroy the sub-widget
console.log('left "foo/bar" state');
fooDom.remove();
});
});
});
rootNav.when('/baz/:someParam', function (someParam, bazNav) {
console.log('entered "baz" state with "' + someParam + '"');
bazNav.whenDestroyed.then(function() {
console.log('left "baz" state with "' + someParam + '"');
});
});
Inspired by AngularJS UI Router nested routes concept and modern techniques like Promises that emphasize immutable, functional state.
Unlike AngularJS UI Router and most other routing libraries, Atomic Routes are defined on-demand and in a decentralized fashion. There is no need for a massive central "routes" file which has to run at bootstrap time.
Composition example:
// RootView.js: top-level "page" view
function RootView() {
var rootNav = new RootRoute();
var $dom = $('body');
rootNav.when('/fizz-buzz', function (fizzBuzzNav) {
var fizzBuzzView = new FizzBuzzView($dom, fizzBuzzNav);
});
}
// FizzBuzzView.js: sub-component in another file which expects delegated nav state
function FizzBuzzView($dom, nav) {
// ... render DOM, etc
// can create sub-routes without needing to know what the parent URL is
nav.when('/foo-bar', function (fooBarNav) {
// render more sub-route DOM, etc
});
}
Routes are defined via when
method. Each route body is executed when a navigation state is entered (immediately if it already matches current route). The navigation state can be used to define nested routes, and to track when the user leaves that navigation state. The library defines the "root" navigation state that is always active - that is the starting place where routes are registered.
To detect when a navigation state is no longer active, register a callback on the state object using the whenDestroyed.then
method. The whenDestroyed
property is a full-fledged promise object, so the callback will be called even when trying to register after the user left the navigation state. This is needed to easily clean up UI created as a result of an asynchronous operation: the operation may complete after the navigation state has become inactive, so attaching a simple event listener would miss out on the cleanup.
For more examples see /example/index.html
.
FAQs
Decentralized nested client-side routing with Promises. Framework-agnostic, composable, simple: designed to work with component-based application UIs.
The npm package atomic-routes receives a total of 0 weekly downloads. As such, atomic-routes popularity was classified as not popular.
We found that atomic-routes 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.