🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

react-undo-redo

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-undo-redo - npm Package Compare versions

Comparing version

to
3.0.0

demo/index.html

19

demo/package.json

@@ -9,4 +9,4 @@ {

"scripts": {
"start": "webpack-dev-server",
"build": "webpack"
"start": "vite",
"build": "vite build"
},

@@ -16,16 +16,11 @@ "dependencies": {

"react-dom": "18.2.0",
"react-undo-redo": "2.1.0",
"react-undo-redo": "2.2.0",
"tiny-invariant": "1.3.1"
},
"devDependencies": {
"@types/react": "18.2.6",
"@types/react-dom": "18.2.4",
"html-webpack-harddisk-plugin": "2.0.0",
"html-webpack-plugin": "5.5.1",
"ts-loader": "9.4.2",
"typescript": "5.0.4",
"webpack": "5.83.1",
"webpack-cli": "5.1.1",
"webpack-dev-server": "4.15.0"
"@types/react": "18.2.23",
"@types/react-dom": "18.2.7",
"typescript": "5.2.2",
"vite": "4.4.9"
}
}

@@ -45,7 +45,15 @@ "use strict";

}
var past = __spreadArray([state.present()], state.past(), true);
var present = presentReducer(state.present(), action);
var present = state.present();
var nextPresent = presentReducer(state.present(), action);
if (present === nextPresent) {
return {
past: function () { return state.past(); },
present: function () { return present; },
future: function () { return state.future(); },
};
}
var past = __spreadArray([present], state.past(), true);
return {
past: function () { return past; },
present: function () { return present; },
present: function () { return nextPresent; },
future: function () { return []; },

@@ -52,0 +60,0 @@ };

export declare enum CountActionTypes {
INCREMENT = "@@count/increment",
DECREMENT = "@@count/decrement"
DECREMENT = "@@count/decrement",
NOOP = "@@count/noop"
}

@@ -11,6 +12,10 @@ type IncrementAction = {

};
export type CountActions = IncrementAction | DecrementAction;
type NoOpAction = {
type: CountActionTypes.NOOP;
};
export type CountActions = IncrementAction | DecrementAction | NoOpAction;
export declare const countReducer: (state: number, action: CountActions) => number;
export declare const increment: () => IncrementAction;
export declare const decrement: () => DecrementAction;
export declare const noop: () => NoOpAction;
export {};

@@ -6,3 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.decrement = exports.increment = exports.countReducer = exports.CountActionTypes = void 0;
exports.noop = exports.decrement = exports.increment = exports.countReducer = exports.CountActionTypes = void 0;
var tiny_invariant_1 = __importDefault(require("tiny-invariant"));

@@ -13,3 +13,4 @@ var CountActionTypes;

CountActionTypes["DECREMENT"] = "@@count/decrement";
})(CountActionTypes = exports.CountActionTypes || (exports.CountActionTypes = {}));
CountActionTypes["NOOP"] = "@@count/noop";
})(CountActionTypes || (exports.CountActionTypes = CountActionTypes = {}));
var countReducer = function (state, action) {

@@ -22,2 +23,4 @@ (0, tiny_invariant_1.default)(state != null, "Count reducer needs an initial state");

return state - 1;
case CountActionTypes.NOOP:
return state;
default:

@@ -28,9 +31,11 @@ (0, tiny_invariant_1.default)(false, "Count reducer received an unknown action.");

exports.countReducer = countReducer;
var increment = function () {
return ({ type: CountActionTypes.INCREMENT });
};
var increment = function () { return ({
type: CountActionTypes.INCREMENT,
}); };
exports.increment = increment;
var decrement = function () {
return ({ type: CountActionTypes.DECREMENT });
};
var decrement = function () { return ({
type: CountActionTypes.DECREMENT,
}); };
exports.decrement = decrement;
var noop = function () { return ({ type: CountActionTypes.NOOP }); };
exports.noop = noop;

@@ -1,1 +0,1 @@

export { countReducer, CountActions, CountActionTypes, increment } from "./countReducer";
export { countReducer, CountActions, CountActionTypes, increment, noop, } from "./countReducer";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.increment = exports.CountActionTypes = exports.countReducer = void 0;
exports.noop = exports.increment = exports.CountActionTypes = exports.countReducer = void 0;
var countReducer_1 = require("./countReducer");

@@ -8,1 +8,2 @@ Object.defineProperty(exports, "countReducer", { enumerable: true, get: function () { return countReducer_1.countReducer; } });

Object.defineProperty(exports, "increment", { enumerable: true, get: function () { return countReducer_1.increment; } });
Object.defineProperty(exports, "noop", { enumerable: true, get: function () { return countReducer_1.noop; } });
{
"name": "react-undo-redo",
"version": "2.2.0",
"version": "3.0.0",
"description": "A library to add undo-redo to any reducer",

@@ -14,4 +14,4 @@ "main": "lib/index.js",

"build": "tsc --project tsconfig.json",
"prepublishOnly": "yarn build && yarn test",
"test": "jest",
"prepublishOnly": "yarn build && yarn test --run",
"test": "vitest",
"format": "prettier --write .",

@@ -21,16 +21,17 @@ "prepare": "husky install"

"devDependencies": {
"@testing-library/jest-dom": "5.16.5",
"@testing-library/jest-dom": "6.1.3",
"@testing-library/react": "14.0.0",
"@testing-library/user-event": "^14.4.3",
"@types/react": "18.2.6",
"@types/react-dom": "18.2.4",
"@types/jest": "^29.5.5",
"@types/react": "18.2.23",
"@types/react-dom": "18.2.7",
"@types/testing-library__jest-dom": "5.14.9",
"husky": "8.0.3",
"jest": "29.5.0",
"jest-environment-jsdom": "29.5.0",
"prettier": "2.8.8",
"jsdom": "^22.1.0",
"prettier": "3.0.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"rimraf": "5.0.1",
"ts-jest": "29.1.0",
"typescript": "5.0.4"
"rimraf": "5.0.4",
"typescript": "5.2.2",
"vitest": "0.34.5"
},

@@ -37,0 +38,0 @@ "prettier": {

@@ -7,2 +7,3 @@ import { createReducer, redo, undo } from "./createReducer"

increment,
noop,
} from "./fixtures"

@@ -66,3 +67,3 @@

{ past: () => [0], present: () => 1, future: () => [2] },
increment()
increment(),
)

@@ -74,3 +75,16 @@

})
it("does not change past, present, and future when the state did not update", () => {
const reducer = createReducer(countReducer)
const updatedState = reducer(
{ past: () => [0], present: () => 1, future: () => [2] },
noop(),
)
expect(updatedState.past()).toEqual([0])
expect(updatedState.present()).toEqual(1)
expect(updatedState.future()).toEqual([2])
})
})
})

