kickstartcrew / redux-offline-queue

Simple offline queue for redux. Queue actions while offline to dispatch the requests upon connectivity.
Other
136 stars 17 forks source link

How did I create the "Creators" of exemple without reduxsauce? #58

Closed ViniciusCrisol closed 4 years ago

ViniciusCrisol commented 4 years ago

markActionsOffline is not working, I think this is wrong, I'm searching, but I didn't find anything

import {combineReducers} from 'redux';
import {reducer as offline, markActionsOffline} from 'redux-offline-queue';

import user from './user/reducer';
import local from './local/reducer';
import result from './result/reducer';
import common from './common/reducer';
import position from './position/reducer';
import locations from './locations/reducer';

markActionsOffline(user, ['@user/SAVE_VALUE_REQUEST']);

export default combineReducers({
  offline,
  user,
  local,
  result,
  common,
  position,
  locations,
});
RobPando commented 4 years ago

@ViniciusCrisol I need to update the readme but basically if you are using pure redux I would imagine you have an actions folder with all your action files. in any action file you need to do something like this

import { createOfflineActions } from "redux-offline-queue";

const { Types, Creators } = createOfflineActions({
  myOfflineActionRequest: ["param1", "param2"]
})
export const OfflineMyStoreTypes = Types;
export const OfflineMyStoreCreators = Creators;

and you should listen to this type for actions so in your redux saga or reducers you would import the type and the constant is the name of the action but snake case and all caps like you would a normal constant

import { OfflineMyStoreTypes } from "./actions/myStore";
....
 case OfflineMyStoreTypes.MY_OFFLINE_ACTION_REQUEST: ....

and in your react components where you will dispatch the actions you would import the creator

import { OfflineMyStoreCreators } from "../redux/actions/myStore";

...

const mapDispatchToProps = (dispatch) => ({
  myRequest: (param1, param2) => dispatch(OfflineMyStoreCreator.myOfflineRequest(param1, param2),
})

NOTE: That for all other actions you make where you don't need offline queue you don't need to odd them in the createOfflineActions method but outside and normally as you would do without it.