Skip to content

Repository files navigation

Undone

A library for undo and redo.

Build Status | Design | Example

Usage

Create an Action from Functions

// An argument for our undoable actions.var map = { 'value':42 };
// Actions bind a 'Do' functon and an 'Undo' function together with arguments.Do _increment = (a) =>++a['value'];
Undo _decrement = (a, r) =>--a['value']; var increment =newAction(map, _increment, _decrement);

Create an Action from a Class

// Define an Action subclass when you want your own type.classSquareextendsAction {
static_square(a) => a['value'] = a['value'] * a['value']; static_squareRoot(a, r) => a['value'] = math.sqrt(a['value']); Square(map):super(map, _square, _squareRoot); }
var square =newSquare(map);

Do an Action

// Call your action, and listen for the result (if you want) - its easy!increment().then((result) =>print('$result')); // prints '43'

Do a Transaction

// Call actions in a transaction - they'll be done and undone together!transact(() {
increment();
square();
}).then((_) =>print('${map["value"]}')); // prints '1936'

Undo and Redo

// Bind undo / redo to keyboard events.
document.onKeyUp.listen((e) { if (e.ctrlKey) {
if (e.keyCode ==KeyCode.Z) {
undo();
} elseif (e.keyCode ==KeyCode.Y) {
redo();
}
}
});

Undone uses the MIT license as described in the LICENSE file, and follows semantic versioning.

About

A library for undo and redo.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages