@hellotext/hellotext 1.1.1 → 1.1.3
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/README.md +2 -2
- package/__tests__/hellotext_test.js +15 -3
- package/lib/hellotext.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -188,10 +188,10 @@ To listen to an event, you can call the `on` method, like so
|
|
|
188
188
|
Hellotext.on(eventName, callback)
|
|
189
189
|
```
|
|
190
190
|
|
|
191
|
-
To
|
|
191
|
+
To remove an event listener, you can call `removeEventListener`
|
|
192
192
|
|
|
193
193
|
```javascript
|
|
194
|
-
Hellotext.
|
|
194
|
+
Hellotext.removeEventListener(eventName, callback)
|
|
195
195
|
```
|
|
196
196
|
|
|
197
197
|
### List of events
|
|
@@ -129,7 +129,19 @@ describe(".on", () => {
|
|
|
129
129
|
});
|
|
130
130
|
});
|
|
131
131
|
|
|
132
|
-
describe("
|
|
132
|
+
describe("when session is stored in the cookie", function () {
|
|
133
|
+
beforeAll(() => {
|
|
134
|
+
document.cookie = `hello_session=12345`
|
|
135
|
+
Hellotext.initialize(123)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it("Assigns session from cookie", function () {
|
|
139
|
+
expect(Hellotext.session).toEqual("12345")
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
describe(".removeEventListener", () => {
|
|
133
145
|
const business_id = "xy76ks"
|
|
134
146
|
|
|
135
147
|
beforeAll(() => {
|
|
@@ -141,7 +153,7 @@ describe(".disconnect", () => {
|
|
|
141
153
|
|
|
142
154
|
it("throws an error when event is invalid", () => {
|
|
143
155
|
expect(
|
|
144
|
-
() => Hellotext.
|
|
156
|
+
() => Hellotext.removeEventListener("undefined-event", () => {})
|
|
145
157
|
).toThrowError()
|
|
146
158
|
});
|
|
147
159
|
|
|
@@ -149,7 +161,7 @@ describe(".disconnect", () => {
|
|
|
149
161
|
const callback = jest.fn()
|
|
150
162
|
|
|
151
163
|
Hellotext.on("session-set", callback)
|
|
152
|
-
Hellotext.
|
|
164
|
+
Hellotext.removeEventListener("session-set", callback)
|
|
153
165
|
|
|
154
166
|
expect(callback).toHaveBeenCalledTimes(0)
|
|
155
167
|
});
|
package/lib/hellotext.js
CHANGED
|
@@ -74,7 +74,7 @@ class Hellotext {
|
|
|
74
74
|
* @param event the name of the event to remove
|
|
75
75
|
* @param callback the callback to remove
|
|
76
76
|
*/
|
|
77
|
-
static
|
|
77
|
+
static removeEventListener(event, callback) {
|
|
78
78
|
if(Event.invalid(event)) { throw new InvalidEvent(event) }
|
|
79
79
|
|
|
80
80
|
this.#eventEmitter.removeSubscriber(event, callback)
|
|
@@ -137,7 +137,7 @@ class Hellotext {
|
|
|
137
137
|
document.cookie = `hello_session=${this.#session}`
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
static #cookie() {
|
|
140
|
+
static get #cookie() {
|
|
141
141
|
return document.cookie.match('(^|;)\\s*' + 'hello_session' + '\\s*=\\s*([^;]+)')?.pop()
|
|
142
142
|
}
|
|
143
143
|
}
|