Tivac
Tivac

Reputation: 2573

How to structure falcor router to get all available IDs?

I'm experimenting with using Falcor to front the Guild Wars 2 API and want to use it to show game item details. I'm especially interested in building a router that can use multiple datasources to combine the results of different APIs.

The catch is, Item IDs in Guild Wars 2 aren't contiguous. Here's an example:

[
    1,
    2,
    6,
    11,
    24,
    56,
    ...
]

So I can't just write paths on the client like items[100..120].name because there's almost certainly going to be a bunch of holes in that list.

I've tried adding a route to my router so I can just request items, but that sends it into an infinite loop on the client. You can see that attempt on GitHub.

Any pointers on the correct way to structure this? As I think about it more maybe I want item.id instead?

Upvotes: 4

Views: 685

Answers (2)

Ignatius Andrew
Ignatius Andrew

Reputation: 8258

You can use 'get' API of Falcor, It retrieves multiple values.. You can pass any number of required properties as shown below

var model=new falcor.Model({
             cache:{       
                     genereList:[
                                    {name:"Recently Watched",
                                     titles:[
                                         {id:123,
                                          name: "Ignatius",
                                         rating: 4}
                                     ]    
                                    },
                                    {name:"New Release",
                                     titles:[
                                         {id:124,
                                          name: "Jessy",
                                         rating: 3}
                                     ]    
                                    }
                                ]
                            }

            });
            Getting single value
            model.getValue('genereList[0].titles[0].name').
            then(function(value){
               console.log(value);
           });

            Getting multiple values
            model.get('genereList[0..1].titles[0].name', 'genereList[0..1].titles[0].rating').
            then(function(json){
                console.log(JSON.stringify(json, null, 4));
            })

Upvotes: 0

Jafar Husain
Jafar Husain

Reputation: 46

You shouldn't find your self asking for ids from a Falcor JSON Graph object.

It seems like you want to build an array of game ids:

{
    games: [
        { $type: "ref", value: ["gamesById", 352] },
        { $type: "ref", value: ["gamesById", 428] }
        // ...
    ],
    gamesById: {
        352: {
            gameProp1: ...,
        },
        428: {
            gameProp2: ...
        }
    }
}

[games, {from: 5, to: 17 }, "gameProp1"]

Does that work?

Upvotes: 3

Related Questions