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
Copy file name to clipboardExpand all lines: README.md
+101-3Lines changed: 101 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,27 @@
1
-
# Parse Offline (Work in progress)
1
+
# Parse Offline
2
2
3
3
Parse JS SDK Addons for handling offline for PWAs
4
4
5
5
Bonus: No external dependencies
6
6
7
+
<!-- TOC -->
8
+
9
+
-[Parse Offline](#parse-offline)
10
+
-[The problem](#the-problem)
11
+
-[The solution](#the-solution)
12
+
-[How it works](#how-it-works)
13
+
-[Examples](#examples)
14
+
-[Basic](#basic)
15
+
-[Controlled cache time](#controlled-cache-time)
16
+
-[With custom cache key](#with-custom-cache-key)
17
+
-[Want to contribute?](#want-to-contribute)
18
+
-[Dev Features](#dev-features)
19
+
-[Credits](#credits)
20
+
-[License](#license)
21
+
-[Support us on Patreon](#support-us-on-patreon)
22
+
23
+
<!-- /TOC -->
24
+
7
25
## The problem
8
26
9
27
When you develop applications with Parse, you constantly need to fetch the information from the remote server, affecting the offline experience.
@@ -16,11 +34,91 @@ With this addon for the Parse JS SDK, you can:
16
34
17
35
*[x] Have a synced cache for your results in the `localStorage` for any class. So everytime you make a request, you can keep a local cache of the results, and display them when your app goes offline.
18
36
19
-
*[ ]Save in the Service Worker cache images from the results.
37
+
*[ ]Edit/destroy objects, and save them when the app goes online.
20
38
21
39
## How it works
22
40
23
-
Because the Parse JS SDK contacts your Parse Server via POST requests, and saves the user token in `localStorage`, it is currently not possible to handle retries via Service Worker. So, the `localStorage` is used to
41
+
Because the Parse JS SDK contacts your Parse Server via POST requests, and saves the user token in `localStorage`, it is currently not possible to handle retries via Service Worker. To solve this problem, the `localStorage` is used to save sets of results that you might need to see when the app goes offline.
42
+
43
+
## Examples
44
+
45
+
Please be aware that the following examples are given in Typescript. The main difference between the Typescript and the Javascript examples is the way in which `parse` is imported.
46
+
47
+
In Typescript:
48
+
```ts
49
+
import*asParsefrom'parse';
50
+
```
51
+
52
+
In Javascript:
53
+
```ts
54
+
importParsefrom'parse';
55
+
```
56
+
57
+
### Basic
58
+
In this example, we get a set of results from the database, and save them to the localStorage. To do this, we call `findWithFallbackAndCache` as follows:
`findWithFallbackAndCache` always tries to fetch the most recent content, and only if the navigator is not online it returns the elements saved in the cache.
71
+
72
+
The results are saved in the `localStorage`, available in the key `_cache_:className`. So, you could do the following, to get the items saved in the browser's local storage:
In this example, we set a maximum age to the fetched results. If the results are still valid, they are returned. Else, the library returns an empty array.
0 commit comments