Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
@amadeus-it-group/tansu
Advanced tools
tansu is a lightweight, push-based state management library. It borrows the ideas and APIs originally designed and implemented by Svelte stores
tansu is a lightweight, push-based state management library. It borrows the ideas and APIs originally designed and implemented by Svelte stores.
Main characteristics:
Implementation wise, it is a tiny (500 LOC) library without any external dependencies.
Tansu is designed to be and to remain fully compatible with Svelte. Nevertheless, it brings several improvements:
async
pipe out of the box;Depending on multiple stores can lead to some issues. Let's have a look at the following example:
import {writable, derived} from 'svelte/store';
const firstName = writable('Arsène');
const lastName = writable('Lupin');
const fullName = derived([firstName, lastName], ([a, b]) => `${a} ${b}`);
fullName.subscribe((name) => console.log(name)); // logs any change to fullName
firstName.set('Sherlock');
lastName.set('Holmes');
console.log('Process end');
The output of this example will be:
Arsène Lupin
Sherlock Lupin
Sherlock Holmes
Process end
The fullName store successively went through different states, including an inconsistent one, as Sherlock Lupin
does not exist! Even if it can be seen as just an intermediate state, it is fundamental for a state management to only manage consistent data in order to prevent issues and optimize the code.
In Tansu, the batch function is available to defer synchronously (another important point) the derived calculation and solve all kind of multiple dependencies issues.
The previous example is resolved this way:
import {writable, derived, batch} from '@amadeus-it-group/tansu';
const firstName = writable('Arsène');
const lastName = writable('Lupin');
const fullName = derived([firstName, lastName], ([a, b]) => `${a} ${b}`);
fullName.subscribe((name) => console.log(name)); // logs any change to fullName
batch(() => {
firstName.set('Sherlock');
lastName.set('Holmes');
});
console.log('Process end');
With the following output:
Arsène Lupin
Sherlock Holmes
Process end
You can add tansu to your project by installing the @amadeus-it-group/tansu
package using your favorite package manager, ex.:
yarn add @amadeus-it-group/tansu
npm install @amadeus-it-group/tansu
Here is an example of an Angular component using a tansu store:
import { Component } from "@angular/core";
import { Store, derived } from "@amadeus-it-group/tansu";
// A store is a class extending Store from tansu
class CounterStore extends Store<number> {
constructor() {
super(0); // initialize store's value (state)
}
// implement state manipulation logic as regular methods
increment() {
// create new state based on the current state
this.update(value => value + 1);
}
reset() {
// replace the entire state with a new value
this.set(0);
}
}
@Component({
selector: "my-app",
template: `
<button (click)="counter$.increment()">+</button> <br />
<!-- store values can be displayed in a template with the standard async pipe -->
Counter: {{ counter$ | async }} <br />
Double counter: {{ doubleCounter$ | async }} <br />
`
})
export class AppComponent {
// A store can be instantiated directly or registered in the DI container
counter$ = new CounterStore();
// One can easily created derived (computed) values by specifying dependant stores and a transformation function
doubleCounter$ = derived(this.counter$, value => 2 * value);
}
While being fairly minimal, this example demonstrates most of the tansu APIs.
Check the documentation for the complete API and more usage examples.
Please check the DEVELOPER.md for documentation on building and testing the project on your local development machine.
FAQs
tansu is a lightweight, push-based framework-agnostic state management library. It borrows the ideas and APIs originally designed and implemented by Svelte stores and extends them with computed and batch.
The npm package @amadeus-it-group/tansu receives a total of 707 weekly downloads. As such, @amadeus-it-group/tansu popularity was classified as not popular.
We found that @amadeus-it-group/tansu demonstrated a healthy version release cadence and project activity because the last version was released less than 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
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.