Skip to content

Commit 8418355

Browse files
committed
# v0.1.5 process
1 parent afe4756 commit 8418355

31 files changed

+201
-178
lines changed

lib/action.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -389,28 +389,31 @@ var makeAction = function makeAction(actionId, parentActionId, actionSchema, act
389389
};
390390
};
391391

392-
// /**
393-
// * Clean entity from entity reducer
394-
// *
395-
// * @memberOf action.makeAction.Action
396-
// * @type {Function}
397-
// *
398-
// * @example
399-
// * store.dispatch(userLoginAction.clean())
400-
// *
401-
// * @returns {Undefined} - returns None, only clear entity data
402-
// */
403-
// this.action.clean = () => {
404-
// return (dispatch, getState) => {
405-
// dispatch({
406-
// time: new Date().getTime(),
407-
// type: ACTION_CLEAN_TYPE_NAME,
408-
// prefix: ACTION_TYPE_PREFIX,
409-
// actionId: this.actionId,
410-
// actionSchema: this.schema
411-
// })
412-
// }
413-
// }
392+
/**
393+
* Delete entity from entity reducer
394+
*
395+
* @memberOf action.makeAction.Action
396+
* @type {Function}
397+
*
398+
* @example
399+
* store.dispatch(userDeleteAction.delete())
400+
*
401+
* @example
402+
* store.dispatch(userDeleteAction.withPrefix(userId).delete())
403+
*
404+
* @returns {Undefined} - returns None, only delete entity data
405+
*/
406+
this.action.delete = function () {
407+
return function (dispatch, getState) {
408+
dispatch({
409+
time: new Date().getTime(),
410+
type: _config.ACTION_DELETE_TYPE_NAME,
411+
prefix: _config.ACTION_TYPE_PREFIX,
412+
actionId: _this.actionId,
413+
actionSchema: _this.schema
414+
});
415+
};
416+
};
414417

415418
return this.action;
416419
};

lib/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ var ACTION_EMPTY_TYPE_NAME = exports.ACTION_EMPTY_TYPE_NAME = ACTION_TYPE_PREFIX
8383
* @const
8484
* @type {String}
8585
*/
86-
var ACTION_CLEAN_TYPE_NAME = exports.ACTION_CLEAN_TYPE_NAME = ACTION_TYPE_PREFIX + '-clean';
86+
var ACTION_DELETE_TYPE_NAME = exports.ACTION_DELETE_TYPE_NAME = ACTION_TYPE_PREFIX + '-clean';
8787

8888
/**
8989
* replaced default response mapper to callback

lib/reducer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ var makeActionsReducer = function makeActionsReducer(defaultActionsState) {
6767
actionState = state.get(actionId);
6868
}
6969

70+
// delete entity id from actions
71+
if (action.type === _config.ACTION_DELETE_TYPE_NAME) {
72+
console.log('action delete', actionState);
73+
return state;
74+
}
75+
7076
actionState = actionState.merge({
7177
status: status,
7278
time: time,
@@ -121,6 +127,12 @@ var makeEntitiesReducer = function makeEntitiesReducer(defaultEntitiesState) {
121127

122128
var newEntitiesItems = normalizedPayloadSource ? normalizedPayloadSource.entities : {};
123129

130+
// delete entity id from actions
131+
if (action.type === _config.ACTION_DELETE_TYPE_NAME) {
132+
console.log('reducer delete');
133+
return state;
134+
}
135+
124136
// merge entity item data
125137
for (var entityName in newEntitiesItems) {
126138
for (var entityId in newEntitiesItems[entityName]) {

src/action.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*/
44

55
import {
6-
ACTION_EMPTY_TYPE_NAME,
76
ACTION_DELETE_TYPE_NAME,
7+
ACTION_EMPTY_TYPE_NAME,
88
ACTION_ID_KEY,
99
ACTION_IDS_KEY,
1010
ACTION_TYPE_PREFIX,

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { createReducers } from './reducer'
33
import {
44
denomalizeEntityItemById,
55
getActionData,
6-
getMergedActionsData,
76
getEntityItemsByAction,
87
getEntityItemsByEntityName,
98
getEntityItemsBySchema,
10-
getEntityReducer
9+
getEntityReducer,
10+
getMergedActionsData
1111
} from './selector'
1212

1313
import {

src/reducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { fromJS } from 'immutable'
66
import { normalize } from 'normalizr'
77

88
import {
9-
ACTION_EMPTY_TYPE_NAME,
109
ACTION_DELETE_TYPE_NAME,
10+
ACTION_EMPTY_TYPE_NAME,
1111
ACTION_TYPE_PREFIX,
1212
ACTIONS_REDUCER_NAME,
1313
ENTITIES_REDUCER_NAME

test/action.spec.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import 'should'
22
import sinon from 'sinon'
33
import { schema } from 'normalizr'
4-
5-
require('should-sinon')
6-
74
import {
5+
createAction,
86
makeActionHandler,
9-
makeActionUniqId,
10-
makeAction,
11-
createAction
7+
makeActionUniqId
128
} from '../src/action'
139

10+
require('should-sinon')
11+
1412
describe('action makeActionUniqId ', function() {
1513
it('makeActionUniqId returns uniquie ids', function() {
1614
const result = new Set([

test/config.spec.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import 'should'
22
import sinon from 'sinon'
33
import { schema } from 'normalizr'
4-
5-
require('should-sinon')
6-
74
import {
8-
IS_TEST_ENVIRONMENT,
9-
STATUSES,
5+
ACTION_EMPTY_TYPE_NAME,
106
ACTION_ID_KEY,
117
ACTION_IDS_KEY,
128
ACTION_TYPE_PREFIX,
139
ACTIONS_REDUCER_NAME,
1410
ENTITIES_REDUCER_NAME,
15-
ACTION_EMPTY_TYPE_NAME,
11+
IS_TEST_ENVIRONMENT,
1612
setDefaultResponseMapper,
17-
setDenormalize
13+
setDenormalize,
14+
STATUSES
1815
} from '../src/config'
1916

2017
import { createAction } from '../src/action'
2118

19+
require('should-sinon')
20+
2221
describe('config is valid', function() {
2322
it('should define all required variables', function() {
2423
IS_TEST_ENVIRONMENT.should.not.be.undefined()

test/helper.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { uniqPrefix, parseError } from '../src/helper'
1+
import { parseError, uniqPrefix } from '../src/helper'
22

33
describe('helper uniqPrefix', function() {
44
it('created uniq prefixed', function() {

test/selector.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'should'
22
import { schema } from 'normalizr'
33
import { fromJS } from 'immutable'
44

5-
import { ENTITIES_REDUCER_NAME, ACTIONS_REDUCER_NAME } from '../src/config'
5+
import { ACTIONS_REDUCER_NAME, ENTITIES_REDUCER_NAME } from '../src/config'
66
import {
77
getActionData,
88
getEntityItemsByAction,

0 commit comments

Comments
 (0)