undone 0.2.13 copy "undone: ^0.2.13" to clipboard
undone: ^0.2.13 copied to clipboard

outdatedDart 1 only

A library for undo and redo.

Undone #

A library for undo and redo.

Build Status

Documentation #

Please consult the API documentation.

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 = new Action(map, _increment, _decrement);

Create a Custom Action Type #

// Use custom actions when you want your own type.
class Square extends Action {  
  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 = new Square(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();
    else if (e.keyCode == KeyCode.Y)      redo();
  }
});

Run the Examples #

The code above can be found here. For more fun, try to nudge a box around a canvas - its undoable!

Read the Article #

Learn more about the design decisions by reading this article.

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

0
likes
0
points
40
downloads

Documentation

Documentation

Publisher

unverified uploader

Weekly Downloads

A library for undo and redo.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

logging

More

Packages that depend on undone