@ouroboros/browser 0.5.5 → 0.5.6
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.
- package/ouroboros-browser-0.5.6.tgz +0 -0
- package/package.json +1 -1
- package/pageVisibility.d.ts +12 -0
- package/pageVisibility.js +31 -18
- package/src/pageVisibility.ts +34 -20
|
Binary file
|
package/package.json
CHANGED
package/pageVisibility.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ import Subscribe, { SubscribeCallback, SubscribeReturn } from '@ouroboros/subscr
|
|
|
17
17
|
* @extends Subscribe
|
|
18
18
|
*/
|
|
19
19
|
declare class PageVisibility extends Subscribe {
|
|
20
|
+
#private;
|
|
20
21
|
/**
|
|
21
22
|
* Constructor
|
|
22
23
|
*
|
|
@@ -27,6 +28,17 @@ declare class PageVisibility extends Subscribe {
|
|
|
27
28
|
* @returns PageVisibility
|
|
28
29
|
*/
|
|
29
30
|
constructor();
|
|
31
|
+
/**
|
|
32
|
+
* Set
|
|
33
|
+
*
|
|
34
|
+
* Overrides Subscribe.set to make sure no one can call it without a failure
|
|
35
|
+
*
|
|
36
|
+
* @name set
|
|
37
|
+
* @access public
|
|
38
|
+
* @param data The new data to set and then send
|
|
39
|
+
* @returns void
|
|
40
|
+
*/
|
|
41
|
+
set(data: any): boolean;
|
|
30
42
|
/**
|
|
31
43
|
* Subscribe
|
|
32
44
|
*
|
package/pageVisibility.js
CHANGED
|
@@ -35,22 +35,6 @@ else {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Track
|
|
40
|
-
*
|
|
41
|
-
* The actual function passed to the event so that we only have one event
|
|
42
|
-
* listener
|
|
43
|
-
*
|
|
44
|
-
* @name track
|
|
45
|
-
* @access private
|
|
46
|
-
*/
|
|
47
|
-
function track() {
|
|
48
|
-
// Set the data so the instance notifies subscribers
|
|
49
|
-
pageVisibility.set({
|
|
50
|
-
property: document[properties.property],
|
|
51
|
-
state: document[properties.state]
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
38
|
/**
|
|
55
39
|
* Page Visibility
|
|
56
40
|
*
|
|
@@ -76,6 +60,19 @@ class PageVisibility extends Subscribe {
|
|
|
76
60
|
state: document[properties.state]
|
|
77
61
|
} : null);
|
|
78
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Set
|
|
65
|
+
*
|
|
66
|
+
* Overrides Subscribe.set to make sure no one can call it without a failure
|
|
67
|
+
*
|
|
68
|
+
* @name set
|
|
69
|
+
* @access public
|
|
70
|
+
* @param data The new data to set and then send
|
|
71
|
+
* @returns void
|
|
72
|
+
*/
|
|
73
|
+
set(data) {
|
|
74
|
+
throw new Error('Calling PageVisibility.set() is forbidden');
|
|
75
|
+
}
|
|
79
76
|
/**
|
|
80
77
|
* Subscribe
|
|
81
78
|
*
|
|
@@ -90,11 +87,27 @@ class PageVisibility extends Subscribe {
|
|
|
90
87
|
// If we have no current subscribers
|
|
91
88
|
if (apiAvailable && this.subscribeCallbacks.length === 0) {
|
|
92
89
|
// Add the event listener
|
|
93
|
-
document.addEventListener(properties.event, track);
|
|
90
|
+
document.addEventListener(properties.event, this.#track);
|
|
94
91
|
}
|
|
95
92
|
// Call the parent subscribe and return
|
|
96
93
|
return super.subscribe(callback);
|
|
97
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Track
|
|
97
|
+
*
|
|
98
|
+
* The actual function passed to the event so that we only have one event
|
|
99
|
+
* listener
|
|
100
|
+
*
|
|
101
|
+
* @name track
|
|
102
|
+
* @access private
|
|
103
|
+
*/
|
|
104
|
+
#track = () => {
|
|
105
|
+
// Set the data so the instance notifies subscribers
|
|
106
|
+
super.set({
|
|
107
|
+
property: document[properties.property],
|
|
108
|
+
state: document[properties.state]
|
|
109
|
+
});
|
|
110
|
+
};
|
|
98
111
|
/**
|
|
99
112
|
* Unsubscribe
|
|
100
113
|
*
|
|
@@ -115,7 +128,7 @@ class PageVisibility extends Subscribe {
|
|
|
115
128
|
// If it was successful and we have no more callbacks
|
|
116
129
|
if (bRet && this.subscribeCallbacks.length === 0) {
|
|
117
130
|
// Remove the event listener
|
|
118
|
-
document.removeEventListener(properties.event, track);
|
|
131
|
+
document.removeEventListener(properties.event, this.#track);
|
|
119
132
|
}
|
|
120
133
|
// Return
|
|
121
134
|
return bRet;
|
package/src/pageVisibility.ts
CHANGED
|
@@ -45,24 +45,6 @@ else {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
/**
|
|
49
|
-
* Track
|
|
50
|
-
*
|
|
51
|
-
* The actual function passed to the event so that we only have one event
|
|
52
|
-
* listener
|
|
53
|
-
*
|
|
54
|
-
* @name track
|
|
55
|
-
* @access private
|
|
56
|
-
*/
|
|
57
|
-
function track(): void {
|
|
58
|
-
|
|
59
|
-
// Set the data so the instance notifies subscribers
|
|
60
|
-
pageVisibility.set({
|
|
61
|
-
property: document[properties.property as keyof Document],
|
|
62
|
-
state: document[properties.state as keyof Document]
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
48
|
/**
|
|
67
49
|
* Page Visibility
|
|
68
50
|
*
|
|
@@ -91,6 +73,20 @@ class PageVisibility extends Subscribe {
|
|
|
91
73
|
} : null);
|
|
92
74
|
}
|
|
93
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Set
|
|
78
|
+
*
|
|
79
|
+
* Overrides Subscribe.set to make sure no one can call it without a failure
|
|
80
|
+
*
|
|
81
|
+
* @name set
|
|
82
|
+
* @access public
|
|
83
|
+
* @param data The new data to set and then send
|
|
84
|
+
* @returns void
|
|
85
|
+
*/
|
|
86
|
+
set(data: any): boolean {
|
|
87
|
+
throw new Error('Calling PageVisibility.set() is forbidden');
|
|
88
|
+
}
|
|
89
|
+
|
|
94
90
|
/**
|
|
95
91
|
* Subscribe
|
|
96
92
|
*
|
|
@@ -107,13 +103,31 @@ class PageVisibility extends Subscribe {
|
|
|
107
103
|
if(apiAvailable && this.subscribeCallbacks.length === 0) {
|
|
108
104
|
|
|
109
105
|
// Add the event listener
|
|
110
|
-
document.addEventListener(properties.event, track);
|
|
106
|
+
document.addEventListener(properties.event, this.#track);
|
|
111
107
|
}
|
|
112
108
|
|
|
113
109
|
// Call the parent subscribe and return
|
|
114
110
|
return super.subscribe(callback);
|
|
115
111
|
}
|
|
116
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Track
|
|
115
|
+
*
|
|
116
|
+
* The actual function passed to the event so that we only have one event
|
|
117
|
+
* listener
|
|
118
|
+
*
|
|
119
|
+
* @name track
|
|
120
|
+
* @access private
|
|
121
|
+
*/
|
|
122
|
+
#track = () => {
|
|
123
|
+
|
|
124
|
+
// Set the data so the instance notifies subscribers
|
|
125
|
+
super.set({
|
|
126
|
+
property: document[properties.property as keyof Document],
|
|
127
|
+
state: document[properties.state as keyof Document]
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
117
131
|
/**
|
|
118
132
|
* Unsubscribe
|
|
119
133
|
*
|
|
@@ -138,7 +152,7 @@ class PageVisibility extends Subscribe {
|
|
|
138
152
|
if(bRet && this.subscribeCallbacks.length === 0) {
|
|
139
153
|
|
|
140
154
|
// Remove the event listener
|
|
141
|
-
document.removeEventListener(properties.event, track);
|
|
155
|
+
document.removeEventListener(properties.event, this.#track);
|
|
142
156
|
}
|
|
143
157
|
|
|
144
158
|
// Return
|