Created
December 6, 2018 13:38
-
-
Save tomdale/795e475dabec4bbc7c13865fff25a596 to your computer and use it in GitHub Desktop.
Tracked property notify API strawman
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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