@commercetools-frontend/notifications 21.23.9 → 21.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,8 +14,6 @@ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
14
14
  var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
15
15
  var _Map = require('@babel/runtime-corejs3/core-js-stable/map');
16
16
  var _setTimeout = require('@babel/runtime-corejs3/core-js-stable/set-timeout');
17
- var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
18
- var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
19
17
 
20
18
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
21
19
 
@@ -30,16 +28,15 @@ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defin
30
28
  var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
31
29
  var _Map__default = /*#__PURE__*/_interopDefault(_Map);
32
30
  var _setTimeout__default = /*#__PURE__*/_interopDefault(_setTimeout);
33
- var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
34
31
 
35
32
  // NOTE: This string will be replaced on build time with the package version.
36
- var version = "21.23.9";
33
+ var version = "21.24.0";
37
34
 
38
- var ADD_NOTIFICATION = 'ADD_NOTIFICATION';
39
- var REMOVE_NOTIFICATION = 'REMOVE_NOTIFICATION';
35
+ const ADD_NOTIFICATION = 'ADD_NOTIFICATION';
36
+ const REMOVE_NOTIFICATION = 'REMOVE_NOTIFICATION';
40
37
 
41
38
  function addNotification(notification, meta) {
42
- var action = {
39
+ const action = {
43
40
  type: ADD_NOTIFICATION,
44
41
  payload: notification
45
42
  };
@@ -50,7 +47,7 @@ function removeNotification(id) {
50
47
  return {
51
48
  type: REMOVE_NOTIFICATION,
52
49
  payload: {
53
- id: id
50
+ id
54
51
  }
55
52
  };
56
53
  }
@@ -59,82 +56,77 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["def
59
56
 
60
57
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
61
58
 
62
- var isNotificationAction = function isNotificationAction(action) {
59
+ // Force TS cast of generic action to TNotificationAction
60
+ const isNotificationAction = action => {
63
61
  var _context;
64
62
 
65
63
  return _includesInstanceProperty__default["default"](_context = [ADD_NOTIFICATION, REMOVE_NOTIFICATION]).call(_context, action.type);
66
64
  };
67
65
 
68
- var dismissCallbacksMap = new _Map__default["default"]();
69
- var id = 0;
66
+ const dismissCallbacksMap = new _Map__default["default"]();
67
+ let id = 0;
70
68
 
71
- var middleware = function middleware(_ref) {
72
- var dispatch = _ref.dispatch;
73
- return function (next) {
74
- return function (action) {
75
- if (!isNotificationAction(action)) {
76
- return next(action);
77
- }
78
-
79
- switch (action.type) {
80
- case ADD_NOTIFICATION:
81
- {
82
- id += 1;
83
-
84
- var notification = _objectSpread(_objectSpread({}, action.payload), {}, {
85
- id: id
86
- });
69
+ const middleware = _ref => {
70
+ let dispatch = _ref.dispatch;
71
+ return next => action => {
72
+ if (!isNotificationAction(action)) {
73
+ return next(action);
74
+ }
87
75
 
88
- var dismissCallback = function dismissCallback() {
89
- dispatch(removeNotification(notification.id));
90
- };
76
+ switch (action.type) {
77
+ case ADD_NOTIFICATION:
78
+ {
79
+ id += 1;
91
80
 
92
- if (action.meta) {
93
- if (action.meta.dismissAfter) _setTimeout__default["default"](dismissCallback, action.meta.dismissAfter);
94
- if (typeof action.meta.onDismiss === 'function') dismissCallbacksMap.set(notification.id, action.meta.onDismiss);
95
- }
81
+ const notification = _objectSpread(_objectSpread({}, action.payload), {}, {
82
+ id
83
+ });
96
84
 
97
- var nextAction = _objectSpread(_objectSpread({}, action), {}, {
98
- payload: notification,
99
- dismiss: dismissCallback
100
- });
85
+ const dismissCallback = () => {
86
+ dispatch(removeNotification(notification.id));
87
+ };
101
88
 
102
- return next(nextAction);
89
+ if (action.meta) {
90
+ if (action.meta.dismissAfter) _setTimeout__default["default"](dismissCallback, action.meta.dismissAfter);
91
+ if (typeof action.meta.onDismiss === 'function') dismissCallbacksMap.set(notification.id, action.meta.onDismiss);
103
92
  }
104
93
 
105
- case REMOVE_NOTIFICATION:
106
- {
107
- var notificationId = action.payload.id;
108
- var callback = dismissCallbacksMap.get(notificationId);
109
- if (callback) callback(notificationId);
110
- dismissCallbacksMap.delete(notificationId);
111
- return next(action);
112
- }
94
+ const nextAction = _objectSpread(_objectSpread({}, action), {}, {
95
+ payload: notification,
96
+ dismiss: dismissCallback
97
+ });
113
98
 
114
- default:
99
+ return next(nextAction);
100
+ }
101
+
102
+ case REMOVE_NOTIFICATION:
103
+ {
104
+ const notificationId = action.payload.id;
105
+ const callback = dismissCallbacksMap.get(notificationId);
106
+ if (callback) callback(notificationId);
107
+ dismissCallbacksMap.delete(notificationId);
115
108
  return next(action);
116
- }
117
- };
109
+ }
110
+
111
+ default:
112
+ return next(action);
113
+ }
118
114
  };
119
115
  };
120
116
 
121
117
  function notificationsReducer() {
122
- var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
123
- var action = arguments.length > 1 ? arguments[1] : undefined;
118
+ let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
119
+ let action = arguments.length > 1 ? arguments[1] : undefined;
124
120
  if (!action || !action.type) return state;
125
121
 
126
122
  switch (action.type) {
127
123
  case ADD_NOTIFICATION:
128
124
  {
129
- var _context;
130
-
131
- return _concatInstanceProperty__default["default"](_context = [action.payload]).call(_context, _toConsumableArray(state));
125
+ return [action.payload, ...state];
132
126
  }
133
127
 
134
128
  case REMOVE_NOTIFICATION:
135
- return _filterInstanceProperty__default["default"](state).call(state, function (notification) {
136
- return action.payload.id !== notification.id;
137
- });
129
+ return _filterInstanceProperty__default["default"](state).call(state, notification => action.payload.id !== notification.id);
138
130
 
139
131
  default:
140
132
  return state;
@@ -14,8 +14,6 @@ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
14
14
  var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
15
15
  var _Map = require('@babel/runtime-corejs3/core-js-stable/map');
16
16
  var _setTimeout = require('@babel/runtime-corejs3/core-js-stable/set-timeout');
17
- var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
18
- var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
19
17
 
20
18
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
21
19
 
@@ -30,16 +28,15 @@ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defin
30
28
  var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
31
29
  var _Map__default = /*#__PURE__*/_interopDefault(_Map);
32
30
  var _setTimeout__default = /*#__PURE__*/_interopDefault(_setTimeout);
33
- var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
34
31
 
35
32
  // NOTE: This string will be replaced on build time with the package version.
36
- var version = "21.23.9";
33
+ var version = "21.24.0";
37
34
 
38
- var ADD_NOTIFICATION = 'ADD_NOTIFICATION';
39
- var REMOVE_NOTIFICATION = 'REMOVE_NOTIFICATION';
35
+ const ADD_NOTIFICATION = 'ADD_NOTIFICATION';
36
+ const REMOVE_NOTIFICATION = 'REMOVE_NOTIFICATION';
40
37
 
41
38
  function addNotification(notification, meta) {
42
- var action = {
39
+ const action = {
43
40
  type: ADD_NOTIFICATION,
44
41
  payload: notification
45
42
  };
@@ -50,7 +47,7 @@ function removeNotification(id) {
50
47
  return {
51
48
  type: REMOVE_NOTIFICATION,
52
49
  payload: {
53
- id: id
50
+ id
54
51
  }
55
52
  };
56
53
  }
@@ -59,82 +56,77 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["def
59
56
 
60
57
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
61
58
 
62
- var isNotificationAction = function isNotificationAction(action) {
59
+ // Force TS cast of generic action to TNotificationAction
60
+ const isNotificationAction = action => {
63
61
  var _context;
64
62
 
65
63
  return _includesInstanceProperty__default["default"](_context = [ADD_NOTIFICATION, REMOVE_NOTIFICATION]).call(_context, action.type);
66
64
  };
67
65
 
68
- var dismissCallbacksMap = new _Map__default["default"]();
69
- var id = 0;
66
+ const dismissCallbacksMap = new _Map__default["default"]();
67
+ let id = 0;
70
68
 
71
- var middleware = function middleware(_ref) {
72
- var dispatch = _ref.dispatch;
73
- return function (next) {
74
- return function (action) {
75
- if (!isNotificationAction(action)) {
76
- return next(action);
77
- }
78
-
79
- switch (action.type) {
80
- case ADD_NOTIFICATION:
81
- {
82
- id += 1;
83
-
84
- var notification = _objectSpread(_objectSpread({}, action.payload), {}, {
85
- id: id
86
- });
69
+ const middleware = _ref => {
70
+ let dispatch = _ref.dispatch;
71
+ return next => action => {
72
+ if (!isNotificationAction(action)) {
73
+ return next(action);
74
+ }
87
75
 
88
- var dismissCallback = function dismissCallback() {
89
- dispatch(removeNotification(notification.id));
90
- };
76
+ switch (action.type) {
77
+ case ADD_NOTIFICATION:
78
+ {
79
+ id += 1;
91
80
 
92
- if (action.meta) {
93
- if (action.meta.dismissAfter) _setTimeout__default["default"](dismissCallback, action.meta.dismissAfter);
94
- if (typeof action.meta.onDismiss === 'function') dismissCallbacksMap.set(notification.id, action.meta.onDismiss);
95
- }
81
+ const notification = _objectSpread(_objectSpread({}, action.payload), {}, {
82
+ id
83
+ });
96
84
 
97
- var nextAction = _objectSpread(_objectSpread({}, action), {}, {
98
- payload: notification,
99
- dismiss: dismissCallback
100
- });
85
+ const dismissCallback = () => {
86
+ dispatch(removeNotification(notification.id));
87
+ };
101
88
 
102
- return next(nextAction);
89
+ if (action.meta) {
90
+ if (action.meta.dismissAfter) _setTimeout__default["default"](dismissCallback, action.meta.dismissAfter);
91
+ if (typeof action.meta.onDismiss === 'function') dismissCallbacksMap.set(notification.id, action.meta.onDismiss);
103
92
  }
104
93
 
105
- case REMOVE_NOTIFICATION:
106
- {
107
- var notificationId = action.payload.id;
108
- var callback = dismissCallbacksMap.get(notificationId);
109
- if (callback) callback(notificationId);
110
- dismissCallbacksMap.delete(notificationId);
111
- return next(action);
112
- }
94
+ const nextAction = _objectSpread(_objectSpread({}, action), {}, {
95
+ payload: notification,
96
+ dismiss: dismissCallback
97
+ });
113
98
 
114
- default:
99
+ return next(nextAction);
100
+ }
101
+
102
+ case REMOVE_NOTIFICATION:
103
+ {
104
+ const notificationId = action.payload.id;
105
+ const callback = dismissCallbacksMap.get(notificationId);
106
+ if (callback) callback(notificationId);
107
+ dismissCallbacksMap.delete(notificationId);
115
108
  return next(action);
116
- }
117
- };
109
+ }
110
+
111
+ default:
112
+ return next(action);
113
+ }
118
114
  };
119
115
  };
120
116
 
121
117
  function notificationsReducer() {
122
- var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
123
- var action = arguments.length > 1 ? arguments[1] : undefined;
118
+ let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
119
+ let action = arguments.length > 1 ? arguments[1] : undefined;
124
120
  if (!action || !action.type) return state;
125
121
 
126
122
  switch (action.type) {
127
123
  case ADD_NOTIFICATION:
128
124
  {
129
- var _context;
130
-
131
- return _concatInstanceProperty__default["default"](_context = [action.payload]).call(_context, _toConsumableArray(state));
125
+ return [action.payload, ...state];
132
126
  }
133
127
 
134
128
  case REMOVE_NOTIFICATION:
135
- return _filterInstanceProperty__default["default"](state).call(state, function (notification) {
136
- return action.payload.id !== notification.id;
137
- });
129
+ return _filterInstanceProperty__default["default"](state).call(state, notification => action.payload.id !== notification.id);
138
130
 
139
131
  default:
140
132
  return state;
@@ -10,17 +10,15 @@ import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
10
10
  import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
11
11
  import _Map from '@babel/runtime-corejs3/core-js-stable/map';
12
12
  import _setTimeout from '@babel/runtime-corejs3/core-js-stable/set-timeout';
13
- import _toConsumableArray from '@babel/runtime-corejs3/helpers/esm/toConsumableArray';
14
- import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
15
13
 
16
14
  // NOTE: This string will be replaced on build time with the package version.
17
- var version = "21.23.9";
15
+ var version = "21.24.0";
18
16
 
19
- var ADD_NOTIFICATION = 'ADD_NOTIFICATION';
20
- var REMOVE_NOTIFICATION = 'REMOVE_NOTIFICATION';
17
+ const ADD_NOTIFICATION = 'ADD_NOTIFICATION';
18
+ const REMOVE_NOTIFICATION = 'REMOVE_NOTIFICATION';
21
19
 
22
20
  function addNotification(notification, meta) {
23
- var action = {
21
+ const action = {
24
22
  type: ADD_NOTIFICATION,
25
23
  payload: notification
26
24
  };
@@ -31,7 +29,7 @@ function removeNotification(id) {
31
29
  return {
32
30
  type: REMOVE_NOTIFICATION,
33
31
  payload: {
34
- id: id
32
+ id
35
33
  }
36
34
  };
37
35
  }
@@ -40,82 +38,77 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (
40
38
 
41
39
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
42
40
 
43
- var isNotificationAction = function isNotificationAction(action) {
41
+ // Force TS cast of generic action to TNotificationAction
42
+ const isNotificationAction = action => {
44
43
  var _context;
45
44
 
46
45
  return _includesInstanceProperty(_context = [ADD_NOTIFICATION, REMOVE_NOTIFICATION]).call(_context, action.type);
47
46
  };
48
47
 
49
- var dismissCallbacksMap = new _Map();
50
- var id = 0;
48
+ const dismissCallbacksMap = new _Map();
49
+ let id = 0;
51
50
 
52
- var middleware = function middleware(_ref) {
53
- var dispatch = _ref.dispatch;
54
- return function (next) {
55
- return function (action) {
56
- if (!isNotificationAction(action)) {
57
- return next(action);
58
- }
59
-
60
- switch (action.type) {
61
- case ADD_NOTIFICATION:
62
- {
63
- id += 1;
64
-
65
- var notification = _objectSpread(_objectSpread({}, action.payload), {}, {
66
- id: id
67
- });
51
+ const middleware = _ref => {
52
+ let dispatch = _ref.dispatch;
53
+ return next => action => {
54
+ if (!isNotificationAction(action)) {
55
+ return next(action);
56
+ }
68
57
 
69
- var dismissCallback = function dismissCallback() {
70
- dispatch(removeNotification(notification.id));
71
- };
58
+ switch (action.type) {
59
+ case ADD_NOTIFICATION:
60
+ {
61
+ id += 1;
72
62
 
73
- if (action.meta) {
74
- if (action.meta.dismissAfter) _setTimeout(dismissCallback, action.meta.dismissAfter);
75
- if (typeof action.meta.onDismiss === 'function') dismissCallbacksMap.set(notification.id, action.meta.onDismiss);
76
- }
63
+ const notification = _objectSpread(_objectSpread({}, action.payload), {}, {
64
+ id
65
+ });
77
66
 
78
- var nextAction = _objectSpread(_objectSpread({}, action), {}, {
79
- payload: notification,
80
- dismiss: dismissCallback
81
- });
67
+ const dismissCallback = () => {
68
+ dispatch(removeNotification(notification.id));
69
+ };
82
70
 
83
- return next(nextAction);
71
+ if (action.meta) {
72
+ if (action.meta.dismissAfter) _setTimeout(dismissCallback, action.meta.dismissAfter);
73
+ if (typeof action.meta.onDismiss === 'function') dismissCallbacksMap.set(notification.id, action.meta.onDismiss);
84
74
  }
85
75
 
86
- case REMOVE_NOTIFICATION:
87
- {
88
- var notificationId = action.payload.id;
89
- var callback = dismissCallbacksMap.get(notificationId);
90
- if (callback) callback(notificationId);
91
- dismissCallbacksMap.delete(notificationId);
92
- return next(action);
93
- }
76
+ const nextAction = _objectSpread(_objectSpread({}, action), {}, {
77
+ payload: notification,
78
+ dismiss: dismissCallback
79
+ });
94
80
 
95
- default:
81
+ return next(nextAction);
82
+ }
83
+
84
+ case REMOVE_NOTIFICATION:
85
+ {
86
+ const notificationId = action.payload.id;
87
+ const callback = dismissCallbacksMap.get(notificationId);
88
+ if (callback) callback(notificationId);
89
+ dismissCallbacksMap.delete(notificationId);
96
90
  return next(action);
97
- }
98
- };
91
+ }
92
+
93
+ default:
94
+ return next(action);
95
+ }
99
96
  };
100
97
  };
101
98
 
102
99
  function notificationsReducer() {
103
- var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
104
- var action = arguments.length > 1 ? arguments[1] : undefined;
100
+ let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
101
+ let action = arguments.length > 1 ? arguments[1] : undefined;
105
102
  if (!action || !action.type) return state;
106
103
 
107
104
  switch (action.type) {
108
105
  case ADD_NOTIFICATION:
109
106
  {
110
- var _context;
111
-
112
- return _concatInstanceProperty(_context = [action.payload]).call(_context, _toConsumableArray(state));
107
+ return [action.payload, ...state];
113
108
  }
114
109
 
115
110
  case REMOVE_NOTIFICATION:
116
- return _filterInstanceProperty(state).call(state, function (notification) {
117
- return action.payload.id !== notification.id;
118
- });
111
+ return _filterInstanceProperty(state).call(state, notification => action.payload.id !== notification.id);
119
112
 
120
113
  default:
121
114
  return state;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/notifications",
3
- "version": "21.23.9",
3
+ "version": "21.24.0",
4
4
  "description": "A general-purpose notification system built on top of redux",
5
5
  "bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
6
6
  "repository": {