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

@tomtomb/ngrx-toolkit

v3.4.1

Published

A bundle containing NgRx Helper classes and functions to simplify the coding experience

Downloads

1,632

Readme

NgRx Toolkit

A bundle containing NgRx Helper classes and functions to simplify the coding experience

NPM version License Conventional Commits Open in Visual Studio Code

Installation

Requires Angular 12.1+ with Ivy enabled and TypeScript 4.3+

npm install @ngrx/{store,effects,entity} @tomtomb/ngrx-toolkit
# or
yarn add @ngrx/{store,effects,entity} @tomtomb/ngrx-toolkit

You probably want to install the store devtools as well

npm install -D @ngrx/store-devtools
# or
yarn add -D @ngrx/store-devtools

Getting started

For a full example have a look at the sandbox application. The toolkit can easily be integrated into an existing NgRx store.

API

These docs are based on version prior to 2.x. The new version included many breaking changes, so please refer to the sandbox app for now!

createActionGroup<Arguments, ResponseData, ErrorResponse>({method, name, scope, isUnique})

Creates an action group containing a call, success and failure action.

Generics

| Generic | Extends | Description | Default | | ------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------ | --------- | | Arguments | ArgumentsBase / null | Arguments needed to perform the action | | | ResponseData | | The response if the call was successfully performed | | | ErrorResponse | | Additional error data returned by the HttpErrorResponse error property | unknown |

IMPORTANT: The structure of the Arguments type must be based on the ArgumentsBase type.

export interface ArgumentsBase {
  queryParams?: Record<string | number, unknown>;
  params?: Record<string | number, unknown>;
  body?: unknown;
  sideUpdates?: Record<string, ArgumentsBase>;
}

Arguments

| Argument | Type | Description | Default | | -------- | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | | method | 'GET' / 'POST' / 'PUT' / 'PATCH' / 'DELETE' | HTTP verb of the action | | | name | string | The actions name | | | scope | string | The actions scope | | | isUnique | boolean / undefined | By default all action calls will be stored inside the store. If true, only one action call will be stored. This is useful for things like login actions | false |

Returns

TypedActionObject<Arguments, ResponseData, ErrorResponse>

Example

export const getFoo = createActionGroup<
  { queryParams: { id: string } }, // This object must follow the ArgumentsBase type
  { value: boolean },
  { additionalErrorData: string }
>({
  method: 'GET',
  name: 'Foo',
  scope: 'Sandbox',
});

View the sandbox code


createStoreSlice({actions})

Creates an reducer based on provided TypedActionObjects.

WIP

View the sandbox code


createEntitySelectors({getState, storeSlice})

Creates selector functions to be used by FacadeBase

WIP

View the sandbox code


EffectBase (class)

A abstract class for handling ngrx effects with ActionGroups

constructor(actions, featureService)

Arguments

| Argument | Type | Description | Default | | -------------- | --------- | ------------------------------------------------------------------ | ------- | | actions | Actions | The NgRx Actions Observable | | | featureService | class | The class where the actual http calls are located | |

onActionSwitchMap(action, serviceCall, sideUpdates)

onActionMergeMap(action, serviceCall, sideUpdates)

onActionExhaustMap(action, serviceCall, sideUpdates)

onActionConcatMap(action, serviceCall, sideUpdates)

These methods are all doing the same except for the used observable flattening operator.

RxJS Docs: switchMap, mergeMap, exhaustMap, concatMap

Generics

Generics should NOT be provided by the user. They are filled automatically.

Arguments

| Argument | Type | Description | Default | | ----------- | -------------------- | -------------------------------------------------------------------------------------------------------------- | --------- | | action | TypedActionObject | The action group created via createActionGroup() | | | serviceCall | method | A reference to the actual http call | | | sideUpdates | object / undefined | Additional user defined side effects. These actions will be called after the parent success action gets called | undefined |

Example

@Injectable()
export class SandboxEffects extends EffectBase {
  getFoo$ = this.onActionSwitchMap({
    action: SandboxActions.getFoo,
    serviceCall: this.featureService.getFoo,
  });

  constructor(
    private actions$: Actions,
    private featureService: SandboxService
  ) {
    super(actions$, featureService);
  }
}

View the sandbox code


FacadeBase (class)

A abstract class for dispatching actions and retrieving data from the store

WIP

View the sandbox code


ServiceBase (class)

A abstract class for making http calls with caching built-in

WIP

View the sandbox code