Repository navigation
Allow skipping interpolation when changing camera - #614
Conversation
cdata
left a comment
There was a problem hiding this comment.
There is an important subtlety to how property values propagate after they have been set. Property change notifications are batched internally by enqueueing them in a microtask.
A brief aside on microtasks (skip if they aren't news to you):
Microtasks are a JavaScript event loop concept. Roughly speaking, there is a FIFO queue of additional tasks that get run at the end of the current event loop step (called a "task"). Microtasks are useful if you want some work to happen synchronously but not until the current call stack of the event loop unwinds, and also their qualities are essential to the underlying behavior of many web APIs.
Back to the topic at hand:
Our property updating semantics and timing are defined by the base class we depend on from LitElement.
So, if you set a property in a test, you need to wait on the microtask queue so that the change can take effect in the element. An easy way to do this in a test looks like this:
import {timePasses} from '../helpers.js';
// later...
test('property-changing test', async () => {
element.someProperty = 'value';
// With no arguments, this will enqueue a microtask and
// defers until after the microtask is dequeued
await timePasses();
// At this point you can assume that the change has taken effect
});An important but subtle detail of the example is that the test callback is an async function so that we can use the await keyword in the function body.
Another strategy that we use circumstantially is to dispatch an event from the element and wait for that before measuring the effects of a property change. This approach cannot always be used, however, because events dispatched on the element constitute public API.
| attribute on account of user interaction or camera interpolation.</p> | ||
| </li> | ||
| <li> | ||
| <div>jumpToGoal()</div> |
There was a problem hiding this comment.
I can make the referential leap with getFieldOfView to understand that it is referring to the camera (what else could FOV be referring to?). jumpToGoal is relatively less clear.
WDYT about jumpCameraToGoal()?
|
Thanks for the explanation, this has now been fixed, and the synchronicity is checked by its test. |
| <li> | ||
| <div>jumpCameraToGoal()</div> | ||
| <p>Instantaneously updates the camera to the specified goal state | ||
| instead of interpolating the motion over time.</p> |
There was a problem hiding this comment.
It might be worth padding the language here to set the expectations about what "instantaneous" means. Maybe rephrase to read along the lines of, "the camera will immediately move to its last configured goals on the next update."
cdata
left a comment
There was a problem hiding this comment.
Minor docs change requested, but otherwise this is looking 💯
Allow skipping interpolation when changing camera (google#614) * pulled camera out of controls.ts * interaction is smooth, 15 tests failing * fixed some tests, 4 to go * test assumption problem * two tests failing * all tests passing * added tests * fixed google#537 * moved framing back to controls.ts * fixed resize bug * added conversion tests * rename dest -> goal * addressing feedback * added damper tests * addressing feedback * exposed jumpToGoal method * test still fails * update doc * made jumpCameraToGoal synchronize with property updates * TS cleanup * fixed typo * updating doc
Fixes #454
This is a pretty simple change to skip interpolation by calling the jumpCameraToGoal method, here exposed on the element.