Add a guard before deref history.

There were certain cases causing togetherjs to break
here when history would be undefined. This was caused
by, for instance, when text in a text box were changed
by script.
Merge pull request #857 from RickEyre/history-guard

Add a guard before deref history.