Re: [w3c/gamepad] Add algorithms for getGamepads and events (#151)

@nondebug commented on this pull request.



>        </p>
     </section>
     <section>
       <h3 id="event-gamepaddisconnected">
         The <dfn class="event">gamepaddisconnected</dfn> event
       </h3>
+      <p>
+        When a gamepad becomes unavailable on the system, run the following
+        steps:
+      </p>
+      <ol>
+        <li>If the [=current settings object=]'s [=environment settings object
+        / responsible document=] is not [=allowed to use=] the `"gamepad"`
+        permission, then abort these steps.
+        </li>
+        <li>Let |gamepad:Gamepad| be the {{Gamepad}} representing the
+        unavailable device.
+        </li>
+        <li>Set |gamepad|.{{Gamepad/[[connected]]}} to `false`.

Agreed. We should update the gamepad state synchronously with firing the event to make sure the state changes are handled sequentially and predictably.

I think this order makes the most sense for gamepadconnected:

1. Create gamepad with gamepad.connected initialized to true
2. Add gamepad to navigator.[[gamepads]]
3. Dispatch gamepadconnected

And for gamepaddisconnected:

1. Set gamepad.connected to false
2. Dispatch gamepaddisconnected
3. Remove gamepad from navigator.[[gamepads]]

Updating in this order ensures the gamepad.connected state matches the stated reflected by the gamepadconnected or gamepaddisconnected event, and also ensures the item in the getGamepads() array at index gamepad.index is the same instance as the gamepad instance in the event.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/gamepad/pull/151#discussion_r666448580

Received on Thursday, 8 July 2021 19:04:21 UTC