Skip to content

Commit

Permalink
Added some documenting comments
Browse files Browse the repository at this point in the history
  • Loading branch information
butlermatt committed Oct 18, 2013
1 parent 83718d0 commit 5428930
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions web/example_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,37 @@ import 'dart:html';
class ExampleApp extends PolymerElement {
@published String page = '';

// Triggered by the on-click event on the buttons.
void updatePage(Event e, var detail, Node node) {
// Get the data-name value from the element
var pg = (node as Element).dataset['name'];

// pass the data-name value as the location fragment
// for the page. This lets route's Router handle passing
// it off to the page attribute.
window.location.hash = pg;
}

// Triggered by the on-change event for our observable
// variable 'page'. Observe library is nice in which we only
// have to create a callback which has the name of the variable
// plus 'Changed' tacked onto it. Receives the old value it used
// to contain.
void pageChanged(oldValue) {
// This check shouldn't be necessary as the observe library should
// handle this for us. But I'm paranoid ;)
if(page == oldValue) {
return;
} else if(page == '') {

// If page is blank just remove anything in the container.
var container = $['container'];
container.children.clear();
} else {
var element = '';

// Determine which element we should be displaying based on
// what was passed to the location fragment.
switch(page.toLowerCase()) {
case 'one':
case '1':
Expand All @@ -40,6 +56,7 @@ class ExampleApp extends PolymerElement {

}

// Take the element we determined needed to be added, create it and add it.
void _addElement(String elementName) {
if(elementName == '') throw new ArgumentError('Must provide an element name');

Expand Down
6 changes: 6 additions & 0 deletions web/routes_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ import 'package:route/client.dart';
final MyUrl = new UrlPattern(r'/routes_example/web/routes_example.html#(\w+)');

main() {
// Create our router and handlers then start listening.
// See route package documentation for more details.
var router = new Router()..addHandler(MyUrl, route_handler)..listen();

}

void route_handler(String path) {
// Since we only have one match group, we're only worried about the
// first result.
var page = MyUrl.parse(path)[0];

// Grab our custom element and assign to the page property.
var exampleApp = document.query('example-app').xtag;
exampleApp.page = page;
}

0 comments on commit 5428930

Please sign in to comment.