I have action, which add new object to a store:
let warning = {message: 'some text', status: 'suspended'}
this.store.dispatch(new WarningActions.AddWarning(warning))
but if I already have the same warning, I don't want to add it again, so I tried to check store before dispatch it:
this.store.select('warning').subscribe(warnings => {
console.log(warnings) // [{message: 'some text', status: 'suspended'}]
if (warnings.indexOf(warning) === -1) {
this.store.dispatch(new WarningActions.AddWarning(warning))
}
})
But this is does not work, because warnings.indexOf(warning) === -1
always yields true, even if I already have exactly the same object. What I did wrong and how I can solve this?