-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(storage-plugin): use
ngServerMode
to check whether we are in SSR
In this commit, we replace `isPlatformServer` in the storage plugin with the new built-in variable `ngServerMode`, available starting from Angular 19. This compile-time variable allows the code to be tree-shakable.
- Loading branch information
Showing
5 changed files
with
15 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,22 @@ | ||
import { InjectionToken, PLATFORM_ID, inject } from '@angular/core'; | ||
import { isPlatformBrowser } from '@angular/common'; | ||
import { InjectionToken } from '@angular/core'; | ||
import { StorageEngine } from '@ngxs/storage-plugin/internals'; | ||
|
||
declare const ngDevMode: boolean; | ||
declare const ngServerMode: boolean; | ||
|
||
export const LOCAL_STORAGE_ENGINE = /* @__PURE__ */ new InjectionToken<StorageEngine | null>( | ||
typeof ngDevMode !== 'undefined' && ngDevMode ? 'LOCAL_STORAGE_ENGINE' : '', | ||
{ | ||
providedIn: 'root', | ||
factory: () => (isPlatformBrowser(inject(PLATFORM_ID)) ? localStorage : null) | ||
factory: () => (typeof ngServerMode !== 'undefined' && ngServerMode ? null : localStorage) | ||
} | ||
); | ||
|
||
export const SESSION_STORAGE_ENGINE = /* @__PURE__ */ new InjectionToken<StorageEngine | null>( | ||
typeof ngDevMode !== 'undefined' && ngDevMode ? 'SESSION_STORAGE_ENGINE' : '', | ||
{ | ||
providedIn: 'root', | ||
factory: () => (isPlatformBrowser(inject(PLATFORM_ID)) ? sessionStorage : null) | ||
factory: () => | ||
typeof ngServerMode !== 'undefined' && ngServerMode ? null : sessionStorage | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters