1.0.1 • Published 3 years ago

usedomlocation v1.0.1

Weekly downloads
22
License
APACHE-2.0
Repository
github
Last release
3 years ago

A helper hook for monitoring page changes in Mendix Widgets.

Mendix is a SPA and window.onpopstate is inconsistent in detecting location changes, and only seems to fire if back and forward button in the browser is clicked.

What useDomLocation does:

It monitors changes in the Dom using the MutationObserver, and when changes are detected it will check window.history or mx.ui.getContentForm() for changes. If there are changes it will fire a Callback function you passed in, thus giving you a reliable way to monitor page changes.

As MutationObserver will fire a lot ,but is very performant, when the page location is changed and even fire when stuff like info boxes are opened, useDomLocation throttles the MutationObserver.

Normal back and forward button presses are handled by window.onpopstate.

useDomLocation will not fire on Page Load.

const { lastUpdateTime, createObserver, turnOffObserver } = useDomLocation({
  locationCallBack,
  throttleDuration: 500,
  useMendixNav: true,
});
TypeInfo
locationCallBackfuncThe callback that will fire when Location is detected
throttleDurationnumberFor how long the MutantObserver must be throttled
useMendixNavbooleanIndicate if you are using it in a mendix Widget, true for Mendix false for non Mendix apps
TypeInfo
lastUpdateTimeDatePasses back the last time the dom was updated.
createObservernumberManually Create observer
turnOffObserverbooleanManually turn off observer

Please open an GH issue.