Socket
Socket
Sign inDemoInstall

@ngxs-labs/dispatch-decorator

Package Overview
Dependencies
5
Maintainers
8
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.2 to 5.0.0

esm2020/lib/internals/unwrap.mjs

31

package.json
{
"$schema": "../node_modules/ng-packagr/package.schema.json",
"name": "@ngxs-labs/dispatch-decorator",
"version": "4.0.2",
"version": "5.0.0",
"repository": {

@@ -19,14 +18,14 @@ "type": "git",

],
"sideEffects": true,
"sideEffects": false,
"peerDependencies": {
"@angular/core": ">=13.0.0",
"@angular/core": ">=15.0.0",
"@ngxs/store": ">=3.7.2",
"rxjs": ">=6.1.0"
},
"module": "fesm2015/ngxs-labs-dispatch.mjs",
"es2020": "fesm2020/ngxs-labs-dispatch.mjs",
"esm2020": "esm2020/ngxs-labs-dispatch.mjs",
"fesm2020": "fesm2020/ngxs-labs-dispatch.mjs",
"fesm2015": "fesm2015/ngxs-labs-dispatch.mjs",
"typings": "ngxs-labs-dispatch.d.ts",
"module": "fesm2015/ngxs-labs-dispatch-decorator.mjs",
"es2020": "fesm2020/ngxs-labs-dispatch-decorator.mjs",
"esm2020": "esm2020/ngxs-labs-dispatch-decorator.mjs",
"fesm2020": "fesm2020/ngxs-labs-dispatch-decorator.mjs",
"fesm2015": "fesm2015/ngxs-labs-dispatch-decorator.mjs",
"typings": "index.d.ts",
"exports": {

@@ -37,8 +36,8 @@ "./package.json": {

".": {
"types": "./ngxs-labs-dispatch.d.ts",
"esm2020": "./esm2020/ngxs-labs-dispatch.mjs",
"es2020": "./fesm2020/ngxs-labs-dispatch.mjs",
"es2015": "./fesm2015/ngxs-labs-dispatch.mjs",
"node": "./fesm2015/ngxs-labs-dispatch.mjs",
"default": "./fesm2020/ngxs-labs-dispatch.mjs"
"types": "./index.d.ts",
"esm2020": "./esm2020/ngxs-labs-dispatch-decorator.mjs",
"es2020": "./fesm2020/ngxs-labs-dispatch-decorator.mjs",
"es2015": "./fesm2015/ngxs-labs-dispatch-decorator.mjs",
"node": "./fesm2015/ngxs-labs-dispatch-decorator.mjs",
"default": "./fesm2020/ngxs-labs-dispatch-decorator.mjs"
}

@@ -45,0 +44,0 @@ },

@@ -12,4 +12,33 @@ <p align="center">

This package simplifies the dispatching process. It would be best if you didn't care about `Store` service injection as we provide a more declarative way to dispatch events out of the box.
This package simplifies the dispatching process. It would be best if you didn't care about the `Store` service injection, as we provide a more declarative way to dispatch events out of the box.
## Compatibility with Angular Versions
<table>
<thead>
<tr>
<th>@ngxs-labs/dispatch-decorator</th>
<th>Angular</th>
</tr>
</thead>
<tbody>
<tr>
<td>
4.x
</td>
<td>
>= 13 < 15
</td>
</tr>
<tr>
<td>
5.x
</td>
<td>
>= 15
</td>
</tr>
</tbody>
</table>
## 📦 Install

@@ -19,4 +48,8 @@

```console
yarn add @ngxs-labs/dispatch-decorator
```sh
$ npm install @ngxs-labs/dispatch-decorator
# Or if you're using yarn
$ yarn add @ngxs-labs/dispatch-decorator
# Or if you're using pnpm
$ pnpm install @ngxs-labs/dispatch-decorator
```

@@ -28,3 +61,3 @@

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

@@ -42,5 +75,5 @@ import { NgxsModule } from '@ngxs/store';

`@Dispatch()` is a function that allows you to decorate the methods and properties of your classes. Firstly let's create our state for demonstrating purposes:
`@Dispatch()` can be used to decorate methods and properties of your classes. Firstly let's create our state for demonstrating purposes:
```typescript
```ts
import { State, Action, StateContext } from '@ngxs/store';

@@ -75,3 +108,3 @@

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

@@ -105,7 +138,7 @@ import { Select } from '@ngxs/store';

As you may mention, we don't have to inject the `Store` class to dispatch those actions. The `@Dispatch` decorator does it for you underneath. It gets the result of the function call and invokes `store.dispatch(...)` under the hood.
You may mention that we don't have to inject the `Store` class to dispatch actions. The `@Dispatch` decorator takes care of delivering actions internally. It unwraps the result of function calls and calls `store.dispatch(...)`.
Dispatchers can also be asynchronous. They can return either `Promise` or `Observable`. Asynchronous operations are handled outside of Angular's zone; thus it doesn't affect performance:
Dispatch function can be both synchronous and asynchronous, meaning that the `@Dispatch` decorator can unwrap `Promise` and `Observable`. Dispatch functions are called outside of the Angular zone, which means asynchronous tasks won't notify Angular about change detection forced to be run:
```typescript
```ts
export class AppComponent {

@@ -132,9 +165,9 @@ // `ApiService` is defined somewhere

Notice that it doesn't matter if you use an arrow function or a regular class method.
Note it doesn't if an arrow function or a regular class method is used.
### Dispatching Multiple Actions
Dispatchers can return arrays. NGXS will handle actions synchronously if their action handlers do a synchronous job and vice versa if their handlers are asynchronous.
`@Dispatch` function can return arrays of actions:
```typescript
```ts
export class AppComponent {

@@ -150,3 +183,3 @@ @Dispatch() setLanguageAndNavigateHome = (language: string) => [

If you have an async dispatcher, you may want to cancel a previous `Observable` if the dispatcher has been invoked again. This is useful for cancelling previous requests like in a typeahead. Given the following example:
`@Dispatch` functions can cancel currently running actions if they're called again in the middle of running actions. This is useful for canceling previous requests like in a typeahead. Given the following example:

@@ -163,3 +196,3 @@ ```ts

If we want to cancel previously uncompleted `getNovels` request, then we need to provide the `cancelUncompleted` option:
We have to provide the `cancelUncompleted` option if we'd want to cancel previously uncompleted `getNovels` action:

@@ -166,0 +199,0 @@ ```ts

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc