add event observer and migrate it to typescript