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

ISSUE-31 update on window resize and path change #36

Merged
merged 12 commits into from
Jun 14, 2017

Conversation

simonhearne
Copy link
Contributor

I ended up implementing an interval as one was required to check for path changes anyway, it also handily debounces the resize.
onHashChange doesn't always work e.g. https://www.oliverbonas.com/ is a SPA that updates the path, not hash. Set it at 500ms which seems like a reasonable compromise.

@simonhearne simonhearne reopened this May 22, 2017
app/public.js Outdated
*/
function refreshImagesInfo() {
hideImagesInfo();
showImagesInfo(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

@simonhearne DoD - why send null? there is no need. undefined is good enough

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

app/public.js Outdated
let path = window.location.pathname;
let update;

interval = setInterval(function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@simonhearne CONSISTENCY - setInterval(() => {})

app/public.js Outdated
let path = window.location.pathname;
let update;

interval = setInterval(function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@simonhearne DoD - should clear interval before creating a new one as we're always create another interval every time showImagesInfo is called

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's cleared in hideImagesInfo(). Assume we never call showImagesInfo() twice without hideImagesInfo()? Then we would get duplicate overlays. Could add a check in showImagesInfo() for isImagesInforActive() then hide first... new issue for that?

Copy link
Contributor

Choose a reason for hiding this comment

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

the idea is to not depend on a different method for clearing the interval. this couples those 2 methods together. in the case of calling showImagesInfo twice, it should be safe, including clearing existing overlays and existing intervals.

perhaps showImagesInfo should always call hideImagesInfo at the beginning to ensure a clean slate.

app/public.js Outdated
@@ -21,6 +21,8 @@
const SVG_URL_REGEX = /\.svg/i;
const SVG_DATA_URI_REGEX = /^data:.*\/svg/i;
const MIN_IMAGE_SIZE = 10;
const CHECKER_INTERVAL_MS = 500;
let interval;
Copy link
Contributor

Choose a reason for hiding this comment

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

@simonhearne MAINTENANCE - use a more descriptive name like refreshImagesInterval

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, done.

Copy link
Contributor Author

@simonhearne simonhearne left a comment

Choose a reason for hiding this comment

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

Updated branch to include the requested changes.

@tabanliviu
Copy link
Contributor

@simonhearne still need to add unit tests 😄

@tabanliviu tabanliviu changed the title Issue 31 - update on window resize and path change ISSUE 31 - update on window resize and path change May 24, 2017
@tabanliviu
Copy link
Contributor

fixes #31

@tabanliviu tabanliviu changed the title ISSUE 31 - update on window resize and path change ISSUE-31 update on window resize and path change Jun 7, 2017
@Ian-Hi
Copy link

Ian-Hi commented Jun 9, 2017

Verified ok

@tabanliviu tabanliviu requested a review from MalcolmSmithUK June 9, 2017 15:30
app/public.js Outdated
/* istanbul ignore if */
if (window.location.pathname !== path) {
update = true;
path = window.location.pathname;

Choose a reason for hiding this comment

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

@tabanliviu DoD - This doesn't include changes in the hash (either for traditional hash or non-HTML5 SPAs).

Copy link
Contributor

Choose a reason for hiding this comment

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

OK

/**
* Set event listeners
*/
function setRefreshImagesWatcher() {

Choose a reason for hiding this comment

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

@tabanliviu MAINTAINABILITY - Please clear the timeout in case another event implements the same method.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK

@tabanliviu
Copy link
Contributor

@MalcolmSmithUK ready for review

@tabanliviu tabanliviu merged commit 20599f4 into development Jun 14, 2017
@tabanliviu tabanliviu deleted the ISSUE-31-event_listeners branch June 14, 2017 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants