@opengeoweb/snackbar 9.15.0 → 9.16.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.
package/index.esm.js CHANGED
@@ -3,8 +3,7 @@ import { useDispatch, useSelector } from 'react-redux';
3
3
  import { CustomIconButton, withEggs } from '@opengeoweb/shared';
4
4
  import { Snackbar } from '@mui/material';
5
5
  import { Close } from '@opengeoweb/theme';
6
- import { createEntityAdapter, createSlice, createSelector } from '@reduxjs/toolkit';
7
- import { takeLatest, select, put, delay } from 'redux-saga/effects';
6
+ import { createEntityAdapter, createSlice, createSelector, createListenerMiddleware } from '@reduxjs/toolkit';
8
7
 
9
8
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
10
9
 
@@ -1104,6 +1103,16 @@ function __rest(s, e) {
1104
1103
  return t;
1105
1104
  }
1106
1105
 
1106
+ function __awaiter(thisArg, _arguments, P, generator) {
1107
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1108
+ return new (P || (P = Promise))(function (resolve, reject) {
1109
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
1110
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
1111
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
1112
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
1113
+ });
1114
+ }
1115
+
1107
1116
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1108
1117
  var e = new Error(message);
1109
1118
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
@@ -1176,9 +1185,9 @@ const slice = createSlice({
1176
1185
  draft,
1177
1186
  // eslint-disable-next-line no-unused-vars
1178
1187
  action) => {},
1179
- // triggerOpenSnackbarBySaga is triggered by the saga to open the snackbar after the current snackbars have all been closed
1188
+ // triggerOpenSnackbarByListener is triggered by the listener to open the snackbar after the current snackbars have all been closed
1180
1189
  // DO NOT CALL THIS ACTION DIRECTLY!
1181
- triggerOpenSnackbarBySaga: (draft, action) => {
1190
+ triggerOpenSnackbarByListener: (draft, action) => {
1182
1191
  const {
1183
1192
  snackbarContent
1184
1193
  } = action.payload;
@@ -1367,31 +1376,37 @@ if (NOT_GENERIC || INCORRECT_NAME) {
1367
1376
  }
1368
1377
 
1369
1378
  const hideTime = 4000;
1370
- function* openSnackbarSaga(capturedAction) {
1371
- const snackbarMessage = capturedAction.payload.message;
1372
- const currentSnackbarMessages = yield select(getCurrentSnackbarMessages);
1373
- // If there are currently opened snackbars we need to close these first
1374
- if (currentSnackbarMessages.length) {
1375
- yield put(snackbarActions.closeSnackbar());
1376
- }
1377
- // Generate a unique id
1378
- const id = `snackbar${Date.now().toString()}`;
1379
- yield put(snackbarActions.triggerOpenSnackbarBySaga({
1380
- snackbarContent: {
1381
- message: snackbarMessage,
1382
- id
1379
+ const snackbarListener = createListenerMiddleware();
1380
+ snackbarListener.startListening({
1381
+ actionCreator: snackbarActions.openSnackbar,
1382
+ effect: ({
1383
+ payload
1384
+ }, listenerApi) => __awaiter(void 0, void 0, void 0, function* () {
1385
+ listenerApi.cancelActiveListeners();
1386
+ const {
1387
+ message: snackbarMessage
1388
+ } = payload;
1389
+ const currentSnackbarMessages = getCurrentSnackbarMessages(listenerApi.getState());
1390
+ // If there are currently opened snackbars we need to close these first
1391
+ if (currentSnackbarMessages.length) {
1392
+ listenerApi.dispatch(snackbarActions.closeSnackbar());
1383
1393
  }
1384
- }));
1385
- // If no new snackbar is triggered cancelling this saga, hide the snackbar after X seconds
1386
- yield delay(hideTime);
1387
- const currentSnackbarMessagesOpen = yield select(getCurrentSnackbarMessages);
1388
- if (currentSnackbarMessagesOpen.length) {
1389
- yield put(snackbarActions.closeSnackbar());
1390
- }
1391
- }
1392
- function* rootSaga() {
1393
- yield takeLatest(snackbarActions.openSnackbar.type, openSnackbarSaga);
1394
- }
1394
+ // Generate a unique id
1395
+ const id = `snackbar${Date.now().toString()}`;
1396
+ listenerApi.dispatch(snackbarActions.triggerOpenSnackbarByListener({
1397
+ snackbarContent: {
1398
+ message: snackbarMessage,
1399
+ id
1400
+ }
1401
+ }));
1402
+ // If no new snackbar is triggered cancelling this listener, hide the snackbar after X seconds
1403
+ yield listenerApi.delay(hideTime);
1404
+ const currentSnackbarMessagesOpen = getCurrentSnackbarMessages(listenerApi.getState());
1405
+ if (currentSnackbarMessagesOpen.length) {
1406
+ listenerApi.dispatch(snackbarActions.closeSnackbar());
1407
+ }
1408
+ })
1409
+ });
1395
1410
 
1396
1411
  /* *
1397
1412
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -1414,7 +1429,7 @@ const snackbarModuleConfig = {
1414
1429
  reducersMap: {
1415
1430
  snackbar: reducer
1416
1431
  },
1417
- sagas: [rootSaga]
1432
+ middlewares: [snackbarListener.middleware]
1418
1433
  };
1419
1434
 
1420
1435
  const SnackbarWrapperConnect = withEggs([snackbarModuleConfig])(props => {
@@ -1431,4 +1446,4 @@ const SnackbarWrapperConnect = withEggs([snackbarModuleConfig])(props => {
1431
1446
  }, props));
1432
1447
  });
1433
1448
 
1434
- export { SnackbarWrapperConnect, snackbarActions, snackbarModuleConfig, reducer as snackbarReducer, rootSaga as snackbarSaga, selectors as snackbarSelectors, types as snackbarTypes };
1449
+ export { SnackbarWrapperConnect, hideTime, snackbarActions, snackbarListener, snackbarModuleConfig, reducer as snackbarReducer, selectors as snackbarSelectors, types as snackbarTypes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/snackbar",
3
- "version": "9.15.0",
3
+ "version": "9.16.0",
4
4
  "description": "GeoWeb snackbar library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -13,8 +13,7 @@
13
13
  "@opengeoweb/shared": "*",
14
14
  "react-redux": "^8.1.3",
15
15
  "@reduxjs/toolkit": "^1.9.7",
16
- "@redux-eggs/core": "^2.2.0",
17
- "redux-saga": "^1.2.3"
16
+ "@redux-eggs/core": "^2.2.0"
18
17
  },
19
18
  "peerDependencies": {
20
19
  "react": "18"
@@ -3,4 +3,4 @@ export * as snackbarSelectors from './selectors';
3
3
  export * as snackbarTypes from './types';
4
4
  export * from './config';
5
5
  export { reducer as snackbarReducer } from './reducer';
6
- export { rootSaga as snackbarSaga } from './sagas';
6
+ export * from './listener';
@@ -0,0 +1,3 @@
1
+ import { SnackbarModuleStore } from './types';
2
+ export declare const hideTime = 4000;
3
+ export declare const snackbarListener: import("@reduxjs/toolkit").ListenerMiddlewareInstance<SnackbarModuleStore, import("@reduxjs/toolkit").ThunkDispatch<SnackbarModuleStore, unknown, import("redux").AnyAction>, unknown>;
@@ -1,11 +1,11 @@
1
1
  import { PayloadAction, Draft } from '@reduxjs/toolkit';
2
- import { OpenSnackbarPayload, SnackbarItem, SnackbarState, TriggerOpenSnackbarBySagaPayload } from './types';
2
+ import { OpenSnackbarPayload, SnackbarItem, SnackbarState, TriggerOpenSnackbarByListenerPayload } from './types';
3
3
  export declare const snackbarAdapter: import("@reduxjs/toolkit").EntityAdapter<SnackbarItem>;
4
4
  export declare const initialState: SnackbarState;
5
5
  export declare const reducer: import("redux").Reducer<SnackbarState, import("redux").AnyAction>;
6
6
  export declare const snackbarActions: import("@reduxjs/toolkit").CaseReducerActions<{
7
7
  openSnackbar: (draft: Draft<SnackbarState>, action: PayloadAction<OpenSnackbarPayload>) => void;
8
- triggerOpenSnackbarBySaga: (draft: Draft<SnackbarState>, action: PayloadAction<TriggerOpenSnackbarBySagaPayload>) => void;
8
+ triggerOpenSnackbarByListener: (draft: Draft<SnackbarState>, action: PayloadAction<TriggerOpenSnackbarByListenerPayload>) => void;
9
9
  closeSnackbar: (draft: Draft<SnackbarState>) => void;
10
10
  }, "snackbar">;
11
- export type SnackbarActions = ReturnType<typeof snackbarActions.openSnackbar> | ReturnType<typeof snackbarActions.triggerOpenSnackbarBySaga> | ReturnType<typeof snackbarActions.closeSnackbar>;
11
+ export type SnackbarActions = ReturnType<typeof snackbarActions.openSnackbar> | ReturnType<typeof snackbarActions.triggerOpenSnackbarByListener> | ReturnType<typeof snackbarActions.closeSnackbar>;
@@ -10,6 +10,6 @@ export interface SnackbarModuleStore {
10
10
  export interface OpenSnackbarPayload {
11
11
  message: string;
12
12
  }
13
- export interface TriggerOpenSnackbarBySagaPayload {
13
+ export interface TriggerOpenSnackbarByListenerPayload {
14
14
  snackbarContent: SnackbarItem;
15
15
  }
@@ -1,5 +0,0 @@
1
- import { SagaIterator } from 'redux-saga';
2
- import { SnackbarActions } from './reducer';
3
- export declare function openSnackbarSaga(capturedAction: SnackbarActions): SagaIterator;
4
- export declare function rootSaga(): SagaIterator;
5
- export default rootSaga;