jcassee / angular-hypermedia

Hypermedia REST API client for AngularJS applications
MIT License
38 stars 5 forks source link

Cannot refresh resources and it's reachable paths #30

Closed mvcatsifma closed 8 years ago

mvcatsifma commented 8 years ago

The resource api will not let us refresh a resource and all it's reachable paths from the server. A kind of loadPaths that gets the resources and it's reachable paths, while still honouring embedded resources.

context.refresh gets all resources in the context from the server, leading to unnecessary requests.

jcassee commented 8 years ago

The implementation could be something like this: (not tested)

Resource.$load:

      $load: {value: function (ts) {
        if (!this.$syncTime || (ts && this.$syncTime < ts)) {
          return this.$context.httpGet(this);
        } else {
          return $q.when(this);
        }
      }},

(Not too sure about the conditional here, but you get the point.)

Context.refresh:

      refresh: {value: function (ts) {
        if (!ts) ts = Date.now();
        var promises = [];
        angular.forEach(this.resources, function (resource) {
          if (resource.$isSynced) {
            promises.push(resource.$load(ts));
          }
        });
        return $q.all(promises);
      }},
jcassee commented 8 years ago

@mvcatsifma Is this still an issue?

mvcatsifma commented 8 years ago

@jcassee Ja, en ik wil deze week de implementatie doen.

jcassee commented 8 years ago

Fixed by #31.