Skip to content

Commit

Permalink
Add remove action and uuid meta attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
RobPando committed Jul 9, 2020
1 parent 2176cd2 commit 6f89f65
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as actions from './actions'
import offlineMiddleware from './offlineMiddleware'
import { createOfflineActions, markActionsOffline, queueAction } from './offlineActions'
import { createOfflineActions, markActionsOffline, queueAction, removeAction } from './offlineActions'
import reducer from './reducer'
import suspendSaga from './suspendSaga'
import consumeActionMiddleware from './consumeActionMiddleware'
Expand All @@ -13,6 +13,7 @@ module.exports = {
offlineMiddleware,
markActionsOffline,
queueAction,
removeAction,
reducer,
suspendSaga,
consumeActionMiddleware,
Expand Down
19 changes: 18 additions & 1 deletion src/offlineActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
forEach as _forEach,
has as _has,
} from 'lodash'
import { QUEUE_ACTION } from "./actions"
import uuid from 'uuid/v4'

import { QUEUE_ACTION, REMOVE_ACTION } from "./actions"

/**
* Wraps reduxsauce's creator function to append offline metadata.
Expand All @@ -14,9 +16,11 @@ import { QUEUE_ACTION } from "./actions"
const appendOfflineMeta = (creator) => {
return (...rest) => {
const creatorResult = creator(...rest)

return {
...creatorResult,
meta: {
uuid: uuid(),
...creatorResult.meta,
queueIfOffline: true,
},
Expand Down Expand Up @@ -81,6 +85,19 @@ export const queueAction = (action) => {
type: QUEUE_ACTION,
payload: {
...action,
meta: {
uuid: uuid(),
...action.meta,
},
}
}
}

export const removeAction = (action) => {
return {
type: REMOVE_ACTION,
payload: {
uuid: action.uuid,
}
}
}
5 changes: 5 additions & 0 deletions src/offlineMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
includes as _includes,
get as _get,
} from 'lodash'
import uuid from 'uuid/v4'

import INITIAL_STATE from './initialState'
import { QUEUE_ACTION, ONLINE, RESET_QUEUE } from './actions'
Expand Down Expand Up @@ -94,6 +95,10 @@ export default function offlineMiddleware(userConfig = {}) {
type: QUEUE_ACTION,
payload: {
...action,
meta: {
uuid: uuid(),
...action.meta,
}
},
}

Expand Down

0 comments on commit 6f89f65

Please sign in to comment.