Skip to content

Commit 9179e9c

Browse files
committed
fix(): add support for multiple listeners
1 parent 381fcee commit 9179e9c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/serverHistory.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import {createLocation} from './util'
22

3-
function ServerHistory() {}
3+
function ServerHistory() {
4+
this.listeners = []
5+
}
46

57
ServerHistory.prototype.listen = function listen(listener) {
6-
this.listener = listener
8+
this.listeners.push(listener)
79
}
810

911
ServerHistory.prototype.push = function push(location) {
10-
const listener = this.listener
11-
if (!listener) {
12+
const listeners = this.listeners
13+
if (!listeners || listeners.length === 0) {
1214
throw new Error('There is no active listener')
1315
}
14-
listener(createLocation(location))
16+
listeners.forEach(l => l(createLocation(location)))
1517
}
1618

1719
ServerHistory.prototype.createHref = function createHref(path) {

0 commit comments

Comments
 (0)