-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
libs/generic-view/store/src/lib/entities/refresh-entities-if-metadata-changed.action.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright (c) Mudita sp. z o.o. All rights reserved. | ||
* For licensing, see https://github.com/mudita/mudita-center/blob/master/LICENSE.md | ||
*/ | ||
|
||
import { createAsyncThunk } from "@reduxjs/toolkit" | ||
import { ReduxRootState } from "Core/__deprecated__/renderer/store" | ||
import { ActionName } from "../action-names" | ||
import { getEntitiesMetadataAction } from "./get-entities-metadata.action" | ||
import { selectEntitiesMetadata } from "../selectors" | ||
import { getEntitiesDataAction } from "./get-entities-data.action" | ||
import { EntitiesMetadata } from "Libs/device/models/src" | ||
|
||
export const refreshEntitiesIfMetadataChanged = createAsyncThunk< | ||
void, | ||
{ deviceId: string; entitiesType: string }, | ||
{ state: ReduxRootState } | ||
>( | ||
ActionName.RefreshEntitiesIfMetadataChanged, | ||
async ( | ||
{ deviceId, entitiesType }, | ||
{ dispatch, getState, rejectWithValue } | ||
) => { | ||
if (!deviceId) { | ||
return rejectWithValue(undefined) | ||
} | ||
|
||
const currentMetadata = selectEntitiesMetadata(getState(), { | ||
deviceId, | ||
entitiesType, | ||
}) | ||
|
||
const metadata = await dispatch( | ||
getEntitiesMetadataAction({ deviceId, entitiesType }) | ||
) | ||
|
||
if ( | ||
currentMetadata?.uniqueKey !== | ||
(metadata.payload as EntitiesMetadata)?.uniqueKey | ||
) { | ||
dispatch(getEntitiesDataAction({ deviceId, entitiesType })) | ||
} | ||
|
||
return | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters