Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

fix(deps): update dependency zundo to v2.0.0 #2307

Merged
merged 1 commit into from
Oct 2, 2023
Merged

Conversation

renovate[bot]
Copy link
Contributor

@renovate renovate bot commented Sep 17, 2023

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
zundo 2.0.0-beta.25 -> 2.0.0 age adoption passing confidence

Release Notes

charkour/zundo (zundo)

v2.0.0: - Smaller and more flexible 🎉

Compare Source

v2.0.0 is a complete rewrite of zundo. It is smaller and more flexible. It also has a smaller bundle size and allows you to opt into specific performance trade-offs. The API has changed slightly. See the API section for more details. Below is a summary of the changes as well as steps to migrate from v1 to v2.

v2 introduces 8 new middleware options and is only ~800 bytes where v1 was a few KBs.

Community

zundo is used by several projects and teams including Stability AI, Yext, KaotoIO, and NutSH.ai.

If this library is useful to you, please consider sponsoring the project. Thank you!

PRs are welcome! pnpm is used as a package manager. Run pnpm install to install local dependencies. Thank you for contributing!

Breaking Changes
Middleware Option Changes
  • include and exclude options are now handled by the partialize option.
  • allowUnchanged option is now handled by the equality option. By default, all state changes are tracked. In v1, we bundled lodash.isequal to handle equality checks. In v2, you are able to use any function.
  • historyDepthLimit option has been renamed to limit.
  • coolOffDurationMs option is now handled by the handleSet option by wrapping the setter function with a throttle or debounce function.
Import changes
  • The middleware is called temporal rather than undoMiddleware.
New Features
New Options
  • partialize option to omit or include specific fields. By default, the entire state object is tracked.
  • limit option to limit the number of previous and future states stored in history.
  • equality option to use a custom equality function to determine when a state change should be tracked. By default, all state changes are tracked.
  • diff option to store state delta rather than full object.
  • onSave option to call a function when the temporal store is updated.
  • handleSet option to throttle or debounce state changes.
  • pastStates and futureStates options to initialize the temporal store with past and future states.
  • wrapTemporal option to wrap the temporal store with middleware. The temporal store is a vanilla zustand store.
New temporal.getState() API
  • undo, redo, and clear functions are now always defined. They can no longer be undefined.
  • undo() and redo() functions now accept an optional steps parameter to go back or forward multiple states at once.
  • isTracking flag, and pause, and resume functions are now available on the temporal store.
  • setOnSave function is now available on the temporal store to change the onSave behavior after the store has been created.
Migration Steps
  1. Update zustand to v4.3.0 or higher
  2. Update zundo to v2.0.0 or higher
  3. Update your store to use the new API
  4. Update imports
- import { undoMiddleware } from 'zundo';
+ import { temporal } from 'zundo';
  • If you're using include or exclude, use the new partialize option
// v1.6.0
// Only field1 and field2 will be tracked
const useStoreA = create<StoreState>(
  undoMiddleware(
    set => ({ ... }),
    { include: ['field1', 'field2'] }
  )
);

// Everything besides field1 and field2 will be tracked
const useStoreB = create<StoreState>(
  undoMiddleware(
    set => ({ ... }),
    { exclude: ['field1', 'field2'] }
  )
);

// v2.0.0
// Only field1 and field2 will be tracked
const useStoreA = create<StoreState>(
  temporal(
    (set) => ({
      // your store fields
    }),
    {
      partialize: (state) => {
        const { field1, field2, ...rest } = state;
        return { field1, field2 };
      },
    },
  ),
);

// Everything besides field1 and field2 will be tracked
const useStoreB = create<StoreState>(
  temporal(
    (set) => ({
      // your store fields
    }),
    {
      partialize: (state) => {
        const { field1, field2, ...rest } = state;
        return rest;
      },
    },
  ),
);
  • If you're using allowUnchanged, use the new equality option
// v1.6.0
// Use an existing `allowUnchanged` option
const useStore = create<StoreState>(
  undoMiddleware(
    set => ({ ... }),
    { allowUnchanged: true }
  )
);

// v2.0.0
// Use an existing equality function
import { shallow } from 'zustand/shallow'; // or use `lodash.isequal` or any other equality function

// Use an existing equality function
const useStoreA = create<StoreState>(
  temporal(
    (set) => ({
      // your store fields
    }),
    { equality: shallow },
  ),
);
  • If you're using historyDepthLimit, use the new limit option
// v1.6.0
// Use an existing `historyDepthLimit` option
const useStore = create<StoreState>(
  undoMiddleware(
    set => ({ ... }),
    { historyDepthLimit: 100 }
  )
);

// v2.0.0
// Use `limit` option
const useStore = create<StoreState>(
  temporal(
    (set) => ({
      // your store fields
    }),
    { limit: 100 },
  ),
);
  • If you're using coolOffDurationMs, use the new handleSet option
// v1.6.0
// Use an existing `coolOffDurationMs` option
const useStore = create<StoreState>(
  undoMiddleware(
    set => ({ ... }),
    { coolOfDurationMs: 1000 }
  )
);

// v2.0.0
// Use `handleSet` option
const withTemporal = temporal<MyState>(
  (set) => ({
    // your store fields
  }),
  {
    handleSet: (handleSet) =>
      throttle<typeof handleSet>((state) => {
        console.info('handleSet called');
        handleSet(state);
      }, 1000),
  },
);

What's Changed

New Contributors

Full Changelog: charkour/zundo@v1.6.0...v2.0.0

v2.0.0-experimental.0

Compare Source

Support zustand v4 with an updated API. This is an experimental release that will be similar to v2 of zundo.

BREAKING CHANGES
The methods undo, redo, clear, setIsUndoHistoryEnabled, and getState are not accessed from useStore.temporal instead of useStore().

  const { undo, redo, clear, setIsUndoHistoryEnabled, getState } = useStore.temporal;

What's Changed

Full Changelog: charkour/zundo@v1.6.0...v2.0.0-experimental.0


Configuration

📅 Schedule: Branch creation - "before 6am" (UTC), Automerge - At any time (no schedule defined).

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Mend Renovate. View repository job log here.

@renovate renovate bot requested a review from a team September 17, 2023 04:46
@codecov
Copy link

codecov bot commented Sep 17, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (d645d6a) 72.64% compared to head (4364496) 72.64%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2307   +/-   ##
=======================================
  Coverage   72.64%   72.64%           
=======================================
  Files          88       88           
  Lines        2968     2968           
  Branches      696      696           
=======================================
  Hits         2156     2156           
  Misses        776      776           
  Partials       36       36           

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

@charkour
Copy link

If you have issues with the upgrade process, let me know!

Thank you for testing the beta version :)

@sonarcloud
Copy link

sonarcloud bot commented Oct 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@lordrip
Copy link
Member

lordrip commented Oct 2, 2023

If you have issues with the upgrade process, let me know!

Thank you for testing the beta version :)

Hey @charkour, thanks for passing by 😃.

I forgot to merge this pull request, I'll do it now.

@lordrip lordrip merged commit 2fccc13 into main Oct 2, 2023
15 of 16 checks passed
@lordrip lordrip deleted the renovate/zundo-2.x branch October 2, 2023 13:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants