DrSensor / DrSensor/nusa

Support undo/redo

Open
#71 0 comments 0 reactions 0 assignees View on GitHub
enhancement priority: low
Dominant language
JavaScript
Stars
4
Forks
0
PR merge metrics
No merged PRs in 30d

Description

This feature introduce history buffer to undo/redo data changes in class accessors/properties. There is 2 kind of history that can be enabled via attribute:
- [ ] `history=linear` - use linear history where each new change after undo() will remove history of that undo()
- [ ] `history=tree` - history can have branch [^1]

[^1]: see [vim undo tree](https://github.com/mbbill/undotree)

`history` and `autotrack=history` attribute available on:
- [ ] `render-scope` - track history on all template for each instance of all linked modules
- [ ] `:is(html, render-scope) > link` - track history for each instance of that module
- [ ] `render-scope > template[shadowrootmode, define]` - track history inside that template

> **Warning**: the history will be removed/renewed when using SPA navigation #12. Cache or persist them (#14) to retain history between page navigation.

(TODO) This feature also pave a way for CRDT and data synchronization between servers and/or clients over network.

#### Example
```html

import * as history from "libnusa/history"
export default class {
#index = history.branch?.length ?? 0
undo() { history.undo() }
redo() { history.redo() }
cycle() {
history.switch(history.branch[
this.#index = this.#index < history.branch.length
? this.#index + 1 : 0
]) // maybe simplify as history.switch(-1 or +1)
}
}


0

↩️
↪️
🔄

```

> **Note** that each event handler need to be specified as `@event=track:methods` or use `@history.track` decorator to track the history. Specifying as `@event=untrack:methods` or using `@history.untrack` decorator will untrack the history when using `autotrack=history` attribute.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.