Skip to content

Instantly share code, notes, and snippets.

@tomdale tomdale/index.js
Created Dec 6, 2018

Embed
What would you like to do?
Tracked property notify API strawman
import Timer from 'simple-timer';
import Component from '@glimmer/component';
import { } from '@glimmer/tracking';
export default class TimerComponent extends Component {
constructor() {
// Mark the timer as "untracked" (i.e., we're asserting
// that timer contains no interior tracked properties at all).
// This function gives us back the timer as well as a callback
// function to call when any interior mutation may have occurred.
const [timer, timerDidChange] = notify(new Timer());
this.timer = timer;
this.timer.onTick(() => {
// invalidate timer and any nested properties used in a template
timerDidChange();
});
}
@tracked
get currentSeconds() {
return this.timer.seconds;
}
@tracked
get currentMinutes() {
return this.timer.minutes;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.