Repository navigation
fix(core): spring roles register themselves when they load #10138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [chore] Internal: each spring role, and the navigation, paging and picker motion tables, register themselves when their module loads, so a spring role plays at the theme's `tempo` wherever it plays, with no register call. A page that plays no spring ships no springs registry. A module that imports single spring rows carries only those rows, unless it also reads the whole `springs` table or calls `registerSpringsTable()`. Not exported from the package entry point. | ||
|
|
||
| @vjeux |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,7 +212,8 @@ export function createAttachableAnimator(): { | |
| if (inactive() || Object.keys(to).length === 0) { | ||
| return; | ||
| } | ||
| // The role registry is written on first use, never on import. | ||
| // The spring roles registered as their module loaded, so this call | ||
| // registers nothing new. | ||
|
Comment on lines
+215
to
+216
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Non-blocking: this comment explains a call that now does nothing. Deleting |
||
| registerSpringsTable(); | ||
| const velocity = motionValues(options?.velocity); | ||
| await motion.animate(to, { | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file selfRegistration.test.ts | ||
| * @input vitest (jsdom); each touch table imported in a fresh module graph, | ||
| * with no call to its register function | ||
| * @output Checks that each spring role row, and the navigation, paging and | ||
| * picker tables, register at import, so a role plays at the theme's tempo | ||
| * @position Testing; validates uikit/springs.ts, navigation.ts, paging.ts and | ||
| * picker.ts | ||
| */ | ||
|
|
||
| import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest'; | ||
|
|
||
| const TEMPO_PROPERTY = '--_astryx-motion-tempo'; | ||
| /** The tempo the stubbed theme writes; empty where no theme sets one. */ | ||
| let tempo = ''; | ||
|
|
||
| beforeEach(() => { | ||
| vi.resetModules(); | ||
| tempo = ''; | ||
| vi.spyOn(window, 'getComputedStyle').mockImplementation( | ||
| () => | ||
| ({ | ||
| getPropertyValue: (name: string) => | ||
| name === TEMPO_PROPERTY ? tempo : '', | ||
| }) as unknown as CSSStyleDeclaration, | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.doUnmock('../roles'); | ||
| vi.restoreAllMocks(); | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| function element(): HTMLElement { | ||
| const child = document.createElement('div'); | ||
| document.body.append(child); | ||
| return child; | ||
| } | ||
|
|
||
| describe('the touch tables register at import', () => { | ||
| it('a page that imports only the settle row plays it at the tempo', async () => { | ||
| const {SETTLE_SPRING} = await import('./springs'); | ||
| const {resolveMotion} = await import('../resolveMotion'); | ||
| const {solveSpring, toSpring} = await import('../spring'); | ||
| const target = element(); | ||
| const base = solveSpring(toSpring(SETTLE_SPRING), {from: 0, to: 1}); | ||
| for (const scale of [0.75, 1.5]) { | ||
| tempo = String(scale); | ||
| const played = solveSpring( | ||
| toSpring(resolveMotion(target, SETTLE_SPRING)), | ||
| {from: 0, to: 1}, | ||
| ); | ||
| expect(played.settleTime(0.001)).toBeCloseTo( | ||
| base.settleTime(0.001) * scale, | ||
| 6, | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| it('a page that imports only the picker plays its tap spin at the tempo', async () => { | ||
| const {picker} = await import('./picker'); | ||
| const {resolveMotion} = await import('../resolveMotion'); | ||
| tempo = '1.5'; | ||
| expect(resolveMotion(element(), picker.tapSpin, 'durationMs')).toBe( | ||
| picker.tapSpin.durationMs * 1.5, | ||
| ); | ||
| }); | ||
|
|
||
| it('each role row and table registers itself, at import', async () => { | ||
| const registered: string[] = []; | ||
| vi.doMock('../roles', async importOriginal => { | ||
| const actual = await importOriginal<typeof import('../roles')>(); | ||
| return { | ||
| ...actual, | ||
| registerMotionTable: ( | ||
| ...args: Parameters<typeof actual.registerMotionTable> | ||
| ) => { | ||
| registered.push(args[0]); | ||
| actual.registerMotionTable(...args); | ||
| }, | ||
| }; | ||
| }); | ||
| const {SETTLE_SPRING, KEYBOARD_SPRING} = await import('./springs'); | ||
| await import('./navigation'); | ||
| await import('./paging'); | ||
| await import('./picker'); | ||
| const {motionRoleOf} = await import('../roles'); | ||
| expect(motionRoleOf(SETTLE_SPRING)?.id).toBe('springs.settle'); | ||
| // The keyboard's spring is a measured constant, not a role. | ||
| expect(motionRoleOf(KEYBOARD_SPRING)).toBeUndefined(); | ||
| expect(registered).toEqual(['navigation', 'paging', 'picker']); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: the first sentence only explains why the
registerSpringsTable()call below does nothing. Deleting that call leaves one sentence to keep: "The slide plays the segmented role, which registers here before the first animation."