Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the difference between ngrx states after another action completes?

Is there any way to find out how can I get the difference between previous and current state in ngrx.

This would be really helpful, thanks in advance.

like image 927
Abhishek Gangwar Avatar asked Oct 19 '25 15:10

Abhishek Gangwar


1 Answers

I personally use a select, like

let state = store.select(['reducer', 'state']); 

and subscribe to the state change

state.takeLast(2).subscribe((result: any[]) => {
  for (let x of result) {
    if (result[x - 1] && (result[x] someCondition result[x - 1])){
      doSomething
    }
  }
})

then just do your simple conditional stuff and viola!

rxjs operators are plentiful and are awesome (like last() or takeLast() for instance)

EDIT just noticed the question and title are a bit different. But you can basically if you dispatch to a state that is used for different actions, the pub/sub method above will still work

like image 86
BSchnitzel Avatar answered Oct 22 '25 03:10

BSchnitzel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!