phetsims/axon

Replace usages of Events with Emitter

Closed this issue · 8 comments

Events.js is deprecated and Emitter should be used instead, we should chip away at this. This is somewhat related to #102 because PropertySet extended Events.

Scheduled for developer meeting to do the following:

  1. Make sure this is a desirable task to complete
  2. Determine what to do with usages in Node.js. Should this file become Node-specific, or integrated into Node? Should Node use emitters? How many emitters would each Node need to evade Events?
  3. Schedule/plan for working on this

Searching for "var Events = require", I see the following number of usages by repository:

common code:
1 axon (PropertySet)
2 dot (Transform3, Transform4)
3 kite (Shape, Segments, Subpath)
6 scenery (Node, Display, Drawable, Instance, AccessibleInstance, AccessiblePeer)

sims:
3 fluid-pressure-and-flow
1 molecule-shapes

Thoughts:

(1) Replace usages of "var Events = require" with "var Emitter = require" in sim repos first. This should be relative easy.

(2) Node extends Events has always felt a bit wrong. I don't think that Node should extend Emitter. But changing from inheritance to (e.g.) composition will complicate changes to client code.

(3) Use of the Events API for Node subtypes will be probably be the bulk of the changes to client code. This will be time-consuming and (potentially) destabilizing to locate and change.

[EDITED by @pixelzoom]

1 axon (Property)

Property and Node both extend Events.

Did you mean PropertySet? That currently extends Events and will be deleted once it is no longer used.

Yes, I meant PropertySet. Looks like you didn't see the EDIT to my comment above.

9/14/17 dev meeting:

Start by removing var Events from sims.
Then remove from dot and kite.
Then address scenery (where some of the usage is internal).

All of the above except FAPF is in @jonathanolson's wheelhouse, so he self assigned.

Co-assigning to @zepumph to work on the FPAF occurrences. It looks like all of the occurrences trigger update or updated, so these should all change to updatedEmitter.emit.

FPAF was completed in phetsims/fluid-pressure-and-flow#297. Unassigning.

Events has been deleted, closing.