-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lib): allow to add custom storage
- Loading branch information
1 parent
0ee5eff
commit 5e4efc4
Showing
6 changed files
with
81 additions
and
43 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
12 changes: 12 additions & 0 deletions
12
projects/ngneat/forms-manager/src/lib/localStorageManager.ts
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PersistManager } from "./types"; | ||
|
||
export class LocalStorageManager<T> implements PersistManager<T> { | ||
setValue(key: string, data: T): T { | ||
localStorage.setItem(key, JSON.stringify(data)); | ||
return data; | ||
} | ||
|
||
getValue(key: string): T { | ||
return JSON.parse(localStorage.getItem(key) || '{}'); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
projects/ngneat/forms-manager/src/lib/sessionStorageManager.ts
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PersistManager } from "./types"; | ||
|
||
export class SessionStorageManager<T> implements PersistManager<T> { | ||
setValue(key: string, data: T): T { | ||
sessionStorage.setItem(key, JSON.stringify(data)); | ||
return data; | ||
} | ||
|
||
getValue(key: string): T { | ||
return JSON.parse(sessionStorage.getItem(key) || '{}'); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
export { NgFormsManager } from './lib/forms-manager'; | ||
export { setAsyncValidators, setValidators } from './lib/validators'; | ||
export { NgFormsManagerConfig, NG_FORMS_MANAGER_CONFIG } from './lib/config'; | ||
export { PersistManager } from './lib/types'; | ||
export { LocalStorageManager } from './lib/localStorageManager'; | ||
export { SessionStorageManager } from './lib/sessionStorageManager'; |