Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"meta.offline" contains empty object. #545

Open
mastadong opened this issue Mar 17, 2023 · 0 comments
Open

"meta.offline" contains empty object. #545

mastadong opened this issue Mar 17, 2023 · 0 comments

Comments

@mastadong
Copy link

mastadong commented Mar 17, 2023

I have a React/Typescript project. I have defined my offline action interface as:

interface ISaveAirBalancesOffline{
    type:CommissioningActionTypes.SAVE_AIR_BALANCES_OFFLINE;
    payload: {selectedSystem:IEquipmentSystem | null,editedAirBalances:IUnitAirBalance[]},
        meta: {
            offline: {
                effect: (dispatch:Dispatch<CommissioningAction>) => void;
            }
        }
}

I implement this interface when I create and dispatch the action from my action-creator like this:

const offlineAction: Action = ({
                type: ActionTypes.SAVE_AIR_BALANCES_OFFLINE,
                payload: {selectedSystem,editedAirBalances},
                meta: {
                    offline: {
                        effect: async (dispatch: Dispatch<Action>) => {
                            try {
                                  /* DO SOME API STUFF *.                           
                                dispatch({
                                    type: ActionTypes.SAVE_AIR_BALANCES_SUCCESS,
                                    payload: updatedSystem,
                                });
                            } catch (err) {
                                if (err instanceof Error) {
                                    dispatch({
                                        type: ActionTypes.SAVE_AIR_BALANCES_ERROR,
                                        payload: err.message,
                                    });
                                }
                            }
                        },                   
                    },
                },
            });

    console.log(`Dispatching offline action: ${JSON.stringify(offlineAction)}`);
    dispatch(offlineAction);

When I place a breakpoint on the line 'dispatch(offlineAction)', the Redux Dev Tools show that the 'effect' contains a function. After dispatching the offlineAction, I open Redux Offline's "outbox" and find the following:

"type": "save_air_balances_offline",
  "payload": {  (This contains all the correct payload data) },
  "meta": {
    "offline": {}
  }

Note that while the "type" and "payload" are correct, the contents of "meta.offline" are empty. Here is how I've implemented Redux Offline in my (React/Typescript) application:

import offlineConfig from '@redux-offline/redux-offline/lib/defaults';
import reducers from './reducers';
import persistCallback from './middleware/persistCallback';

const customConfig = {
  ...offlineConfig,
  persistCallback: persistCallback,
};

export const store = configureStore({
  reducer: reducers,
  enhancers:[offline(customConfig)]
});

Since the documentation for Redux Offline is so sparse and some examples are outdated, I'm having a hard time working out exactly how to implement the library in my application. Does anyone have a plausible explanation for what's happening or why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant