https://github.com/uditalias/timeline
JavaScript Undo/Redo mechanism with simple API ✌️
https://github.com/uditalias/timeline
history-management npm-package timeline undo-redo
Last synced: about 1 year ago
JSON representation
JavaScript Undo/Redo mechanism with simple API ✌️
- Host: GitHub
- URL: https://github.com/uditalias/timeline
- Owner: uditalias
- License: mit
- Created: 2019-09-24T12:29:21.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-28T09:02:47.000Z (almost 2 years ago)
- Last Synced: 2025-04-15T05:28:32.611Z (about 1 year ago)
- Topics: history-management, npm-package, timeline, undo-redo
- Language: TypeScript
- Homepage:
- Size: 16.6 KB
- Stars: 33
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-list - timeline
README
🕰
Timeline
JavaScript Undo/Redo mechanism with simple API < 1KB
Install
##### NPM
```bash
npm i @udidu/timeline
```
##### YARN
```bash
yarn add @udidu/timeline
```
##### CDN
```html
```
Minified
```html
```
Usage
```javascript
import Timeline from "@udidu/timeline";
const timeline = new Timeline();
timeline.setPresent(1);
timeline.setPresent(2);
timeline.setPresent(3);
timeline.present; // 3
timeline.undo(); // 2
timeline.hasPast; // true
timeline.hasFuture; // true
timeline.setPresent(4);
timeline.hasFuture; // false
timeline.undo(); // 2
timeline.redo(); // 4
timeline.clear();
timeline.hasPast; // false
timeline.hasFuture; // false
```
Options
All options are optional
```javascript
const timeline = new Timeline({
// The size of the past queue
// default: Infinity
size: 5,
// When calling `setPresent(preset)` the value is passed to this function.
// this is good for cases when we want to clone the object before saving it.
// default: echo function - returns the same value/reference
cloneFn: item => toJS(item),
// Initialize the present
// default: undefined
present: 2
});
```
For your convenience, I created this [**Fiddle**](https://jsfiddle.net/udidu/hcbkzvgj/), so you can take Timeline for a ride.
---
License
The MIT License (MIT)
Copyright (c) 2019 Udi Talias
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.