https://github.com/theneuronproject/ef-time-traveler
Time travel support for ef.js
https://github.com/theneuronproject/ef-time-traveler
Last synced: over 1 year ago
JSON representation
Time travel support for ef.js
- Host: GitHub
- URL: https://github.com/theneuronproject/ef-time-traveler
- Owner: TheNeuronProject
- License: mit
- Created: 2019-09-05T08:00:46.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T22:21:34.000Z (over 3 years ago)
- Last Synced: 2024-10-01T20:08:39.961Z (almost 2 years ago)
- Language: JavaScript
- Size: 448 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ef-time-traveler
A time traveler written for ef, written with ef
## Usage
Import the time traveler and template to be time-traveled
```javascript
import TimeTraveler from 'ef-time-traveler'
import Template from './template.eft'
```
Create a time traveler instance and a new template instance
```javascript
const timeTraveler = new TimeTraveler()
const template = new Template()
```
---
Register the template instance to the time traveler instance. Specify keys to tell the time traveler to record which things needed:
```javascript
timeTraveler.register(template, ['key1', 'key2.subProp'])
```
---
Then do some operations on template instance, history will be automatically recorded
---
Get how many history is recorded. This is a read only value:
```javascript
const count = timeTraveler.historyCount
```
Jump back to history at position `X`
```javascript
timeTraveler.currentPos = X
```
Recording is disabled when viewing history. Resume to the last history position in order to continue editing:
```javascript
timeTraveler.currentPos = timeTraveler.historyCount
```
Revert `X` history records. Newer history record is then discarded:
```javascript
timeTraveler.revert(X)
```
Reset to position `X` and then all newer history is discarded:
```javascript
timeTraveler.reset(X)
```
## Notice
This time traveler only records changes, so you may need to be careful when manually setting `currentPos`. Reverting history would lead to a full history reconstruct, so use carefully to avoid performance issue.
## License
[MIT](http://cos.mit-license.org/)