Commit aae5131ab41c69d3cbd719887d6650e3f70ad3c8
fix scroll performance drop caused by link preview global scroll handler
Matt McKegg committed on 11/11/2017, 9:08:14 AMParent: b35053e7c5a8f5e255e69269800c444f7978b8cb
Files changed
modules/app/link-preview.js | changed |
modules/app/link-preview.js | ||
---|---|---|
@@ -1,5 +1,5 @@ | ||
1 | -var { h, Value } = require('mutant') | |
1 | +var { h, Value, computed } = require('mutant') | |
2 | 2 | var ObserveLinkHover = require('../../lib/observe-link-hover') |
3 | 3 | var ref = require('ssb-ref') |
4 | 4 | |
5 | 5 | var nest = require('depnest') |
@@ -13,9 +13,8 @@ | ||
13 | 13 | |
14 | 14 | exports.create = function (api) { |
15 | 15 | var i18n = api.intl.sync.i18n |
16 | 16 | return nest('app.linkPreview', function (container, delay) { |
17 | - | |
18 | 17 | var currentHover = ObserveLinkHover(container, (value, lastValue) => { |
19 | 18 | var href = value && value.getAttribute('href') |
20 | 19 | var oldHref = lastValue && lastValue.getAttribute('href') |
21 | 20 | |
@@ -29,8 +28,18 @@ | ||
29 | 28 | return delay |
30 | 29 | }) |
31 | 30 | var previewElement = Value() |
32 | 31 | |
32 | + // hide preview on scroll | |
33 | + var hasPreview = computed(previewElement, x => !!x) | |
34 | + hasPreview(value => { | |
35 | + if (value) { | |
36 | + window.addEventListener('wheel', previewElement.cancel) | |
37 | + } else { | |
38 | + window.removeEventListener('wheel', previewElement.cancel) | |
39 | + } | |
40 | + }) | |
41 | + | |
33 | 42 | currentHover(element => { |
34 | 43 | var href = element && element.getAttribute('href') |
35 | 44 | var preview = null |
36 | 45 | |
@@ -47,9 +56,8 @@ | ||
47 | 56 | } |
48 | 57 | } |
49 | 58 | |
50 | 59 | if (preview) { |
51 | - preview.addEventListener('wheel', previewElement.cancel) | |
52 | 60 | var rect = element.getBoundingClientRect() |
53 | 61 | var width = 510 |
54 | 62 | var maxLeft = window.innerWidth - width |
55 | 63 | var maxTop = window.innerHeight - 100 |
@@ -84,10 +92,7 @@ | ||
84 | 92 | currentHover.cancel() |
85 | 93 | previewElement.set(null) |
86 | 94 | } |
87 | 95 | |
88 | - // hide preview on scroll | |
89 | - container.addEventListener('wheel', previewElement.cancel) | |
90 | - | |
91 | 96 | return previewElement |
92 | 97 | }) |
93 | 98 | } |
Built with git-ssb-web