@lowentry/react-redux 1.3.1 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/LeRed.js +36 -9
  2. package/package.json +1 -1
package/LeRed.js CHANGED
@@ -781,27 +781,54 @@ export const LeRed = (() =>
781
781
  {
782
782
  return LeRed.useEffect(() =>
783
783
  {
784
- let stop = false;
784
+ const run = () =>
785
+ {
786
+ callable();
787
+ };
788
+
789
+ if(typeof window !== 'undefined')
790
+ {
791
+ window.addEventListener('beforeunload', run, {capture:true});
792
+ }
793
+ return () =>
794
+ {
795
+ if(typeof window !== 'undefined')
796
+ {
797
+ window.removeEventListener('beforeunload', run, {capture:true});
798
+ }
799
+ run();
800
+ };
801
+ }, [comparingValues, equalsComparator]);
802
+ };
803
+
804
+ LeRed.useEffectPageFocusLost = (callable, comparingValues, equalsComparator) =>
805
+ {
806
+ const events = ['pagehide', 'freeze', 'blur', 'visibilitychange'];
807
+ return LeRed.useEffect(() =>
808
+ {
809
+ if((typeof window === 'undefined'))
810
+ {
811
+ return;
812
+ }
785
813
 
786
814
  const run = () =>
787
815
  {
788
- if(stop)
816
+ if(typeof document === 'undefined')
789
817
  {
790
818
  return;
791
819
  }
792
- stop = true;
793
- if(typeof window !== 'undefined')
820
+ if((document.visibilityState !== 'hidden') && document.hasFocus())
794
821
  {
795
- window.removeEventListener('beforeunload', run);
822
+ return;
796
823
  }
797
824
  callable();
798
825
  };
799
826
 
800
- if(typeof window !== 'undefined')
827
+ events.forEach(type => window.addEventListener(type, run, {capture:true}));
828
+ return () =>
801
829
  {
802
- window.addEventListener('beforeunload', run);
803
- }
804
- return run;
830
+ events.forEach(type => window.removeEventListener(type, run, {capture:true}));
831
+ };
805
832
  }, [comparingValues, equalsComparator]);
806
833
  };
807
834
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowentry/react-redux",
3
- "version": "1.3.1",
3
+ "version": "1.4.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Provides utilities for React and Redux.",