On Wed, Nov 18, 2015 at 10:52 PM, Marcus Cavanaugh <[email protected]> wrote:
>
> 1. From SomeWidget's perspective, it's not clear why we emit the
> event. (Here, the sole reason we emit the event is to ensure
> InputWindowManager handles the hook at the right time.)
>
> 2. From InputWindowManager's perspective, we now have a group of logic
> that needs to run in response to a bunch of different events. Rather than
> reducing coupling, we've just moved the explicit dependency to
> InputWindowManager, disguised as an event.
>
> 3. This pattern contributes to "event spaghetti", wherein code becomes
> difficult to refactor and rationalize about due to the hidden entanglement
> and cascading nature of event dispatching.
>
> Dead on.
>
> For cases like this, where we _need_ a specific action to be performed, I
> think we should be more explicit about what, precisely, we want to happen:
>
I like the way this is phrased, and it's an important precision. There
needs to be a strong 1-1 dependency (although not yet explicit in our code).
>
> // SomeWidget.js:
> Service.request('InputWindowManager.releaseWindowFocus')
There's one little issue.
Lets say we're on a device without an InputWindowManager (a pc-like dongle
with a keyboard), Service.js will queue the requests indefinitely [1].
So I'd suggest adding a Service.requestIfAvailable() or similar
(Service.ask() ?) to prevent this.
I have a feeling the "semantic event" approach would degenerate quickly :)
Thank you for caring!
[1]
https://github.com/mozilla-b2g/gaia/blob/ffaade435bb9c3005fd6c9b7ee1cd17b90e08cbf/apps/system/js/service.js#L90-L94
_______________________________________________
dev-fxos mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-fxos