npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-tansu

v0.0.1-alpha

Published

ngx-tansu is a lightweight, push-based state management library for Angular. It borrows the ideas and APIs originally designed and implemented by Svelte stores

Downloads

3

Readme

build

ngx-tansu

ngx-tansu is a lightweight, push-based state management library for Angular. It borrows the ideas and APIs originally designed and implemented by Svelte stores.

Main characteristics:

  • small conceptual surface with expressive and very flexible API (functional and class-based);
  • can be used to create "local" (module-level or component-level), collaborating stores;
  • can handle both immutable and mutable data;
  • results in compact code with the absolute minimum of boilerplate.

ngx-tansu is tightly integrated with the Angular ecosystem:

  • works with the standard async pipe out of the box;
  • stores can be registered in the DI container at any level (module or component injector).

Implementation wise, it is a tiny (500 LOC) library without any external dependencies.

Installation

You can add ngx-tansu to your project by installing the ngx-tansu package using your favorite package manager, ex.:

  • yarn add ngx-tansu
  • npm install ngx-tansu

Usage

Here is an example of a component using a ngx-tansu store:

import { Component } from "@angular/core";
import { Store, derived } from "ngx-tansu";

// A store is a class extending Store from ngx-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 ngx-tansu APIs.

Check the documentation for the complete API and more usage examples.

Contributing to the project

Please check the DEVELOPER.md for documentation on building and testing the project on your local development machine.

Credits and the prior art

  • Svelte gets all the credit for the initial idea and the API design.
  • NgRx component stores solve a similar problem with a different approach.