Skip to content

Commit

Permalink
chore: add zoneless SSR part
Browse files Browse the repository at this point in the history
  • Loading branch information
arturovt committed Jul 11, 2024
1 parent 6641c3c commit 12f1131
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
20 changes: 10 additions & 10 deletions docs/concepts/store/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
It is recommended to handle errors within your `@Action` function in your state:

### Deterministice errors:
- `Update the state` to capture the error details
- Ensure that the relevant selectors cater for these error states and provide information for your user to respond to the error accordingly
- OR `dispatch` an action that sends the error details to the necessary state or service
- This action could be picked up by an application level error state or could be picked up by a service that is listening to the action stream (see [Action Handlers](../actions/action-handlers.md))

- `Update the state` to capture the error details
- Ensure that the relevant selectors cater for these error states and provide information for your user to respond to the error accordingly
- OR `dispatch` an action that sends the error details to the necessary state or service
- This action could be picked up by an application level error state or could be picked up by a service that is listening to the action stream (see [Action Handlers](../actions/action-handlers.md))

### Non-deterministic errors:
- Respond to the error accordingly(retry, abort, etc.)
- AND use one of the deterministic error handling mechanisms above to inform your user about the situation

- Respond to the error accordingly(retry, abort, etc.)
- AND use one of the deterministic error handling mechanisms above to inform your user about the situation

## Fallback Error Handling

Expand All @@ -26,6 +27,7 @@ Error handling firstly falls back to any error handler at the `dispatch` call an
To manually catch an error thrown and not handled by an action, you can subscribe to the observable returned by the `dispatch` call and include an `error` callback. By subscribing and providing an `error` callback, NGXS won't pass the error to its final unhandled error handler.

You can include this error callback in three ways:

- by explicitly supplying the `error` callback in your `subscribe` function call
- by using one of the `rjxs` error handling operators
- by converting the observable into a promise and using any standard `async` or `promise` error handling mechanisms
Expand Down Expand Up @@ -60,9 +62,7 @@ class AppComponent {

async handleErrorAsync() {
try {
await latestValueFrom(
this.store.dispatch(new ActionThatCausesAnError())
);
await latestValueFrom(this.store.dispatch(new ActionThatCausesAnError()));
} catch (error) {
console.log('unhandled error on dispatch caught: ', error);
}
Expand Down Expand Up @@ -125,4 +125,4 @@ config.onUnhandledError = function (error: any) {
existingHandler.call(this, error);
}
};
```
```
30 changes: 23 additions & 7 deletions publication/2024-06-10_announcing_ngxs_18/article.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ We're thrilled to announce the release of NGXS v18! This update represents month

But that's not all – we've also made a strategic decision to align NGXS versioning with Angular's release cycle. This means, starting with v18, the minimum supported Angular version will also align with Angular's latest release, unless explicitly stated otherwise.

Angular has entered a new era, where the incremental introduction of new features and api changes offer a host of opportunities for libraries. This move by NGXS ensures seamless compatibility and allows you to leverage the latest features from both libraries as they evolve together.
Angular has entered a new era, where the incremental introduction of new features and API changes offer a host of opportunities for libraries. This move by NGXS ensures seamless compatibility and allows you to leverage the latest features from both libraries as they evolve together.
For NGXS v18, since this is our first release under the new versioning scheme, we will be supporting Angular versions >=16.

But before we dive in, we want to unveil a fresh new look for NGXS!
Expand All @@ -30,28 +30,28 @@ We've got some exciting news in this release beyond the usual code wizardry. We'

Head over to our brand new Discord server at https://discord.gg/yFk6bu7v. Don't forget to introduce yourself and let us know what awesome NGXS projects you're working on!

The move from Slack to Discord will be incremental, as we encourage our many Slack users to move over. There is a wealth of valuable community discussions in our Slack archives (6 years of data). This is unfortunately inaccessible due to Slack's 90-day policy. We plan to make this archive available in dedicated discord channels in the near future.
---
## The move from Slack to Discord will be incremental, as we encourage our many Slack users to move over. There is a wealth of valuable community discussions in our Slack archives (6 years of data). This is unfortunately inaccessible due to Slack's 90-day policy. We plan to make this archive available in dedicated discord channels in the near future.

Now, let's get down to business!

## Overview

Part 1

- 🚦 Signals
- ⏩ Dispatch Utilities
Part 2
Part 2
- 🎨 Standalone API
- πŸš€ Schematics
- ❗ Error Handling
Part 3
- πŸ—„οΈ Zoneless Server-Side Rendering
Part 3
- πŸ›‘ Breaking Changes
- πŸ—‘οΈ Deprecations
- πŸ”Œ Exposed Internals

---


## Standalone API

We have introduced a new, standalone API that is backward compatible with the old API. Here is a quick comparison of the two APIs:
Expand Down Expand Up @@ -234,15 +234,16 @@ There are various schematics available to quickly generate various NGXS files:
```bash
ng generate @ngxs/store:store
```

Generates sample `state` and `actions` files in the provided location, with the provided name and generation options (see [documentation](https://www.ngxs.io/concepts/store/schematics)).

- Generate `state` file:

```bash
ng generate @ngxs/store:state --name TodosState
```

Will generate a sample `todos.state.ts` file in the provided location (with the provided name and generation options - see [documentation](https://www.ngxs.io/concepts/state/schematics)).


- Generate `actions` file:

Expand Down Expand Up @@ -276,6 +277,21 @@ You can read more [here](https://www.ngxs.io/concepts/store/error-handling#overr
---
## Zoneless Server-Side Rendering (experimental)
Before zoneless change detection was introduced, Angular required zone.js to be used for server-side rendering. This was necessary to determine when the application became 'stable' and could be serialized for client transmission. With zoneless change detection, Angular utilizes its internal pending tasks service. This service explicitly contributes to application stability by notifying Angular when asynchronous tasks are in progress, preventing premature serialization.
NGXS provides an experimental feature called `withExperimentalNgxsPendingTasks`, which can be registered when calling `provideStore`. This feature prevents SSR serialization before NGXS actions have been handled:
```ts
import { provideStore } from '@ngxs/store';
import { withExperimentalNgxsPendingTasks } from '@ngxs/store/experimental';
export const appConfig: ApplicationConfig = {
providers: [provideStore([], withExperimentalNgxsPendingTasks())]
};
```
## Breaking Changes
### Storage Plugin
Expand Down

0 comments on commit 12f1131

Please sign in to comment.