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

stack timeout listener #23

Merged
merged 4 commits into from
Jul 21, 2020

Conversation

hueitan
Copy link
Member

@hueitan hueitan commented Jul 17, 2020

PR related to #20
Comment related to beb4a3a#commitcomment-40695177

Before we introducing the delay feature for desktop, we deal with all the events synchronously, delay feature brings the race condition and asynchronous event execution. Also note that there is only one instance of popup, unless we declare popup instance for each new popup event.

Therefore this let us think more about the order of the event called, and all of them should be cleared empty once hide event is called, this POC shows the following

  1. A central place for all the event listener - No more manually remove each event listener, instead, remove ALL
  2. A central place for all the timeout - takes care of the timeout event whether it should execute or clear.

Let me know what do you see or foresee any problem.

@hueitan hueitan requested review from stephanebisson and medied July 17, 2020 20:16
@hueitan hueitan marked this pull request as draft July 17, 2020 20:30
@medied
Copy link
Contributor

medied commented Jul 20, 2020

I really like this approach Huei, it's a neat way to keep track of all events and therefore easily remove them.

I think we should move forward in this direction. However one issue I'm just realizing now is that a new popup will still accidentally hide if you go from one preview from one init instance/section/language to a different one:

<script type="text/javascript">
      wikipediaPreview.init({
        lang: 'en',
        root: document.querySelector('.content-en')
      });
      wikipediaPreview.init({
        lang: 'fr',
        root: document.querySelector('.content-fr')
      });
      wikipediaPreview.init({
        lang: 'es',
        root: document.querySelector('.content-es')
      });
      wikipediaPreview.init({
        lang: 'zh',
        root: document.querySelector('.content-zh')
      });
</script>

It seems a new popup (from a different init instance) activated within the 300ms does not have the updated stacks from the previous popup (of different init instance). I tried making both stacks somehow more globally accessible (using localStorage, declaring stacks in index.js and importing to event.js, attaching to popup, etc), but can't quite get it to work yet. Will continue trying.

@hueitan
Copy link
Member Author

hueitan commented Jul 21, 2020

It seems a new popup (from a different init instance) activated within the 300ms does not have the updated stacks from the previous popup (of different init instance). I tried making both stacks somehow more globally accessible (using localStorage, declaring stacks in index.js and importing to event.js, attaching to popup, etc), but can't quite get it to work yet. Will continue trying.

yup you are right, every single call of init has the popup within the scope, therefore my statement before wasn't right at all

there is only one instance of popup, unless we declare popup instance for each new popup event.

Will look into that! Thanks.

@hueitan
Copy link
Member Author

hueitan commented Jul 21, 2020

I think we should move forward in this direction. However one issue I'm just realizing now is that a new popup will still accidentally hide if you go from one preview from one init instance/section/language to a different one:

As we discuss, we will move this into another ticket, as this requires more changes to the overall codebase.

@hueitan hueitan marked this pull request as ready for review July 21, 2020 14:30
@hueitan hueitan changed the title POC stack timeout listener stack timeout listener Jul 21, 2020
src/event.js Outdated
@@ -1,27 +1,43 @@
import { isTouch } from './utils'

export const customEvents = popup => {
const onMouseLeave = e => {

var eventListenerStack = [],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let instead of var?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errr, right i don't know why it happens to var here, on it

@medied medied merged commit 27cdea0 into T256213-hover-closing-delay Jul 21, 2020
@medied medied deleted the POC-stack-timeout-listener branch July 21, 2020 14:48
stephanebisson pushed a commit that referenced this pull request Jul 27, 2020
* Add 300 ms delay to onMouseLeve

* Handle quick exit and re-enter

* Define previewElement at top of the scope

* Fix issue when quickly transitioning to a new popup

* stack timeout listener (#23)

* POC - stack all event listener and timeout event

* remove unused comment line

* naming clearAllEventListener

* var -> let

* Fix touch interaction

Co-authored-by: Huei Tan <hueitan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants