You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Efficient local storage module for Angular apps and Progressive Wep apps (PWA):
4
-
-**simplicity**: based on native `localStorage` API, with automatic JSON stringify/parse,
5
-
-**perfomance**: internally stored via the asynchronous `IndexedDB` API,
6
-
-**Angular-like**: wrapped in RxJS `Observables`,
3
+
Efficient client-side storage module for Angular apps and Progressive Wep Apps (PWA):
4
+
-**simplicity**: based on native `localStorage` API,
5
+
-**perfomance**: internally stored via the asynchronous `indexedDB` API,
6
+
-**Angular-like**: wrapped in RxJS `Observable`s,
7
7
-**security**: validate data with a JSON Schema,
8
8
-**compatibility**: works around some browsers issues,
9
9
-**documentation**: API fully explained, and a changelog!
10
10
-**maintenance**: the lib follows Angular LTS and anticipates the next Angular version,
11
-
-**reference**: 1st Angular library for local storage according to [ngx.tools](https://ngx.tools/#/search?q=local%20storage).
11
+
-**reference**: 1st Angular library for client-side storage according to [ngx.tools](https://ngx.tools/#/search?q=local%20storage).
12
12
13
13
## By the same author
14
14
15
15
-[Angular schematics extension for VS Code](https://marketplace.visualstudio.com/items?itemName=cyrilletuzi.angular-schematics) (GUI for Angular CLI commands)
16
-
- Other Angular libraries: [@ngx-pwa/offline](https://github.com/cyrilletuzi/ngx-pwa-offline) and [@ngx-pwa/ngsw-schema](https://github.com/cyrilletuzi/ngsw-schema)
16
+
- Other Angular library: [@ngx-pwa/offline](https://github.com/cyrilletuzi/ngx-pwa-offline)
17
17
- Popular [Angular posts on Medium](https://medium.com/@cyrilletuzi)
18
18
- Follow updates of this lib on [Twitter](https://twitter.com/cyrilletuzi)
19
19
-**[Angular onsite trainings](https://formationjavascript.com/formation-angular/)** (based in Paris, so the website is in French, but [my English bio is here](https://www.cyrilletuzi.com/en/web/) and I'm open to travel)
20
20
21
21
## Why this module?
22
22
23
-
For now, Angular does not provide a local storage module, and almost every app needs some local storage.
23
+
For now, Angular does not provide a client-side storage module, and almost every app needs some client-side storage.
next: (user) => { /* Called if data is valid or `undefined` or `null` */ },
139
205
error: (error) => { /* Called if data is invalid */ },
140
206
});
141
207
```
@@ -144,15 +210,16 @@ See the [full validation guide](./docs/VALIDATION.md) to see how to validate all
144
210
145
211
### Subscription
146
212
147
-
You *DO NOT* need to unsubscribe: the `Observable` autocompletes (like in the `HttpClient` service).
213
+
You *DO NOT* need to unsubscribe: the `Observable` autocompletes (like in the Angular `HttpClient` service).
148
214
149
-
But **you *DO* need to subscribe**, even if you don't have something specific to do after writing in local storage (because it's how RxJS Observables work).
215
+
But **you *DO* need to subscribe**, even if you don't have something specific to do after writing in storage
216
+
(because it's how RxJS `Observable`s work).
150
217
151
218
### Errors
152
219
153
220
As usual, it's better to catch any potential error:
@@ -163,8 +230,8 @@ For read operations, you can also manage errors by providing a default value:
163
230
import { of } from'rxjs';
164
231
import { catchError } from'rxjs/operators';
165
232
166
-
this.localStorage.getItem('color').pipe(
167
-
catchError(() =>of('red'))
233
+
this.storageMap.get('color').pipe(
234
+
catchError(() =>of('red')),
168
235
).subscribe((result) => {});
169
236
```
170
237
@@ -177,27 +244,25 @@ Could only happen when in `localStorage` fallback:
177
244
178
245
Should only happen if data was corrupted or modified from outside of the lib:
179
246
-`.getItem()`: data invalid against your JSON schema (`ValidationError` from this lib)
180
-
- any method when in `indexedDB`: database store has been deleted (`DOMException` with name `'NotFoundError'`)
247
+
- any method when in `indexedDB`: database store has been deleted (`DOMException` with name `NotFoundError`)
181
248
182
249
Other errors are supposed to be catched or avoided by the lib,
183
250
so if you were to run into an unlisted error, please file an issue.
184
251
185
252
### `Map`-like operations
186
253
187
-
Starting *with version >= 7.4*, in addition to the classic `localStorage`-like API,
188
-
this lib also provides some`Map`-like methods for advanced operations:
189
-
-`.keys()` method
190
-
-`.has(key)` method
191
-
-`.size` property
254
+
Starting *with version >= 8* of this lib, in addition to the classic `localStorage`-like API,
255
+
this lib also provides a`Map`-like API for advanced operations:
256
+
-`.keys()`
257
+
-`.has(key)`
258
+
-`.size`
192
259
193
260
See the [documentation](./docs/MAP_OPERATIONS.md) for more info and some recipes.
261
+
For example, it allows to implement a multiple databases scenario.
194
262
195
-
### Collision
196
-
197
-
If you have multiple apps on the same *sub*domain *and* you don't want to share data between them,
198
-
see the [prefix guide](./docs/COLLISION.md).
263
+
## Support
199
264
200
-
## Angular support
265
+
###Angular support
201
266
202
267
We follow [Angular LTS support](https://angular.io/guide/releases),
203
268
meaning we support Angular >= 6, until November 2019.
@@ -207,22 +272,27 @@ This module supports [AoT pre-compiling](https://angular.io/guide/aot-compiler).
207
272
This module supports [Universal server-side rendering](https://github.com/angular/universal)
208
273
via a mock storage.
209
274
210
-
## Browser support
275
+
###Browser support
211
276
212
-
[All browsers supporting IndexedDB](http://caniuse.com/#feat=indexeddb), ie. **all current browsers** :
277
+
[All browsers supporting IndexedDB](https://caniuse.com/#feat=indexeddb), ie. **all current browsers** :
213
278
Firefox, Chrome, Opera, Safari, Edge, and IE10+.
214
279
215
280
See [the browsers support guide](./docs/BROWSERS_SUPPORT.md) for more details and special cases (like private browsing).
216
281
217
-
## Interoperability
282
+
### Collision
283
+
284
+
If you have multiple apps on the same *sub*domain *and* you don't want to share data between them,
285
+
see the [prefix guide](./docs/COLLISION.md).
286
+
287
+
### Interoperability
218
288
219
-
For interoperability when mixing this lib with direct usage of native APIs or other libs like `localforage`
220
-
(which doesn't make sense in most of cases),
289
+
For interoperability when mixing this lib with direct usage of native APIs or other libs like `localForage`
290
+
(which doesn't make sense in most cases),
221
291
see the [interoperability documentation](./docs/INTEROPERABILITY.md).
222
292
223
-
## Changelog
293
+
###Changelog
224
294
225
-
[Changelog available here](https://github.com/cyrilletuzi/angular-async-local-storage/blob/master/CHANGELOG.md), and [migration guides here](./MIGRATION.md).
295
+
[Changelog available here](./CHANGELOG.md), and [migration guides here](./MIGRATION.md).
Be aware that local storage is limited in browsers when in private / incognito modes. Most browsers will delete the data when the private browsing session ends.
20
-
It's not a real issue as local storage is useful for apps, and apps should not be in private mode.
19
+
Be aware that `indexedDB` usage is limited in browsers when in private / incognito modes.
20
+
Most browsers will delete the data when the private browsing session ends.
21
+
It's not a real issue as client-side storage is only useful for apps, and apps should not be in private mode.
21
22
22
23
In some scenarios, `indexedDB` is not available, so the lib fallbacks to (synchronous) `localStorage`. It happens in:
23
24
- Firefox private mode (see [#26](https://github.com/cyrilletuzi/angular-async-local-storage/issues/26))
0 commit comments