Skip to content

Commit

Permalink
PB-984: upgrade to equality check in messages
Browse files Browse the repository at this point in the history
- We now dive into the params to check that they have the same length, the same keys, and the same values.
  • Loading branch information
ltkum committed Oct 10, 2024
1 parent 9f4b60a commit be77afb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
22 changes: 10 additions & 12 deletions src/store/modules/ui.store.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,12 +394,11 @@ export default {
errors instanceof Array &&
errors.filter((error) => error instanceof ErrorMessage).length === errors.length
) {
errors = errors.filter(
(error) =>
// we only add the errors that are not existing within the store
[...state.errors].filter((otherError) => {
error.isEquals(otherError)
}).length === 0
errors = errors.filter((error) =>
// we only add the errors that are not existing within the store
[...state.errors].some((otherError) => {
error.isEquals(otherError)
})
)
if (errors.length > 0) {
commit('addErrors', { errors, dispatcher })
Expand Down Expand Up @@ -427,12 +426,11 @@ export default {
warnings.filter((warning) => warning instanceof WarningMessage).length ===
warnings.length
) {
warnings = warnings.filter(
(warning) =>
// we only add the warnings that are not existing within the store
[...state.warnings].filter((otherWarning) => {
warning.isEquals(otherWarning)
}).length === 0
warnings = warnings.filter((warning) =>
// we only add the warnings that are not existing within the store
[...state.warnings].some((otherWarning) => {
warning.isEquals(otherWarning)
})
)
if (warnings.length > 0) {
commit('addWarnings', { warnings, dispatcher })
Expand Down
8 changes: 6 additions & 2 deletions src/utils/ErrorMessage.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ export default class ErrorMessage {
*/
constructor(msg, params = null) {
this.msg = msg
this.params = params
this.params = params ?? {}
}

isEquals(object) {
return (
object instanceof ErrorMessage &&
object.msg === this.msg &&
object.params === this.params
Object.keys(this.params).every(
(key) =>
Object.keys(object.params).includes(key) &&
this.params[key] === object.params[key]
)
)
}
}
8 changes: 6 additions & 2 deletions src/utils/WarningMessage.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ export default class WarningMessage {
*/
constructor(msg, params = null) {
this.msg = msg
this.params = params
this.params = params ?? {}
}

isEquals(object) {
return (
object instanceof WarningMessage &&
object.msg === this.msg &&
object.params === this.params
Object.keys(this.params).every(
(key) =>
Object.keys(object.params).includes(key) &&
this.params[key] === object.params[key]
)
)
}
}

0 comments on commit be77afb

Please sign in to comment.