ivarcode / schackmatt

chess website
http://www.schackmatt.net/
8 stars 5 forks source link

investigate why subscribe used this way is "deprecated" to tslint #165

Open ivarcode opened 3 years ago

ivarcode commented 3 years ago

Problem / Catalyst image

Describe the enhancement you'd like Investigate this

cristian-5 commented 3 years ago

According to Angular Docs, the better way to do this is with an object which encapsulates all the different callbacks, instead of passing a bunch of callback functions as parameters. This allows you to refactor and split the callbacks in several class methods if needed; giving you the possibility to have object properties that you can share between callbacks instead of global variables. Neat, isn't it?

https://angular.io/guide/observables https://stackoverflow.com/questions/55472124/subscribe-is-deprecated-use-an-observer-instead-of-an-error-callback

// Create simple observable that emits three values
const myObservable = of(1, 2, 3);

// Create observer object
const myObserver = {
  next: x => console.log('Observer got a next value: ' + x),
  error: err => console.error('Observer got an error: ' + err),
  complete: () => console.log('Observer got a complete notification'),
};

// Execute with the observer object
myObservable.subscribe(myObserver);

// Logs:
// Observer got a next value: 1
// Observer got a next value: 2
// Observer got a next value: 3
// Observer got a complete notification