redux-substore
Advanced tools
Comparing version 0.1.2 to 0.2.1
{ | ||
"name": "redux-substore", | ||
"version": "0.1.2", | ||
"version": "0.2.1", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "devDependencies": { |
@@ -6,3 +6,10 @@ import * as most from 'most' | ||
class Substore { | ||
constructor({ prefix, promiseFunction, callbackFunction, initialState, responseMap }) { | ||
constructor({ | ||
prefix, | ||
promiseFunction, | ||
callbackFunction, | ||
initialState, | ||
responseMap, | ||
actionMeta, | ||
}) { | ||
this.prefix = prefix | ||
@@ -12,2 +19,3 @@ this.promiseFunction = promiseFunction | ||
this.responseMap = responseMap || (response => ({ data: response })) | ||
this.actionMeta = actionMeta || {} | ||
@@ -28,15 +36,18 @@ try { | ||
return { | ||
REQUEST: `${this.prefix}_REQUEST`, | ||
CLEAR: `${this.prefix}_CLEAR`, | ||
FAILURE: `${this.prefix}_REQUEST_FAILURE`, | ||
SUCCESS: `${this.prefix}_REQUEST_SUCCESS`, | ||
REQUEST: `${this.prefix}REQUEST`, | ||
CLEAR: `${this.prefix}CLEAR`, | ||
FAILURE: `${this.prefix}REQUEST_FAILURE`, | ||
SUCCESS: `${this.prefix}REQUEST_SUCCESS`, | ||
} | ||
} | ||
clearAction = () => ({ type: this.ACTION_TYPE.CLEAR }) | ||
requestAction = payload => ({ | ||
type: this.ACTION_TYPE.REQUEST, | ||
meta: this.actionMeta.requestAction, | ||
payload, | ||
}) | ||
requestAction = payload => ({ type: this.ACTION_TYPE.REQUEST, payload }) | ||
failureAction = error => ({ | ||
type: this.ACTION_TYPE.FAILURE, | ||
meta: this.actionMeta.failureAction, | ||
payload: error, | ||
@@ -48,5 +59,8 @@ error: true, | ||
type: this.ACTION_TYPE.SUCCESS, | ||
meta: this.actionMeta.successAction, | ||
payload, | ||
}) | ||
clearAction = () => ({ type: this.ACTION_TYPE.CLEAR, meta: this.actionMeta.clearAction }) | ||
reducer = (state = this.initialState, { type, payload }) => { | ||
@@ -53,0 +67,0 @@ switch (type) { |
@@ -7,3 +7,3 @@ import Substore from './' | ||
beforeEach(() => { | ||
substore = new Substore({ prefix: 'PREFIX' }) | ||
substore = new Substore({ prefix: 'prefix/' }) | ||
}) | ||
@@ -30,6 +30,6 @@ | ||
it('builds a set of action types', () => { | ||
expect(substore.ACTION_TYPE).toHaveProperty('CLEAR', 'PREFIX_CLEAR') | ||
expect(substore.ACTION_TYPE).toHaveProperty('REQUEST', 'PREFIX_REQUEST') | ||
expect(substore.ACTION_TYPE).toHaveProperty('FAILURE', 'PREFIX_REQUEST_FAILURE') | ||
expect(substore.ACTION_TYPE).toHaveProperty('SUCCESS', 'PREFIX_REQUEST_SUCCESS') | ||
expect(substore.ACTION_TYPE).toHaveProperty('CLEAR', 'prefix/CLEAR') | ||
expect(substore.ACTION_TYPE).toHaveProperty('REQUEST', 'prefix/REQUEST') | ||
expect(substore.ACTION_TYPE).toHaveProperty('FAILURE', 'prefix/REQUEST_FAILURE') | ||
expect(substore.ACTION_TYPE).toHaveProperty('SUCCESS', 'prefix/REQUEST_SUCCESS') | ||
}) | ||
@@ -36,0 +36,0 @@ |
149976
13
418