Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not triggering when splicing #140

Open
mackelito opened this issue Nov 9, 2020 · 2 comments
Open

Not triggering when splicing #140

mackelito opened this issue Nov 9, 2020 · 2 comments

Comments

@mackelito
Copy link

Not sure if it's just me or if this is a bug or not :D

  addToCart(cartArticle: CartArticle) {
    this.cart.articles.push(cartArticle);
    this.refreshExpireDate();
    this._storage.store('cart', this.cart);
  }

  removeFromCart(index: number) {
    this.cart.articles.splice(index, 1);
    this.refreshExpireDate();
    this._storage.store('cart', this.cart);
  }

In both functions I see that the refreshExpireDate does trigger in my service as it is updated in localstorage...

but the subscription I have does not trigger on remove.. only add?

    this.storage.observe('cart').pipe(
      startWith(this.storage.retrieve('cart'))
    ).subscribe(cart => {
      console.log('checkoutpage', cart);
      this.cartSubject.next(cart);
    });
@mackelito
Copy link
Author

Oh.. It must be something with the dirty checking in angular where the object does not change but only the underlaying array..

@mackelito
Copy link
Author

Spoke to soon..
There is something else going on here..

  ngOnInit() {
    this.storage.observe('cart').pipe(
      startWith(this.storage.retrieve('cart'))
    ).subscribe(cart => {
      console.log('summary', cart);
      this.cartSubject.next(cart);
    });
  }

This summary only triggers on the first remove.. but all adds?

@mackelito mackelito reopened this Nov 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant