<commit_before>Ember-Memento [![Build Status](https://secure.travis-ci.org/pangratz/ember-memento.png)](http://travis-ci.org/pangratz/ember-memento)
==============

A mixin for Ember.js which adds undo/redo functionality to `Ember.Object`'s.

Added functionality to an object with the `Ember.Memento` mixin:

* [undo](#undo) and [redo](#redo) functionality
* [mementoSize](#mementosize) to limit amount of saved history states
* [clearHistory](#clearhistory) to clear history and optionally keep a given amount of states
* [updateProperties](#updateproperties) to update multiple properties and only keep 1 history state

Usage
-----

Add the mixin, located in `app/lib/memento.js` to your project.

The mixin works with properties of type 'string', 'number', 'boolean' and 'array'.

Use it in your objects which shall offer the functionality like this, see [JSFiddle](http://jsfiddle.net/pangratz666/Dbvhe/):

```javascript
var obj = Ember.Object.create(Ember.Memento, {
    // array of properties which shall be considered in undo/redo
    mementoProperties: 'firstName lastName age tags',

    firstName: 'Buster',
    age: 35,
    tags: ['cartographer']
});

// firstName = 'Buster', lastName = undefined, age = 35, tags = ['brother', 'cartographer']
obj.getProperties('firstName lastName age tags'.w());
```

Properties are modified as usual via Ember.js `setter`'s

```javascript
obj.set('lastName', 'Bluth');
obj.get('tags').pushObject('step-brother');
obj.set('firstName', '<NAME>');

// firstName = '<NAME>', lastName = 'Bluth', age = 35, tags = ['cartographer', 'step-brother']
obj.getProperties('firstName lastName age tags'.w());
```

#### undo

To undo a change, simply call `undo` on the object:

```javascript
// undo last change of firstName<commit_msg>Updated the README to use the w() method to convert the strings into an array<commit_after>Ember-Memento [![Build Status](https://secure.travis-ci.org/pangratz/ember-memento.png)](http://travis-ci.org/pangratz/ember-memento)
==============

A mixin for Ember.js which adds undo/redo functionality to `Ember.Object`'s.

Added functionality to an object with the `Ember.Memento` mixin:

* [undo](#undo) and [redo](#redo) functionality
* [mementoSize](#mementosize) to limit amount of saved history states
* [clearHistory](#clearhistory) to clear history and optionally keep a given amount of states
* [updateProperties](#updateproperties) to update multiple properties and only keep 1 history state

Usage
-----

Add the mixin, located in `app/lib/memento.js` to your project.

The mixin works with properties of type 'string', 'number', 'boolean' and 'array'.

Use it in your objects which shall offer the functionality like this, see [JSFiddle](http://jsfiddle.net/pangratz666/Dbvhe/):

```javascript
var obj = Ember.Object.create(Ember.Memento, {
    // array of properties which shall be considered in undo/redo
    mementoProperties: 'firstName lastName age tags'.w(),

    firstName: 'Buster',
    age: 35,
    tags: ['cartographer']
});

// firstName = 'Buster', lastName = undefined, age = 35, tags = ['brother', 'cartographer']
obj.getProperties('firstName lastName age tags'.w());
```

Properties are modified as usual via Ember.js `setter`'s

```javascript
obj.set('lastName', 'Bluth');
obj.get('tags').pushObject('step-brother');
obj.set('firstName', '<NAME>');

// firstName = '<NAME>', lastName = 'Bluth', age = 35, tags = ['cartographer', 'step-brother']
obj.getProperties('firstName lastName age tags'.w());
```

#### undo

To undo a change, simply call `undo` on the object:

```javascript
// undo last change of firstName
{'fraction_non_alphanumeric': 0.15058236272878536, 'fraction_numerical': 0.005546311702717693, 'mean_word_length': 4.9718543046357615, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '435737', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1106, 'n_words': 361}