deblockt / hal-rest-client

Typescript HAL Rest client
Apache License 2.0
25 stars 11 forks source link

Force data updating using HalRestClient fetchArray #30

Closed YanaHoncharova closed 5 years ago

YanaHoncharova commented 6 years ago

Hello,

It would be useful to add possibility to force data updating when using HalRestClient fetchArray method. (Currently there is a force param in HalResouce fetch method that do the trick.)

I've faced with an issue related to this updating. When I retrieve data using HalRestClient fetchArray method, I expect to see new response each time, but instead I recieve partly updated one with cached properties from previous call.

deblockt commented 6 years ago

Can you provide a sample code to reproduce the issue (With server response example)? There are no force option for fetchArray because there are no cache on fetchArray.

YanaHoncharova commented 6 years ago

For example first server response is something like:

value: 1
_embedded: 
    'list': 
        0: {
            name: 'FirstName';
            _embedded: 
                Done: {
                    count: 1;
                    _links....
                }
        }

Second one:

value: 1
_embedded: 
    'list': 
        0: {
            name: 'FirstName';
            _embedded: 
                Testing: {
                    count: 1;
                    _links....
                }
        }

And here is example how I fetch it every time:

this.halClient.fetchArray(some.uri.uri, OurModel)
    .then(data => {})

And in the data after second response I get in props both: Done and Testing. As if response was:

value: 1
_embedded: 
    'list': 
        0: {
            name: 'FirstName';
            _embedded: 
               Done: {
                    count: 1;
                    _links....
                }
               Testing: {
                    count: 1;
                    _links....
                }
        }

resetCache() before fetchArray helps.

EvgeniyReznichenko commented 6 years ago

Same issue... I fetchArray the list of Entries, then I update a single Entry, then refresh the list by fetching the array again.

NOTE: Each Entry has an unique list of links available, depends on it's state.

As a result - after the Entry was updated and the new array was fetched again, the corresponding Entry contains the links (which it must not has anymore) Despite the fact that the server output does not send them

deblockt commented 5 years ago

@EvgeniyReznichenko @YanaHoncharova can you try with 0.5.0 version.

I must be fix

YanaHoncharova commented 5 years ago

I have tried with 0.5.0 version and everything works fine. Thank you.

But also I've faced another thing:

  1. Fetch parent resource and show it in ui.
  2. Fetch child resouce which has parent as embedded staying on the same ui.
  3. Errors in browser like "Cannot read property 'somename' of undefined" for parent.

As I understand, on fetching child resource parent is reseted. And than created with key-value pairs from new server response. But in embedded object there are less parent properties, than we recieved previously from fetching parent. And as we use parent resource for our ui directly, the problem occure.

Could you suggest something?

deblockt commented 5 years ago

@YanaHoncharova I have create a new issue #40