Skip to content

Instantly share code, notes, and snippets.

@nikgraf
Created July 17, 2013 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikgraf/6016426 to your computer and use it in GitHub Desktop.
Save nikgraf/6016426 to your computer and use it in GitHub Desktop.
import 'dart:async';
import 'package:polymer/polymer.dart';
import 'package:observe/observe.dart';
class CountdownClock extends CustomElement with ObservableMixin {
static final oneSecond = new Duration(seconds: 1);
@observable var timeLeft = new Duration(seconds: 72);
/*
* Initialize the timer who updates the duration periodically
* when the component has been added to the DOM.
*/
void inserted() {
new Timer.periodic(oneSecond, _updateTimeLeft);
}
/*
* Update timeLeft until 0 seconds left.
*/
void _updateTimeLeft(Timer _) {
if (timeLeft > new Duration(seconds: 0)) {
timeLeft = timeLeft - oneSecond;
}
}
}
name: alarm
description: A sample WebUI application
dependencies:
browser: any
mdv: any
observe: any
polymer: any
shadow_dom: any
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment