قالب وردپرس درنا توس
Home / IOS Development / Reag data layer – Part 7: Offline printer

Reag data layer – Part 7: Offline printer



This post is the seventh part of an 8-part series that delves deep into how to build a robust, real-world frontend app data layer. See the previous sections here:

Caching read data while offline introduces some complexity into an app, and caching printer adds even more more complexity. With reading data, the worst thing that can happen is when the data is outdated. With a cached printer, if an error occurs, data entered by a user is lost. Making sure this doesn't happen is a significant cost, so you'll want to make sure it's worth it for your app.

With that said, let's see how we can implement some basic cached writing. The first thing we can do is keep track of failed additions and try them again.

If you want, you can download the app at the end of the post.

Try again

First, let's keep track of a queue of games that have not yet been saved. Make the following changes to shop / games / actions.js :

   export const STORE_GAMES = & # 39; STORE_GAMES & # 39 ;;
export const ADD_GAME = & # 39; ADD_GAME & # 39 ;;
 + export const QUEUE_GAME_TO_ADD = & # 39; QUEUE_GAME_TO_ADD & # 39 ;;
 export const START_LOADING = & # 39; START_LOADING & # 39 ;;
export const RECORD_ERROR = & # 39; RECORD_ERROR & # 39 ;;
...
export const addGame = (title) => async (send) => {
const game = {
type: "games",
attributes: {title},
};
 + shipping ({
+ type: QUEUE_GAME_TO_ADD,
+ games,
+});
 const {data: responseBody} = waiting api.post (& # 39; / games & # 39 ;, {data: game});
shipment ({
type: ADD_GAME,
games: responseBody.data,
});
};

Import the new action into store / game / reducers.js :

   import {
+ QUEUE_GAME_TO_ADD,
ADD_GAME,
STORE_GAMES,

  Next, let's make a  spillToAdd  reduction: 

  export    function    gamesToAdd   (  state    =


Source link