troyanskiy / ngx-resource

Resource (REST) Client for Angular 2
http://troyanskiy.github.io/ngx-resource/
200 stars 46 forks source link

Inconsistency between `$observable` and `$observable.toPromise()` #129

Closed marshall007 closed 7 years ago

marshall007 commented 7 years ago

I would expect the following two examples to be equivalent, but it seems that when using toPromise, the result is still a wrapped ResourceResult:

resource.get({ id: '123' }).$observable.subscribe(
  (value) => this.data = value // T
)

resource.get({ id: '123' }).$observable.toPromise().then(
  (value) => this.data = value // ResourceResult<T>
)
marshall007 commented 7 years ago

Somewhat related, there appears to be a possible race condition when using resource.save(...) which prevents $cleanData(...) from being called before the request is sent.

troyanskiy commented 7 years ago

For me both are same

this._u.testGet()
      .$observable
      .subscribe((data: any) => {
        console.log('Data 1', data);
      });

    this._u.testGet()
      .$observable
      .toPromise()
      .then((data: any) => {
        console.log('Data 2', data);
      });

image

troyanskiy commented 7 years ago

Could you please provide plunker example to debug the Inconsistency between $observable and $observable.toPromise()

Thanks

marshall007 commented 7 years ago

@troyanskiy not sure what was going on before, but I can't reproduce this again. Also updating to v3.2.4 seems to have fixed $ properties being included in POST requests.