
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@storeon/undo
Advanced tools
Tiny module for Storeon which is adding undo functionality to your state. This means that now you can undoing or redoing the events in the state.
It is just 377 bytes module (it uses Size Limit to control the size) without any dependencies.
import { undoable, UNDO, REDO } from "@storeon/undo/full";
const store = createStore([
/* all your modules */
undoable,
]);
// now you can use UNDO and REDO with dispatch
dispatch(UNDO);
npm install @storeon/undo
# or
yarn add @storeon/undo
If you need to support IE, you need to compile node_modules
with Babel.
You can use this module in two ways:
To using the undo/redo functionality you just need to add the undoable
module to createStore
.
import { createStoreon } from "storeon";
import { undoable, UNDO, REDO } from "@storeon/undo/full";
let counter = (store) => {
store.on("@init", () => ({ counter: 0 }));
store.on("inc", (state) => ({ counter: state.counter + 1 }));
store.on("dec", (state) => ({ counter: state.counter - 1 }));
};
const store = createStoreon([counter, undoable]);
And now you can use the functions undo
and redo
to manipulate the history.
const Counter = () => {
const { dispatch, counter } = useStoreon("counter");
return (
<React.Fragment>
<div>{counter}</div>
<button onClick={() => dispatch("inc")}>Inc</button>
<button onClick={() => dispatch("dec")}>Dec</button>
</React.Fragment>
);
};
const UndoRedo = () => {
const { dispatch } = useStoreon();
return (
<>
<button onClick={() => dispatch(UNDO)}>Undo</button>
<button onClick={() => dispatch(REDO)}>Redo</button>
</>
);
};
If you need history only for some particular keys in state you can use createHistory
function:
import { createHistory } from "@storeon/undo";
// history will be collect only for key `a`
const history = createHistory(["a"]);
const { UNDO, REDO } = history;
createStore([
/* all your modules */
history.module,
]);
// to change the history use the UNDO and REDO from `history` object
dispatch(UNDO);
type paths = Array<String>;
The keys of state object that will be stored in history
type config.key = String
The default state key for storing history, when omitted:
paths
is not empty will be generated based on paths
content'undoable'
MIT
This module based on Implementing Undo History recipe article.
FAQs
Module for storeon which allows undoing or redoing the latest event
We found that @storeon/undo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.