Skip to content

feat: Endpoint.update programmable sideeffects #843

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 3 commits into from
May 24, 2021
Merged

feat: Endpoint.update programmable sideeffects #843

merged 3 commits into from
May 24, 2021

Conversation

ntucker
Copy link
Collaborator

@ntucker ntucker commented May 24, 2021

Motivation

Iterating toward #760

  • Define programmable update in endpoint
  • Improve function signature

Solution

We maintain working on raw reducer state, however we introduce improvements on the update method itself being much more straightforward and easy to define correctly.

  • two degree function
  • map key -> update function
const createUser = new Endpoint(postToUserFunction, {
  schema: User,
  update: (newUserId: string)  => {
    const updates = {
      [userList.key()]: (users = []) => [newUserId, ...users],
      [userList.key({ sortBy: 'createdAt' })]: (users = [], { sortBy }) => {
        const ret = [newUserId, ...users];
        ret.sortBy(sortBy);
        return ret;
      },
    ];
    if (newUser.isAdmin) {
      updates[userList.key({ admin: true })] = (users = []) => [newUserId, ...users];
    }
    return updates;
  },
});

Legacy plan

This PR

  • Maintain previous updaters in reducer
  • add update method to actions
  • introduce usage in useFetcher found in experimental

Stage 2

  • Make previous useFetcher() method transform into new update meta

Stage 3

  • Stop supporting old update meta by removal from reducer

@ntucker ntucker requested a review from ljharb May 24, 2021 03:43
@github-actions
Copy link
Contributor

github-actions bot commented May 24, 2021

Size Change: +3 B (0%)

Total Size: 142 kB

Filename Size Change
packages/core/dist/index.cjs.js 11.8 kB +50 B (0%)
packages/core/dist/index.umd.min.js 5.16 kB +37 B (0%)
packages/experimental/dist/index.cjs.js 8.37 kB -94 B (1%)
packages/experimental/dist/index.umd.min.js 3.05 kB +10 B (0%)
ℹ️ View Unchanged
Filename Size Change
packages/endpoint/dist/index.cjs.js 2.01 kB 0 B
packages/endpoint/dist/index.umd.min.js 1.42 kB 0 B
packages/hooks/dist/index.cjs.js 8.28 kB 0 B
packages/hooks/dist/index.umd.min.js 3.01 kB 0 B
packages/img/dist/index.cjs.js 7.82 kB 0 B
packages/img/dist/index.umd.min.js 2.9 kB 0 B
packages/legacy/dist/index.cjs.js 578 B 0 B
packages/legacy/dist/index.umd.min.js 517 B 0 B
packages/normalizr/dist/normalizr.amd.js 10.8 kB 0 B
packages/normalizr/dist/normalizr.amd.min.js 5.89 kB 0 B
packages/normalizr/dist/normalizr.browser.js 10.8 kB 0 B
packages/normalizr/dist/normalizr.browser.min.js 5.89 kB 0 B
packages/normalizr/dist/normalizr.js 10.7 kB 0 B
packages/normalizr/dist/normalizr.min.js 5.9 kB 0 B
packages/normalizr/dist/normalizr.umd.js 10.9 kB 0 B
packages/normalizr/dist/normalizr.umd.min.js 5.97 kB 0 B
packages/rest-hooks/dist/index.cjs.js 8.04 kB 0 B
packages/rest-hooks/dist/index.umd.min.js 4.31 kB 0 B
packages/rest/dist/index.cjs.js 4.1 kB 0 B
packages/rest/dist/index.umd.min.js 2.19 kB 0 B
packages/use-enhanced-reducer/dist/index.cjs.js 1.08 kB 0 B
packages/use-enhanced-reducer/dist/index.umd.min.js 607 B 0 B

compressed-size-action

@ntucker ntucker merged commit 3b011b2 into master May 24, 2021
@ntucker ntucker deleted the feat/update branch May 24, 2021 04:01
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.

2 participants