-
-
Notifications
You must be signed in to change notification settings - Fork 30
fix(RuleY): widen data generic to accept raw values #572
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
Open
ljodea
wants to merge
3
commits into
main
Choose a base branch
from
fix/issue-41-ruley-datarow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all 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
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,2 @@ | ||
| declare module 'interval-tree-1d'; | ||
| declare module 'd3-time'; |
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,18 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import path from 'node:path'; | ||
|
|
||
| const ruleYPath = path.join(path.dirname(fileURLToPath(import.meta.url)), '../src/marks/RuleY.svelte'); | ||
|
|
||
| describe('RuleY public type contract', () => { | ||
| const src = readFileSync(ruleYPath, 'utf8'); | ||
|
|
||
| it('declares Datum extends DataRecord | RawValue', () => { | ||
| expect(src).toMatch(/generics="Datum extends DataRecord \| RawValue/); | ||
| }); | ||
|
|
||
| it('passes data to recordizeY without a DataRow cast', () => { | ||
| expect(src).not.toMatch(/data as DataRow\[\]/); | ||
| }); | ||
| }); |
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,12 @@ | ||
| import type { ComponentProps } from 'svelte'; | ||
| import RuleY from '../src/marks/RuleY.svelte'; | ||
|
|
||
| type AssertRuleYProps<T extends ComponentProps<typeof RuleY>> = T; | ||
|
|
||
| // Regression guards (green on main; stay green after fix) | ||
| type _RawBaseline = AssertRuleYProps<{ data: [0, 1] }>; | ||
| type _RecordRows = AssertRuleYProps<{ data: { y: number }[]; y: 'y' }>; | ||
| type AssertTrue<T extends true> = T; | ||
| type RuleYData = NonNullable<ComponentProps<typeof RuleY>['data']>; | ||
| type _NumberArrayAssignable = [number[]] extends [RuleYData] ? true : false; | ||
| type _ExpectNumberArray = AssertTrue<_NumberArrayAssignable>; |
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,23 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "paths": { | ||
| "svelteplot": ["./src/index.ts"], | ||
| "svelteplot/*": ["./src/*"] | ||
| } | ||
| }, | ||
| "include": [ | ||
| "tests/ruleY.contract.ts", | ||
| "tests/check-ambient.d.ts", | ||
| "src/**/*.ts", | ||
| "src/**/*.svelte", | ||
| "src/**/*.js" | ||
| ], | ||
| "exclude": [ | ||
| "tests/**/*.test.ts", | ||
| "tests/**/*.test.svelte.ts", | ||
| "tests/**/*.svelte", | ||
| "src/**/*.test.ts", | ||
| "src/**/*.spec.ts" | ||
| ] | ||
| } |
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.
With this widened generic, calls such as
<RuleY data={[5]} y={(d) => d} />now type-check withdas the raw number. HoweverrecordizeYonly createsRAW_VALUEwrappers wheny == null; when an explicitycallback is present it indexes the primitive as an object, so the callback receives the wrapper record instead of5and produces an invalid channel value. Either preserve raw datums even when explicit channels are supplied or keep the raw-value contract limited to the no-yshorthand.Useful? React with 👍 / 👎.
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.
Fair catch on
recordizeYbehavior, but out of scope for this PR.The raw shorthand this fixes is the documented no-
yform (<RuleY data={[50, 100, 150]} />). Combining a raw value array with an explicityaccessor was already handled the same way onmain(RuleY still cast toDataRow[]beforerecordizeY); this diff only changes the declared generic and removes that cast.recordizeYonly wraps primitives wheny == nullby design — that is shared transform logic, not something RuleY's generic widening introduced. Tightening or fixing that path (raw data + explicit channel) belongs in a follow-up onrecordizeY/recordizeX, not in the #41 type-honesty fix.