# @a15-ghm/gh-ngrx-elements

> This Angular library contains sharable NgRx elements such as selectors, actions, and related functions. It allows to reuse these elements without duplication code in another Angular libraries or Angular applications.

Latest version **1.0.0** (published 2023-11-21) · 0 weekly downloads

## Install

```sh
npm install @a15-ghm/gh-ngrx-elements
pnpm add @a15-ghm/gh-ngrx-elements
yarn add @a15-ghm/gh-ngrx-elements
bun add @a15-ghm/gh-ngrx-elements
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-11-21 |
| First published | 2023-11-21 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 18.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | devops-ghm-npm, danni.liu, s.bely, kiskina_victoria, sergey.kuzovlev, s.bozhik, brian.park |

## Links

- npm: https://www.npmjs.com/package/@a15-ghm/gh-ngrx-elements
- npm.io page: https://npm.io/package/@a15-ghm/gh-ngrx-elements

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0

## Recent versions

- 1.0.0 (latest) — 2023-11-21

## README

# gh-ngrx-elements

This Angular library contains sharable NgRx elements such as selectors, actions, and related functions. It allows to reuse these elements without duplication code in another Angular libraries or Angular applications.

## Sharable selectors

1. `cartSubtotalBeforeDiscountSelector`
   The selector returns product prices in the cart before discounts, tax and shipping calculation, only the total price of all products and variants. For calculation `state.ghCartState.cart.products` and `state.ghCartState.cart.variants` are used.

## Sharable utils

1.  `calculateCartSubtotal`
    The function returns the subtotal price of incoming products and variants.

```ts
calculateCartSubtotal(products: Products, variants: Products): number;
```

2. `getRoundedTotal`
   The function returns a rounded price with a maximum of two decimal places.

```ts
getRoundedTotal(total: number): number;
```

## Usage

To use these sharable elements follow these steps:

### Installation

Install the `gh-ngrx-elements` library by running the following command

```bash
npm install --save @a15-ghm/gh-ngrx-elements
```

### Importing and usage selectors

Import the selector to where you need it and use it

```ts
import { Component, OnInit, inject } from '@angular/core';
import { Store } from '@ngrx/store';

import { IStore } from '@a15-ghm/gh-models/interfaces/store';
import { cartSubtotalBeforeDiscountSelector } from '@a15-ghm/gh-ngrx-elements';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent implements OnInit {
  cartSubtotal: number;

  private store: Store<IStore> = inject(Store);

  ngOnInit() {
    this.store.select(cartSubtotalBeforeDiscountSelector).subscribe((subtotal) => {
      this.cartSubtotal = subtotal;
    });
  }
}
```

### Improting and usage utilities

Import the utility to where you need it and use it

```ts
import { Component } from '@angular/core';

import { calculateCartSubtotal, getRoundedTotal } from '@a15-ghm/gh-ngrx-elements';
import { Product } from '@a15-ghm/gh-models/types/product';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  products: Product;
  variants: Product;

  calculateSubtotal(): number {
    const subtotal = calculateCartSubtotal(this.products, this.variants);

    return getRoundedTotal(subtotal);
  }
}
```

---
_Source: https://npm.io/package/@a15-ghm/gh-ngrx-elements · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
