Skip to content

Commit 426f7f2

Browse files
authored
added option to clear schemas (#62)
1 parent 1d4419f commit 426f7f2

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@shoutem/redux-io",
3-
"version": "3.2.3",
3+
"version": "3.2.4-beta.0",
44
"description": "Action creators, reducers and middleware for simple handling of normalized json api data in state",
55
"main": "index.js",
66
"scripts": {

src/actions/clear.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
REFERENCE_CLEAR,
44
} from './../';
55

6-
export default function clear(schema, tag = '') {
6+
export default function clear(schema, tag = '*') {
77
if (!_.isString(schema)) {
88
throw new Error(`Invalid schema, "clear" expected a string but got: ${JSON.stringify(schema)}`);
99
}

src/reducers/collection.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ function isValidAction(action, schema, tag) {
3535
if (action.type === REFERENCE_STATUS && _.get(action, 'meta.tag') === '*') {
3636
return true;
3737
}
38+
39+
// Every collection should be cleared if action is type of REFERENCE_CLEAR
40+
// and action meta tag is broadcast
41+
if (action.type === REFERENCE_CLEAR && _.get(action, 'meta.tag') === '*') {
42+
return true;
43+
}
44+
3845
return false;
3946
}
4047

src/reducers/one.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ function isValidAction(action, schema, tag) {
3232
if (action.type === REFERENCE_STATUS && _.get(action, 'meta.tag') === '*') {
3333
return true;
3434
}
35+
36+
// Every collection should be cleared if action is type of REFERENCE_CLEAR
37+
// and action meta tag is broadcast
38+
if (action.type === REFERENCE_CLEAR && _.get(action, 'meta.tag') === '*') {
39+
return true;
40+
}
41+
3542
return false;
3643
}
3744

test/actions/clear.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Clear action creator', () => {
2727
type: REFERENCE_CLEAR,
2828
meta: {
2929
schema,
30-
tag: '',
30+
tag: '*',
3131
},
3232
});
3333
});

0 commit comments

Comments
 (0)