traverson/traverson-angular

Following multiple link relations from a resource.

patrickjuchli opened this issue · 3 comments

In vanilla traverson, I've been successfully using traversal.continue() to follow multiple link relations from a resource.

I have problems doing the same thing with traverson-angular. I'm following the documentation on traverson-angular for continuing a link traversal but I get stuck when I try to create two different continuations from an initial request.

Am I doing something wrong with cloning the request builder? Following the documentation:

   request.continue().then(function(request) {
       request.follow("my-resource")
       ...

This works as expected. As a next step, I want to clone the request builder with newRequest() in order two launch two seperate requests based on the initial one:

   request.continue().then(function(request) {
        var clonedRequest = request.newRequest();
        clonedRequest.follow("my-resource")
        ...

This is not working, what am I missing?

Update:
Looking at clonedRequest above, its property continuation is null. Copying the continuation property of the request over to clonedRequest makes everything work as expected:

request.continue().then(function(request) {
     var branch1 = request.newRequest();
     var branch2 = request.newRequest();
     branch1.continuation = request.continuation;
     branch2.continuation = request.continuation;

     branch1.follow("my-nested-resource")
     ...

     branch2.follow("my-other-nested-resource")
     ...

Works. Is this a possible bug fix?

Yeah, right. Seems I promised too much regarding the combination of continue() and newRequest() in the docs without testing it :-(

I wonder why this worked for you in vanilla traverson? Or didn't you use newRequest() on the continued traversal when testing with vanilla? Because for me, it looks like this was broken in traverson already.

Anyway, a fix landed in traverson@2.0.1 and traverson-angular@2.1.2 includes traverson@2.0.1, so it also has this fix.

You are right, I wasn't using newRequest() at all when you using plain traverson. Somehow it still worked just using traversal.continue().follow... multiple times. Well, at least I now learned how to use Traverson correctly. Thanks a lot for the fix!