Using findLocal on an empty store

Dear Enyo Devs,

I'm feeding data into my at application startup time, using Ajax. However, I cannot guarantee that the data is accessed only after it has been added - if the user uses the search before the Ajax call succeeded, currently what happens is:
Uncaught TypeError: Cannot read property '42' of undefined 
To reproduce, please take a look at
If you call addData before getData, everything is fine. If you do it the other way 'round, you get the TypeError.

I think that findLocal should handle the case where the collection is still empty more graceful...


  • Hi @mephinet, first I'd like to thank you for notifying us of the issue and adding that helpful jsfiddle example. I agree with your assessment that this situation should be more gracefully handled and have entered a Jira for the issue which you can track I'll just note that in the future putting this information in a bug report (including that helpful example) would probably speed the resolution up a bit. But again, thanks for the report.
  • I also wanted to point out a few things that you may/may-not be aware of but wanted to make sure were clear.

    In your jsfiddle example your getData method will fail even in a case where an error isn't thrown in the Store. This is because the code as it exists assumes that a record will always be returned but this isn't the case. While the Store will gracefully fail it will return undefined (as intended for requests to find by primaryKey or euid) if it cannot find the requested entry. So any code using this will still need to ensure that a record was returned prior to using it OR you could overload the Store method (or your own proxy method) to create the record when it doesn't exist but that implementation would be up to you.

    The other thing just to note is your example goes out of its way to access the 'store' property of the Collection instance but unless you've assigned a different Store instance it will be a reference to the globally available root Store '' that you could access instead. Of course this isn't always appropriate but I wanted to make sure you knew about that.
  • Thanks, Cole, for your comments and for fixing the issue (verified with today's nightly). I'll open an Jira next time I'm sure I've found an issue... Regarding your comments to the code: thanks, I'm aware of the shortcomings of that snippet, my production code is cleaner ;-)
Sign In or Register to comment.