refactor javascript api to use emitters