@@ -9,3 +9,3 @@ export type UndoRedoState<Present> = {

state: Present,
action: Actions
action: Actions,
) => Present

@@ -19,3 +19,3 @@

state: UndoRedoState<Present>,
action: Actions
action: Actions,
) => UndoRedoState<Present>

@@ -42,7 +42,7 @@

presentReducer: PresentReducer<Present, Actions>,
{ track = trackAll }: UndoRedoOptions<Actions> = {}
{ track = trackAll }: UndoRedoOptions<Actions> = {},
): UndoRedoReducer<Present, UndoRedoActions<Actions>> {
return function reducer(
state: UndoRedoState<Present>,
action: UndoRedoActions<Actions>
action: UndoRedoActions<Actions>,
): UndoRedoState<Present> {

@@ -74,2 +74,3 @@ if ("type" in action) {

const isTrackableAction = track(action)
if (!isTrackableAction) {

@@ -83,8 +84,18 @@ return {

const past = [state.present(), ...state.past()]
const present = presentReducer(state.present(), action)
const present = state.present()
const nextPresent = presentReducer(state.present(), action)
if (present === nextPresent) {
return {
past: () => state.past(),
present: () => present,
future: () => state.future(),
}
}
const past = [present, ...state.past()]
return {
past: () => past,
present: () => present,
present: () => nextPresent,
future: () => [],

@@ -91,0 +102,0 @@ }

@@ -6,2 +6,3 @@ import invariant from "tiny-invariant"

DECREMENT = "@@count/decrement",
NOOP = "@@count/noop",
}

@@ -17,4 +18,8 @@

export type CountActions = IncrementAction | DecrementAction
type NoOpAction = {
type: CountActionTypes.NOOP
}
export type CountActions = IncrementAction | DecrementAction | NoOpAction
export const countReducer = (state: number, action: CountActions): number => {

@@ -28,2 +33,4 @@ invariant(state != null, "Count reducer needs an initial state")

return state - 1
case CountActionTypes.NOOP:
return state
default:

@@ -34,5 +41,10 @@ invariant(false, "Count reducer received an unknown action.")

export const increment = (): IncrementAction =>
({ type: CountActionTypes.INCREMENT } as const)
export const decrement = (): DecrementAction =>
({ type: CountActionTypes.DECREMENT } as const)
export const increment = (): IncrementAction => ({
type: CountActionTypes.INCREMENT,
})
export const decrement = (): DecrementAction => ({
type: CountActionTypes.DECREMENT,
})
export const noop = (): NoOpAction => ({ type: CountActionTypes.NOOP })

@@ -1,1 +0,7 @@

export { countReducer, CountActions, CountActionTypes, increment } from "./countReducer"
export {
countReducer,
CountActions,
CountActionTypes,
increment,
noop,
} from "./countReducer"

@@ -19,4 +19,5 @@ {

"**/*.spec.tsx",
"jest.setup.ts"
"./vite.config.ts",
"./setupTests.ts"
]
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet