Search This Blog

Sunday, July 20, 2014

Initializing a list of objects

It is a common pattern to maintain a list of objects.  To maintain the list, you need to add a new object to a list of objects and delete existing objects.  Lists have add and remove methods, but you have to properly initialize the list.
Doesn't Work:
   @ observable List<Object> objects
Works:
  final List<Object> objects = toObservable(new List());

@observable works for numbers and Strings, but not Maps and Lists.

I am working with the YouTube api example from the previous post.  My method of creating objects from the api response does not tolerate missing values.

  1. Short term, I can stop looking for that fields where there are missing values (comments and average rating).
  2. Check if a value exists before trying to assign the value to the object.  Solves the problem, but doesn't feel eloquent of robust.
I am ignoring the offending fields for now because what I want to work on is displaying the list. 

My initial idea is to use the template "repeat" to display the name.  It works after I remember specify the list in the class the contains the list and all the constructors and functions for maintaining the list.  
Example: 
<template repeat="{{class.list}}">

I decided to try <core-list-dart> because I am greedy.
  1. I need to add a selector field.

No comments:

Post a Comment