Skip to content
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

enhance: setResponseAction.payload -> setResponseAction.response; remove fetchAction.payload #3141

Merged
merged 1 commit into from
Jul 9, 2024

Conversation

ntucker
Copy link
Collaborator

@ntucker ntucker commented Jul 9, 2024

Motivation

  • Simplification
  • Consistent terminology

Solution

setResponseAction.payload -> setResponseAction.response

  • payload is unique terminology here, inherited from legacy redux actions.
  • Let's keep the value's name consistent with what we call it elsewhere so it's clear they are equivalent

This only affects those writing custom Managers that inspect SET_RESPONSE_TYPE action.payload.

Before

import { SET_RESPONSE_TYPE, type Manager, type Middleware } from '@data-client/react';

export default class MyManager implements Manager {
  getMiddleware = (): Middleware => controller => next => async action => {
    switch (action.type) {
      case SET_RESPONSE_TYPE:
        console.log('Resolved with value', action.payload);
        return next(action);
      default:
        return next(action);
    }
  };

  cleanup() {}
}

After

import { SET_RESPONSE_TYPE, type Manager, type Middleware } from '@data-client/react';

export default class MyManager implements Manager {
  getMiddleware = (): Middleware => controller => next => async action => {
    switch (action.type) {
      case SET_RESPONSE_TYPE:
        console.log('Resolved with value', action.response);
        return next(action);
      default:
        return next(action);
    }
  };

  cleanup() {}
}

remove fetchAction.payload

  • This is redundant as we have been passing action.endpoint for some time along with args
  • This means test and NetworkManager must both change to call action.endpoint now

This only affects those writing custom Managers that inspect FETCH_TYPE action.fetch.

Before

import { FETCH_TYPE, type Manager, type Middleware } from '@data-client/react';

export default class MyManager implements Manager {
  getMiddleware = (): Middleware => controller => next => async action => {
    switch (action.type) {
      case FETCH_TYPE:
        // consume fetch, and print the resolution
        action.fetch().then(response => console.log(response));
      default:
        return next(action);
    }
  };

  cleanup() {}
}

After

import { FETCH_TYPE, type Manager, type Middleware } from '@data-client/react';

export default class MyManager implements Manager {
  getMiddleware = (): Middleware => controller => next => async action => {
    switch (action.type) {
      case FETCH_TYPE:
        // consume fetch, and print the resolution
        action
          .endpoint(...action.meta.args)
          .fetch()
          .then(response => console.log(response));
      default:
        return next(action);
    }
  };

  cleanup() {}
}

Copy link

changeset-bot bot commented Jul 9, 2024

🦋 Changeset detected

Latest commit: ee0a8e8

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

This PR includes changesets to release 5 packages
Name Type
@data-client/core Minor
@data-client/react Minor
@data-client/test Minor
example-benchmark 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 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: ee0a8e8 Previous: 3ffa454 Ratio
normalizeLong 508 ops/sec (±0.42%) 491 ops/sec (±0.89%) 0.97
infer All 9847 ops/sec (±0.39%) 9392 ops/sec (±2.09%) 0.95
denormalizeLong 342 ops/sec (±0.78%) 317 ops/sec (±2.54%) 0.93
denormalizeLong donotcache 907 ops/sec (±0.15%) 874 ops/sec (±0.20%) 0.96
denormalizeShort donotcache 500x 1369 ops/sec (±0.11%) 1351 ops/sec (±0.18%) 0.99
denormalizeShort 500x 975 ops/sec (±0.30%) 967 ops/sec (±0.24%) 0.99
denormalizeShort 500x withCache 4815 ops/sec (±0.13%) 4777 ops/sec (±0.44%) 0.99
denormalizeLong with mixin Entity 287 ops/sec (±0.56%) 291 ops/sec (±0.56%) 1.01
denormalizeLong withCache 6368 ops/sec (±0.12%) 7396 ops/sec (±0.19%) 1.16
denormalizeLong All withCache 6635 ops/sec (±0.22%) 6546 ops/sec (±0.23%) 0.99
denormalizeLong Query-sorted withCache 6431 ops/sec (±0.69%) 6292 ops/sec (±0.66%) 0.98
denormalizeLongAndShort withEntityCacheOnly 1494 ops/sec (±0.53%) 1526 ops/sec (±0.57%) 1.02
getResponse 6528 ops/sec (±1.24%) 6257 ops/sec (±1.19%) 0.96
getResponse (null) 5358559 ops/sec (±0.94%) 5229459 ops/sec (±0.46%) 0.98
getResponse (clear cache) 291 ops/sec (±0.32%) 285 ops/sec (±0.64%) 0.98
getSmallResponse 2677 ops/sec (±0.19%) 2676 ops/sec (±0.92%) 1.00
getSmallInferredResponse 2091 ops/sec (±0.19%) 2079 ops/sec (±0.20%) 0.99
getResponse Query-sorted 5526 ops/sec (±0.43%) 5352 ops/sec (±0.64%) 0.97
getResponse Collection 6351 ops/sec (±1.12%) 6885 ops/sec (±1.33%) 1.08
get Collection 5726 ops/sec (±1.14%) 5954 ops/sec (±1.27%) 1.04
setLong 511 ops/sec (±0.52%) 484 ops/sec (±2.17%) 0.95
setLongWithMerge 202 ops/sec (±0.27%) 195 ops/sec (±0.46%) 0.97
setLongWithSimpleMerge 210 ops/sec (±0.75%) 208 ops/sec (±0.47%) 0.99
setSmallResponse 500x 886 ops/sec (±0.37%) 892 ops/sec (±0.33%) 1.01

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

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.79%. Comparing base (6834bff) to head (eba43b3).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3141      +/-   ##
==========================================
- Coverage   98.80%   98.79%   -0.01%     
==========================================
  Files         126      126              
  Lines        2250     2248       -2     
  Branches      460      460              
==========================================
- Hits         2223     2221       -2     
  Misses         16       16              
  Partials       11       11              

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

@ntucker ntucker merged commit d225595 into master Jul 9, 2024
5 of 6 checks passed
@ntucker ntucker deleted the no-payload-action branch July 9, 2024 11:27
@github-actions github-actions bot mentioned this pull request Jul 9, 2024
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.

None yet

1 participant