Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
addAction({ type, payload, handler }) {
let handlerName = type
.split(/(?=[A-Z])/)
.join('_')
.toUpperCase()
this.actionObject[type] = payload
const { Types, Creators } = createActions(this.actionObject, {
prefix: `${this.name.toUpperCase()}_`
})
this.actionTypes = Types
this.actions = Creators
this.actionHandlers[Types[handlerName]] = handler
Object.getPrototypeOf(this)[type] = args => {
return dispatch => {
dispatch(this.actions[type].apply(null, Object.values(args)))
}
}
}
addAction({ type, payload, handler }) {
let handlerName = type.split(/(?=[A-Z])/).join('_').toUpperCase();
this.actionObject[type] = payload
const { Types, Creators } = createActions(this.actionObject, { prefix: `${this.name.toUpperCase()}_` })
this.actionTypes = Types
this.actions = Creators
this.actionHandlers[Types[handlerName]] = handler
Object.getPrototypeOf(this)[type] = (args) => {
return (dispatch) => {
dispatch(this.actions[type].apply(null, Object.values(args)))
}
}
}
export function createOfflineActions(config) {
const { Types, Creators } = createActions(config)
const OfflineCreators = _mapValues(Creators, (creator) => {
return appendOfflineMeta(creator)
})
return {
Types,
Creators: OfflineCreators,
}
}
constructor(name, url) {
this.name = name
this.endpointUrl = url
this.initialState = {
items: []
}
this.actionObject = {
'loadMore' : ['newItems'],
'refresh' : ['newItems']
}
const { Types, Creators } = createActions(this.actionObject, { prefix: `${name.toUpperCase()}_` })
this.actionTypes = Types
this.actions = Creators
this.actionHandlers = {
[Types['LOAD_MORE']]: (state, { newItems }) => {
return {
...state,
items: state.items.concat(newItems)
}
},
[Types['REFRESH']]: (state, { newItems }) => {
return {
...state,
items: newItems
}
this.onParsePaginationResponse = onParsePaginationResponse
this.customizedReducerPath = customizedReducerPath
this.getHeaders = requestHeaders
this.initialState = {
items: []
}
this.actionObject = {
loadMore: ['newItems'],
refresh: ['newItems'],
reset: [],
setTotalPage: ['totalPagesNumber']
}
const { Types, Creators } = createActions(this.actionObject, {
prefix: `${name.toUpperCase()}_`
})
this.actionTypes = Types
this.actions = Creators
this.actionHandlers = {
[Types['LOAD_MORE']]: (state, { newItems }) => {
return {
...state,
items: state.items.concat(newItems)
}
},
[Types['REFRESH']]: (state, { newItems }) => {
return {
...state,