1.0.0 • Published 11 months ago

valtio-history v1.0.0

Weekly downloads
-
License
-
Repository
github
Last release
11 months ago

valtio-history

valtio utility for creating a proxy state with history tracking

npm version

https://valtio.pmnd.rs/docs/api/utils/proxyWithHistory

see detailed api docs for more info.


Migrating from valtio/utils

// replace the following line
// import { proxyWithHistory } from 'valtio/utils';

import { proxyWithHistory } from 'valtio-history';
import { useSnapshot } from 'valtio';

const state = proxyWithHistory({ count: 0 });
console.log(state.value); // ---> { count: 0 }
state.value.count += 1;
console.log(state.value); // ---> { count: 1 }
state.undo();
console.log(state.value); // ---> { count: 0 }
state.redo();
console.log(state.value); // ---> { count: 1 }

// React example
export default function App() {
  const {
    value,
    undo,
    redo,
    history,
    isUndoEnabled,
    isRedoEnabled,
    currentChangeDate,
    remove,
    replace,
} = useSnapshot(state);

  ...
}

Notable changes

  • the history object has changes
    • history.snapshots is renamed to history.nodes
    • a HistoryNode has the structure { snapshot: Snapshot<T>; createdAt: Date; updatedAt?: Date; }
  • The second parameter of proxyWithHistory is now an object instead of a boolean. { skipSubscribe?: boolean }
1.0.0

11 months ago

1.0.0-0

11 months ago

0.3.5

1 year ago

0.3.3

1 year ago

0.3.0

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.2.1

1 year ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.1

2 years ago

0.0.2

2 years ago

0.0.0

2 years ago