Skip to content

Instantly share code, notes, and snippets.

@tomdale
Created December 6, 2018 13:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomdale/795e475dabec4bbc7c13865fff25a596 to your computer and use it in GitHub Desktop.
Save tomdale/795e475dabec4bbc7c13865fff25a596 to your computer and use it in GitHub Desktop.
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