npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

undo-redo-helper

v1.1.4

Published

Undo Redo That Helper.

Downloads

26

Readme

undo-redo-helper

Undo Redo That Helper, control your value timeLine (past-future).

ValueTimeLineSimple is open for any type, and have few simple oprations, get-set(value), undo(isUndo), redo(isRedo), timeLine(past[], future[]).

ValueTimeLineWrapper is like the simple version, but have encpsulated RxJs abilities (BehaviorSubject), such as Subscribe, trigger, pipe, and so on and so forth and what have you not.

npmjs/undo-redo-helper

github/YotamHassin/undo-redo-helper

Installation

cd <my_location>
npm install undo-redo-helper --save

Usage

TypeScript

TS ValueTimeLine Simple

import { ValueTimeLineSimple } from "undo-redo-helper";

// if not undefined => add as first value (last undo is always undefined).
let stateHistory = new ValueTimeLineSimple<number|undefined>(undefined);

// value 1
stateHistory.value = 1;

// will add undefined to history(in ctor undefined will not add)
stateHistory.value = undefined;

console.log('timeLine, value change', stateHistory.value, stateHistory.timeLine);

// undo array, add undo options 3, 4.
stateHistory.timeLine.past.push(...[3, 4]);

// timeLine change.
// timeLine.past change => value change.
console.log('timeLine.past change, value change', stateHistory.value, stateHistory.timeLine);

// redo array, add redo options, no need to fireEventHandler
stateHistory.timeLine.future = [5, 6, 7];
	
// redo (after undo, or by timeLine.future);
stateHistory.redo();

console.log('timeLine.future + redo, value change', stateHistory.value);

// go back.
stateHistory.undo();

//stateHistory.redo();
console.log('stateHistory.timeLine - past-future', stateHistory.value, stateHistory.timeLine);

TS ValueTimeLine Wrapper

import { ValueTimeLineWrapper } from "undo-redo-helper";
import { getLog } from "myy-common";
import { map } from "rxjs/operators";

// if not undefined => add as first value (last undo is always undefined).
// trigger 0
//let stateHistory = new ValueTimeLineWrapper(undefined, val => { getLog('stateHistory.eventHandler init test:')(val); });
let stateHistory = new ValueTimeLineWrapper(undefined, getLog('stateHistory.eventHandler init test:'));

// will trigger also on Ctor.
stateHistory._subscribe(getLog('stateHistory.eventHandler _subscribe test:'));
    
// line brake
stateHistory.subscribe(x => console.log());

// trigger 1
stateHistory.value = 1;

// will add undefined to history(in ctor undefined will not add)
stateHistory.value = undefined;

// trigger custom change.
stateHistory.fireEventHandler('my custom action', 2);

// not-trigger, undo array, add undo options 3, 4.
// to trigger 4 (last) use fireEventHandler
stateHistory.timeLine.past.push(...[3, 4]);

// timeLine change => no trigger.
// timeLine.past change => value change.
console.log('timeLine.past change, value change, no trigger', 
	stateHistory.value);

// update Observable by past array, trigger 4 (last from timeLine.past).
stateHistory.fireEventHandler('past.push');

// pipe source to make calced data.
stateHistory.e.pipe(map(x => 'last num is: ' + x))
	.subscribe(getLog('stateHistory simple pipe test:'));

stateHistory._e.pipe(map(x => JSON.stringify(x)))
	.subscribe(getLog('stateHistory complex pipe test:'));

// line brake
stateHistory.subscribe(x=> console.log());

// redo array, add redo options, no need to fireEventHandler
stateHistory.timeLine.future = [5, 6, 7];
	
// redo (after undo, or by timeLine.future);
stateHistory.redo();

// go back and trigger all subscribers.
stateHistory.undo();
//stateHistory.undo();

console.log('stateHistory.timeLine - past-future', stateHistory.timeLine);

JavaScript

JS ValueTimeLine Simple


const { ValueTimeLineSimple } = require('undo-redo-helper');

// if not undefined => add as first value (last undo is always undefined).
// value 0
let stateHistory = new ValueTimeLineSimple(undefined);

// value 1
stateHistory.value = 1;

// will add undefined to history(in ctor undefined will not add)
stateHistory.value = undefined;

// undo array, add undo options 3, 4.
stateHistory.timeLine.past.push(...[3, 4]);

// timeLine change.
// timeLine.past change => value change.
console.log('timeLine.past change, value change',
	stateHistory.value);

// redo array, add redo options, no need to fireEventHandler
stateHistory.timeLine.future = [5, 6, 7];

// redo (after undo, or by timeLine.future);
stateHistory.redo();

console.log('timeLine.future + redo, value change',
	stateHistory.value);

// go back.
stateHistory.undo();

console.log('stateHistory.timeLine - past-future', stateHistory.value, stateHistory.timeLine);

JS ValueTimeLine Wrapper

const { ValueTimeLineWrapper } = require('undo-redo-helper');
const { getLog } = require('myy-common');
const { map } = require('rxjs/operators');

// if not undefined => add as first value (last undo is always undefined).
// trigger 0
let stateHistory = new ValueTimeLineWrapper(undefined, getLog('stateHistory.eventHandler init test:'));

// will trigger also on Ctor.
stateHistory._subscribe(getLog('stateHistory.eventHandler _subscribe test:'));
// line brake
stateHistory.subscribe(x => console.log());

// trigger 1
stateHistory.value = 1;

// will add undefined to history(in ctor undefined will not add)
stateHistory.value = undefined;

// trigger custom change.
stateHistory.fireEventHandler('my custom action', 2);

// not-trigger, undo array, add undo options 3, 4.
// to trigger 4 (last) use fireEventHandler
stateHistory.timeLine.past.push(...[3, 4]);

// timeLine change => no trigger.
// timeLine.past change => value change.
console.log('timeLine.past change, value change, no trigger',
	stateHistory.value);

// update Observable by past array, trigger 4 (last from timeLine.past).
stateHistory.fireEventHandler('past.push');

// pipe source to make calced data.
stateHistory.e.pipe(map(x => 'last num is: ' + x))
	.subscribe(getLog('stateHistory simple pipe test:'));

stateHistory._e.pipe(map(x => JSON.stringify(x)))
	.subscribe(getLog('stateHistory complex pipe test:'));
// line brake
stateHistory.subscribe(x => console.log());

// redo array, add redo options, no need to fireEventHandler
stateHistory.timeLine.future = [5, 6, 7];

// redo (after undo, or by timeLine.future);
stateHistory.redo();

// go back and trigger all subscribers.
stateHistory.undo();

console.log('stateHistory.timeLine - past-future', stateHistory.timeLine);

Join me on the quest to make Computer, Software and Development Simple.

Patreon/YotamHassin