Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat! use immutable route data #321

Merged
merged 3 commits into from
Sep 2, 2024
Merged

Conversation

LayZeeDK
Copy link
Member

@LayZeeDK LayZeeDK commented Sep 2, 2024

Features

  • Use immutable route data

BREAKING CHANGES

StrictRouteData members are now read-only.

TypeScript will fail to compile application code that mutates route data data structures.

BEFORE:

// heroes.component.ts
// (...)
import { RouterStore } from "@ngworker/router-component-store";

@Component({
  // (...)
})
export class DashboardComponent {
  #routerStore = inject(RouterStore);

  limit$: Observable<number> = this.#routerStore.routeData$.pipe(
    map((data) => {
      data["limit"] = Number(data["limit"])

      return data;
    }),
    map(data => data["limit"])
  );
}

AFTER:

// heroes.component.ts
// (...)
import { RouterStore } from "@ngworker/router-component-store";

@Component({
  // (...)
})
export class DashboardComponent {
  #routerStore = inject(RouterStore);

  limit$: Observable<number> = this.#routerStore.routeData$.pipe(
    map((data) => Number(data["limit"]))
  );
}

**BREAKING CHANGES**

`StrictRouteData`
members are now read-only.

TypeScript will fail to compile application code that mutates route data data structures.

BEFORE:

```typescript
// heroes.component.ts
// (...)
import { RouterStore } from "@ngworker/router-component-store";

@component({
  // (...)
})
export class DashboardComponent {
  #routerStore = inject(RouterStore);

  limit$: Observable<number> = this.#routerStore.routeData$.pipe(
    map((data) => {
      data["limit"] = Number(data["limit"])

      return data;
    }),
    map(data => data["limit"])
  );
}
```

AFTER:

```typescript
// heroes.component.ts
// (...)
import { RouterStore } from "@ngworker/router-component-store";

@component({
  // (...)
})
export class DashboardComponent {
  #routerStore = inject(RouterStore);

  limit$: Observable<number> = this.#routerStore.routeData$.pipe(
    map((data) => Number(data["limit"]))
  );
}
```
@LayZeeDK LayZeeDK force-pushed the feat/use-immutable-route-data branch from 22b9f36 to 2f350a8 Compare September 2, 2024 20:54
@LayZeeDK LayZeeDK enabled auto-merge September 2, 2024 20:55
@LayZeeDK LayZeeDK merged commit fb72ea9 into main Sep 2, 2024
7 checks passed
@LayZeeDK LayZeeDK deleted the feat/use-immutable-route-data branch September 2, 2024 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant