Refactor js library to 'event' pattern.