Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In v0.4.0+, values of type undefined work differently - update documentation #194

Open
camsjams opened this issue Nov 27, 2016 · 0 comments

Comments

@camsjams
Copy link

camsjams commented Nov 27, 2016

Using the todo list samples from the docs, we have the route get handling for genrelist[{integers:indices}].titles[{integers:titleIndices}] from falcor-router-demo here:

 return recommendationService.
        getGenreList(this.userId).
        then(function(genrelist) {
            var pathValues = [];
            pathSet.indices.forEach(function (index) {
                var genre = genrelist[index];
                
                // If we determine that there is no genre at the index, we must
                // be specific and return that it is the genre that is not 
                // present and not the name of the genre.
                if (genre == null) {
                    pathValues.push({
                        path: ['genrelist', index],
                        value: genre
                    });
                } else {
                    pathSet.titleIndices.forEach(function(titleIndex) {
                        var titleID = genrelist[index].titles[titleIndex];

                        if (titleID == null) {
                            pathValues.push({ path: ["genrelist", index, "titles", titleIndex], value: titleID });
                        }
                        else {
                            pathValues.push({
                                path: ['genrelist', index, 'titles', titleIndex],
                                value: $ref(['titlesById', titleID])
                            });
                        }
                    });
                }
            });
            return pathValues;
        });

The issue arises from this loose equality and the eventual usage of titleID:

if (titleID == null) {
    pathValues.push({ path: ["genrelist", index, "titles", titleIndex], value: titleID });
}
// null == null is true
// undefined == null is true

Unfortunately, on falcor-router v0.4.0, it seems that setting value to undefined will prevent the ref lookup, and return back empty data.

Instead this needs to be null.

For those following along with the tutorials, please advise that you will need to coalesce to null, or some other way to ensure that undefined does not make its way into your values!

var titleID = genrelist[index].titles[titleIndex] || null;

The documentation/tutorial does not match implementation anymore, although I can see why this change was made as it makes the value types more JSON-compliant.

@camsjams camsjams changed the title In v0.4.0+, values of type undefined issue where refs are not retrieved In v0.4.0+, values of type undefined work differently Nov 28, 2016
@camsjams camsjams changed the title In v0.4.0+, values of type undefined work differently In v0.4.0+, values of type undefined work differently - update documentation Nov 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant