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-triple-ssp

v0.1.1

Published

ngx-triple-segmented-state-pattern

Downloads

13

Readme

ngx-triple-ssp

O ngx-triple-ssp é um pacote Angular que implementa o padrão Triple (State, Success, Error) para gerenciamento de estado de forma eficiente e reativa, facilitando a construção de interfaces de usuário dinâmicas e responsivas.

Características

  • Gerenciamento de Estado: Simplifica o gerenciamento de estados de carregamento, sucesso e erro em aplicações Angular.
  • Integração com RxJS: Utiliza observáveis para uma abordagem reativa ao estado da UI.
  • Facilidade de Uso: Projetado para ser facilmente integrado e utilizado em projetos Angular existentes.

Instalação

Para instalar o ngx-triple-ssp, execute o seguinte comando no seu terminal:

npm install ngx-triple-ssp

Uso

Após a instalação, você pode utilizar o TripleComponent para gerenciar estados em seus componentes Angular. Aqui está um exemplo básico de como utilizar:

import { Component, OnInit } from '@angular/core';
import { CounterService } from './_shared/counter.service';
import { NgxTripleSspComponent } from 'ngx-triple-ssp';

@Component({
  selector: 'app-counter',
  templateUrl: './counter.component.html',
  styleUrls: ['./counter.component.scss']
})
export class CounterComponent extends NgxTripleSspComponent<number> implements OnInit {
  constructor(private counterService: CounterService) {
    super(0);
  }

  async ngOnInit() {
    await this.loadData();
  }

  async loadData() {
    this.setError(null);
    this.setLoading(true);

    try {
      const data = await this.counterService.loadData();
      this.setData(data);
    } catch (error) {
      this.setError(error);
    } finally {
      this.setLoading(false);
    }
  }

  increment() {
    if (this.data !== null) {
      let data = this.data;
      data++;

      this.setData(data);
    }
  }

  decrement() {
    if (this.data !== null) {
      let data = this.data;
      data--;

      this.setData(data);
    }
  }

  protected override updateUI(): void {
    if (this.loading) {
      console.log('Loading...');
    } else if (this.error) {
      console.error('Error:', this.error);
    } else {
      console.log('Data:', this.data);
    }
  }
}

Template de Exemplo

Utilize o template a seguir para exibir os estados de carregamento, sucesso e erro:

<section class="align-center" *ngIf="!loading && !error">
  <div>
    <h2>Counter: {{ data }}</h2>

    <div>
      <button (click)="increment()">+</button>
      <button (click)="decrement()">-</button>
    </div>
  </div>
</section>

<section class="align-center" *ngIf="error">
  <div>
    <h5>Error: {{ error }}</h5>
  </div>
</section>

<section class="align-center" *ngIf="loading">
  <div>
    <h2>Loading...</h2>
  </div>
</section>

<section class="align-center">
  <br />
  <br />
  <button (click)="loadData()">Reload</button>
</section>

Exemplo completo no GitHub

Contribuições

Contribuições são bem-vindas! Se você quiser contribuir para o ngx-triple-ssp, por favor envie um pull request.

Licença

O pacote ngx-triple-ssp é licenciado sob a MIT License.