Skip to content

enhance: Remove INVALID symbol from endpoints in favor of delegate access #3461

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 1 commit into from
Apr 8, 2025

Conversation

ntucker
Copy link
Collaborator

@ntucker ntucker commented Apr 8, 2025

Motivation

There should only be one symbol. We're getting around this by simply checking typeof, but this is a hack because normalizr and endpoint should not 'know' of each other directly.

Solution

Just like we hand off special errors to throw with snapshot, we can do the same thing with our delegate.

normalize

Before

normalize(
  input: any,
  parent: any,
  key: string | undefined,
  args: any[],
  visit: (...args: any) => any,
  delegate: INormalizeDelegate,
): string {
  delegate.setEntity(this as any, pk, INVALID);
}

After

normalize(
  input: any,
  parent: any,
  key: string | undefined,
  args: any[],
  visit: (...args: any) => any,
  delegate: INormalizeDelegate,
): string {
  delegate.invalidate(this as any, pk);
}

queryKey

Before
queryKey(args: any, unvisit: any, delegate: IQueryDelegate): any {
  if (!found) return INVALID;
}
After
queryKey(args: any, unvisit: any, delegate: IQueryDelegate): any {
  if (!found) return delegate.INVALID;
}

Copy link

changeset-bot bot commented Apr 8, 2025

🦋 Changeset detected

Latest commit: 620b745

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@data-client/normalizr Minor
@data-client/endpoint Minor
@data-client/rest Minor
@data-client/graphql Minor
@data-client/core Minor
example-benchmark Patch
normalizr-github-example Patch
normalizr-redux-example Patch
normalizr-relationships Patch
@data-client/img Minor
@data-client/react Minor
test-bundlesize Patch
coinbase-lite Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Apr 8, 2025

Size Change: -31 B (-0.04%)

Total Size: 77.8 kB

Filename Size Change
examples/test-bundlesize/dist/rdcClient.js 10.2 kB +18 B (+0.18%)
examples/test-bundlesize/dist/rdcEndpoint.js 5.6 kB -49 B (-0.87%)
ℹ️ View Unchanged
Filename Size
examples/test-bundlesize/dist/App.js 3.42 kB
examples/test-bundlesize/dist/polyfill.js 311 B
examples/test-bundlesize/dist/react.js 57.5 kB
examples/test-bundlesize/dist/webpack-runtime.js 726 B

compressed-size-action

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 620b745 Previous: ce792ac Ratio
normalizeLong 509 ops/sec (±0.76%) 486 ops/sec (±0.79%) 0.95
infer All 9483 ops/sec (±0.89%) 9385 ops/sec (±0.90%) 0.99
denormalizeLong 263 ops/sec (±2.86%) 281 ops/sec (±2.55%) 1.07
denormalizeLong donotcache 981 ops/sec (±0.33%) 1019 ops/sec (±0.22%) 1.04
denormalizeShort donotcache 500x 1396 ops/sec (±0.33%) 1344 ops/sec (±0.66%) 0.96
denormalizeShort 500x 763 ops/sec (±2.23%) 755 ops/sec (±2.24%) 0.99
denormalizeShort 500x withCache 5038 ops/sec (±0.30%) 5187 ops/sec (±0.33%) 1.03
queryShort 500x withCache 2420 ops/sec (±0.55%) 2400 ops/sec (±0.44%) 0.99
denormalizeLong with mixin Entity 266 ops/sec (±1.93%) 259 ops/sec (±2.10%) 0.97
denormalizeLong withCache 6751 ops/sec (±0.59%) 6528 ops/sec (±0.39%) 0.97
denormalizeLong All withCache 7775 ops/sec (±0.55%) 8190 ops/sec (±0.12%) 1.05
denormalizeLong Query-sorted withCache 7471 ops/sec (±1.21%) 8147 ops/sec (±0.14%) 1.09
denormalizeLongAndShort withEntityCacheOnly 1702 ops/sec (±0.33%) 1750 ops/sec (±0.29%) 1.03
getResponse 6704 ops/sec (±1.19%) 6834 ops/sec (±0.89%) 1.02
getResponse (null) 5679878 ops/sec (±0.58%) 6020982 ops/sec (±1.75%) 1.06
getResponse (clear cache) 256 ops/sec (±1.90%) 268 ops/sec (±1.72%) 1.05
getSmallResponse 2586 ops/sec (±0.28%) 2549 ops/sec (±0.58%) 0.99
getSmallInferredResponse 2037 ops/sec (±0.20%) 2081 ops/sec (±0.50%) 1.02
getResponse Collection 6417 ops/sec (±1.07%) 6857 ops/sec (±0.79%) 1.07
get Collection 5649 ops/sec (±0.37%) 6173 ops/sec (±0.35%) 1.09
get Query-sorted 7040 ops/sec (±0.34%) 7129 ops/sec (±0.27%) 1.01
setLong 507 ops/sec (±0.75%) 512 ops/sec (±0.26%) 1.01
setLongWithMerge 220 ops/sec (±0.52%) 228 ops/sec (±0.47%) 1.04
setLongWithSimpleMerge 229 ops/sec (±0.76%) 244 ops/sec (±0.31%) 1.07
setSmallResponse 500x 906 ops/sec (±0.31%) 887 ops/sec (±0.84%) 0.98

This comment was automatically generated by workflow using github-action-benchmark.

Copy link

codecov bot commented Apr 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.74%. Comparing base (ce792ac) to head (620b745).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3461      +/-   ##
==========================================
- Coverage   98.75%   98.74%   -0.01%     
==========================================
  Files         125      124       -1     
  Lines        2241     2239       -2     
  Branches      460      460              
==========================================
- Hits         2213     2211       -2     
  Misses         13       13              
  Partials       15       15              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ntucker ntucker merged commit 939a4b0 into master Apr 8, 2025
24 checks passed
@ntucker ntucker deleted the invalid branch April 8, 2025 12:09
@github-actions github-actions bot mentioned this pull request Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant