Using MutationObserver API and undo.js to track DOM changes

I was recently working on this project that had a kind of drag and drop builder. Users should be able to drag items into a specific building area to assembly stuff — I’m sorry for not giving more details, by the time I’m writing this the product is not yet released. One of the features I had to implement was a pair of buttons to undo and redo actions.

Every time an item is added to the builder, a DOM change happens. So, I started to look for ways to track changes in the DOM. That’s when I found about MutationObserver API. That web API is implemented by most of the modern browsers, Internet Explorer 11+ included, and allows you to observe DOM changes using a simple approach. The second tool that helped me build this was undo.js. It’s a simple Javascript class that allows developers to implement actions tracking in an exceptionally easy way.

After coding this feature, it seemed to me that combination of tools might be useful for a lot of other use cases. So I wrote this fiddle to demonstrate how they can be used together:

If you have any question, the comments area below is all yours.


Declarando arrays em shell script, no bash

Apenas uma referência básica de declaração de arrays em shell script, no bash. Em relação ao uso, existem várias formas e possibilidades.

Exemplo com strings:

nomes=( "Esse" "Aquele" "Outro" )

Exemplo com inteiros:

ids=( 1 2 3 4 5 6 7 )