Generic-user-small David Wilhelm 2 posts

Hey

I was excited to see the new chapters on dojo.data and dojo.declare.. nice to have a thorough analysis.

However I was getting errors with the examples for dojo.data, in particular the ones with the FilteringSelect, that are using the genetox dataset. It was really bothering me, so I dug in to track the bug down….

I figured out that when the ItemFileReadStore was returning a bunch of items, some were failing the ‘isItem’ test and the whole thing blew up with an ‘invalid item’ error. I suspected the data source was the cause of the error, so I hacked away at it until the error went away. The error re-appeared whenever there was an item with an attribute which was an object specifically the results attribute:

results: [ 
  { specimen:"Mouse", 
    result:"Negative" 
  },

So I read through the ItemFileReadStore code to see why this was happening. It turns out that when there’s an item attribute which is an object, it is getting added as an item. However (in this case) these sub-items do not have the specified identifier for the datastore, so these items will fail ‘isItem’ when the time comes.

This behaviour doesn’t seem right to me. I don’t think that all objects in the data set should be added as items, especially if they don’t have the specified identifier. There is a very easy fix for this… don’t add sub-items if they don’t have the identifier.. around line
396 of ItemFileReadStore, in the function valueIsAnItem(aValue) theres this code:
var isItem = ( (aValue != null) && (typeof aValue "object") && (!dojo.isArray(aValue)) && (!dojo.isFunction(aValue)) && (aValue.constructor Object) && (typeof aValue._reference "undefined") && (typeof aValue._type “undefined”) && (typeof aValue._value == “undefined”)
)
return isItem;

now if we add the following to the list of conditions:

&&(dataObject.identifier?aValue[dataObject.identifier]:true)

this will ensure that subItems without the identifier are not loaded as items (but if there’s no identifier it just adds it – not sure if we want this either, but anyways)

So that helped get rid of the “invalid item” error.

But then I was still getting another error which said “missing parenthetical”

If I removed the comment from the beginning of the json file though, this error went away. The filtering select now works happily. So that was my morning… but at least I got to the bottom of it. Hope this helps someone else.

Dave

 
Generic-user-small David Wilhelm 2 posts

just noticed something else

the final ‘null’ value in the genetox dataset is also causing problems because it is not handled by ItemFileReadStore, which tries to add it as an item. Around line 438 in ItemFileReadStore.js

for(i = 0; i < this._arrayOfTopLevelItems.length; ++i){
}
item = this._arrayOfTopLevelItems[i];
if(!item) continue;
addItemAndSubItemsToArrayOfAllItems(item);
item[this._rootItemPropName]=true;

I added the line

if(!item) continue;

to avoid adding null, undefined, or other values which are falsy as items

AFAIK all items should be objects with attributes, which are truthy

 
Generic-user-small Don Albertson 3 posts

This chapter needed a Q/A team to validate it. So far, with 2 titles that I’ve purchased I’m deeply disappointed in the Pragmatic series. Neither one would qualify as a shippable product.

 
Official_photo_small Craig Riecke 17 posts

We did Q/A, but unfortunately just a bit too early. Part of the release process for the code was to add the boilerplate copyright notices to each file. We didn’t think to do Q/A after that – after all, it’s just a comment, right? Turns out this confuses Dojo in a few places simply because some files that look like code are in fact data. JSON is a perfect example.

I’ll try to get this into the Q/A process for Pragmatic Books in general.

4 posts, 3 voices