Skip to content

Commit db4811b

Browse files
committed
Use prefix to meta data name to avoid conflict
1 parent 7347cc7 commit db4811b

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/actions.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const keep = createAction(KEEP);
1616
export const content = createAction(CONTENT);
1717
export const place = createAction(PLACE);
1818

19+
export const DELAY = prefix('delay');
1920
const DEFAULT_DURATION = 1500;
2021
export function delay(action, duration = DEFAULT_DURATION) {
2122
if (!action.meta) {
@@ -24,7 +25,7 @@ export function delay(action, duration = DEFAULT_DURATION) {
2425
if (duration === true) {
2526
duration = DEFAULT_DURATION;
2627
}
27-
action.meta.delay = parseInt(duration);
28+
action.meta[DELAY] = parseInt(duration);
2829
return action;
2930
}
3031

src/middleware.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { startTimeout, endTimeout } from './actions';
1+
import { startTimeout, endTimeout, DELAY } from './actions';
22
import { resolve } from './utils';
33

44
function getToken(state, name) {
@@ -18,7 +18,7 @@ export default function middleware(store) {
1818
token && clearTimeout(token);
1919
});
2020

21-
if (!action.meta || !action.meta.delay) {
21+
if (!action.meta || !action.meta[DELAY]) {
2222
return next(action);
2323
}
2424

@@ -32,10 +32,10 @@ export default function middleware(store) {
3232
next(endTimeout({ name }));
3333

3434
// Dispatch original action
35-
delete action.meta['delay'];
35+
delete action.meta[DELAY];
3636
next(action);
3737
}
38-
}, action.meta.delay);
38+
}, action.meta[DELAY]);
3939

4040
// Store timeout token
4141
next(startTimeout({ name, token: newToken }));

tests/unit/test_actions.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('actions', () => {
1818
value: 123
1919
},
2020
meta: {
21-
delay: 1500,
21+
'redux-tooltip/delay': 1500,
2222
}
2323
});
2424
});
@@ -47,7 +47,7 @@ describe('actions', () => {
4747
},
4848
meta: {
4949
gem: 'bundler',
50-
delay: 1500,
50+
'redux-tooltip/delay': 1500,
5151
}
5252
});
5353
});

0 commit comments

Comments
 (0)