Skip to content

Instantly share code, notes, and snippets.

@lucperkins
Created January 27, 2014 03:06
Show Gist options
  • Save lucperkins/8642707 to your computer and use it in GitHub Desktop.
Save lucperkins/8642707 to your computer and use it in GitHub Desktop.
Making data types iterable in Dart
@CustomTag('x-note-element')
class NoteElement extends LIElement with Polymer, Observable {
@published Note note;
NoteElement.created() : super.created();
}
@CustomTag('x-notebook-element')
class NotebookElement extends PolymerElement {
@published Notebook notebook = new Notebook(new List<Note>());
NotebookElement.created() : super.created();
}
<polymer-element name="x-note-element" extends="li">
<template>
<h3>{{note.title}}</h3>
<p>{{note.content}}</p>
</template>
<script ...></script>
</polymer-element>
<polymer-element name="x-notebook-element">
<template>
<ul>
<template repeat="{{note in notebook}}">
<li is="x-note-element" note="{{note}}"></li>
</template>
</ul>
</template>
<script ...></script>
</polymer-element>
class Note {
String title;
String content;
Note(this.title, this.content);
}
class Notebook extends Object with IterableMixin<Note> {
List<Note> notes;
Iterator get iterator => notes.iterator;
Notebook(this.notes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment