Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add emitters to SimpleDragHandler #843

Closed
zepumph opened this issue Aug 15, 2018 · 33 comments
Closed

Add emitters to SimpleDragHandler #843

zepumph opened this issue Aug 15, 2018 · 33 comments

Comments

@zepumph
Copy link
Member

zepumph commented Aug 15, 2018

This will take over the events from SimpleDragHandlerIO, and we can then delete that type.

We can then uninstrument SimpleDragHandler and its sub emitters can be children of the draggable node.

@zepumph
Copy link
Member Author

zepumph commented Aug 15, 2018

This doesn't need to be done for FL stable because FL will be converted to use DragListener in phetsims/faradays-law#117

@samreid
Copy link
Member

samreid commented Sep 14, 2018

I tried this and there's a problem. SimpleDragHandler currently has:

        self.phetioStartEvent( 'dragged', {
          x: event.pointer.point.x,
          y: event.pointer.point.y
        }, HIGH_FREQUENCY_OPTIONS );

And if we convert to Emitter we will lose the ability to indicate

  var HIGH_FREQUENCY_OPTIONS = {
    highFrequency: true
  };

How should we address this? Would the high frequency options become an Emitter phetio option? Assigned to @zepumph for discussion, but feel free to escalate to a meeting label if you think that's appropriate.

@samreid samreid removed their assignment Sep 14, 2018
@zepumph
Copy link
Member Author

zepumph commented Sep 14, 2018

It seems like these options need to be promoted to a phetio prefixed option, i,e: phetioHighFrequencyEvents: true or something.

Then it should be passed to the phetioStartEvent calls in Emitter.emit() (because that will be the only method soon.)

Before we were worried about boxing us into "one type always either fully opts in or has to be completely out." Maybe we can convince ourselves that for Emitter that is ok, since Emitters only ever should be emitting for one single task, i.e. one specific phet-io event.

@zepumph zepumph assigned samreid and unassigned zepumph Sep 14, 2018
@samreid
Copy link
Member

samreid commented Sep 17, 2018

It looks like the other option key in PhetioObject.phetioStartEvent is phetioEventType, should it also be moved to the PhetioObject constructor options?

@samreid samreid assigned zepumph and unassigned samreid Sep 17, 2018
@zepumph
Copy link
Member Author

zepumph commented Sep 17, 2018

It already is!

image

@samreid
Copy link
Member

samreid commented Sep 27, 2018

Sounds good.

It seems like these options need to be promoted to a phetio prefixed option

Also, we can add that to the instanceMetadata as we did for phetioEventType. I'll work on this soon.

@samreid
Copy link
Member

samreid commented Oct 8, 2018

Keep in mind the drag event should be high frequency.

@zepumph
Copy link
Member Author

zepumph commented Oct 17, 2018

Graphing Quadratics should not go out until we convert this to use the new emitter pattern. Marking high priority.

@zepumph zepumph assigned samreid and chrisklus and unassigned samreid Oct 17, 2018
@zepumph zepumph assigned samreid and unassigned zepumph Jan 8, 2019
@samreid
Copy link
Member

samreid commented Jan 8, 2019

I think the "move everything to the Emitter" as exemplified in Input.js seems the cleanest (and maybe even removing the adapter methods altogether, maybe not), but I'm somewhat concerned that other developers may not like that pattern at all. Maybe we should discuss it with @jonathanolson and @pixelzoom? What do you think @zepumph?

@samreid samreid assigned zepumph and unassigned samreid Jan 8, 2019
@zepumph
Copy link
Member Author

zepumph commented Jan 8, 2019

We are pretty heavily invested in this approach at this point, and it doesn't seem to be causing issues atm. I think we are good to proceed. Could we either (a) move the scenery logging out of the emitters in SimpleDragHandler, or (b) move logging into the emitters in PressListener.

I think I prefer the first option, what do you think?

@zepumph zepumph assigned samreid and unassigned zepumph Jan 8, 2019
@pixelzoom
Copy link
Contributor

pixelzoom commented Jan 8, 2019

@samreid said:

... Maybe we should discuss it with @jonathanolson and @pixelzoom? ...

I am so out of the loop on this (I don't even know why we're adding Emitters to SImpleDragHandler) that I have nothing no feedback.

@samreid
Copy link
Member

samreid commented Jan 9, 2019

I would like to move the entire body of press() to the _pressedEmitter, but unfortunately, it has a return value which is not supported by Emitter. However, I looked through all usages of .press( event and didn't see any places where the return value is used, so maybe clients that really need that feature can call this.canPress( event ) on their own? Also, I'd like to eliminate the awkward onPress adapter, and just put the entire function body directly in _pressedEmitter: listener. Can we chat on these topics before moving forward?

@samreid samreid assigned zepumph and unassigned samreid Jan 9, 2019
@zepumph
Copy link
Member Author

zepumph commented Jan 9, 2019

so maybe clients that really need that feature can call this.canPress( event ) on their own?

That is a question for @jonathanolson, I feel like part of that has to do with subtyping. Note how children also have that capability. In FireListener, the value is also returned, though in DragListener it isn't used.

This may not be related, but Mouse.js has listeners that return values too. Perhaps this is a pattern used in scenery for some input related reasons? But so far my investigation didn't yield much, see Input.dispatchToListeners for where I think those functions are called, and nothing is being done with their return values.

@jonathanolson why does PressListener.press return a value?

EDIT:

Can we chat on these topics before moving forward?

Sure thing!

@jonathanolson
Copy link
Contributor

@jonathanolson why does PressListener.press return a value?

Since the subtype "overridden" press can see whether the press succeeded or not before continuing with other behavior. Its usage is:

var success = PressListener.prototype.press.call( this, event, targetNode, function() { /*...*/ } );

@jonathanolson jonathanolson removed their assignment Jan 17, 2019
@zepumph
Copy link
Member Author

zepumph commented Jan 18, 2019

That makes sense to me, assigning to @samreid for discussion.

@samreid
Copy link
Member

samreid commented Jan 19, 2019

@samreid said:

I'm somewhat concerned that other developers may not like that pattern at all.

@zepumph said:

We are pretty heavily invested in this approach at this point, and it doesn't seem to be causing issues atm. I think we are good to proceed.

@pixelzoom said:

I am so out of the loop on this (I don't even know why we're adding Emitters to SImpleDragHandler) that I have nothing no feedback.

I'll create a separate issue to review our patterns for inlining/instrumenting Emitters and see if the development team has questions or feedback.

Since the subtype "overridden" press can see whether the press succeeded or not before continuing with other behavior.

@jonathanolson are you aware of current usages of this, or is this mainly planning for potential future usage?

@pixelzoom
Copy link
Contributor

@samreid said:

I'm somewhat concerned that other developers may not like that pattern at all.

I fall heavily in that category. See my feedback in #928 (comment).

@zepumph
Copy link
Member Author

zepumph commented Jan 31, 2019

I think we have a clear step forward for this issue outlined in #928 (comment).

In addition it sounds like we need to keep the functionality of press's return value, so we should keep the content of pressedEmitter's callback (listener?) the way it is.

@samreid
Copy link
Member

samreid commented Feb 1, 2019

SimpleDragHandler is using Emitters in the style that we discussed in depth at today's PhET-iO meeting. In #928 (comment) we will update the pattern to use before instead of listener.

PressListener cannot put all of the logic in the Emitters since it requires return values, so the pattern it is using now seems reasonable. Technically, we could move the logic to listener for release but then it wouldn't match style for press so it is a wash.

Therefore I recommend we close this issue and continue in #928

@zepumph sound OK?

@samreid samreid removed their assignment Feb 1, 2019
@zepumph
Copy link
Member Author

zepumph commented Feb 1, 2019

Sounds good to me

@zepumph zepumph closed this as completed Feb 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants