Skip to content

Commit 36cf94e

Browse files
committed
adding event callback
1 parent 88f5e93 commit 36cf94e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
var socket1 = socket(public_key, {
3333
element: '#socket1',
3434
api_root: api_root,
35+
event_callback: function (name, v) {
36+
console.log(name, v)
37+
}
3538
})
3639
socket(public_key, {
3740
element: '#socket2',

src/main.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ module.exports = function (public_key, config) {
144144
config.subject_filter = true
145145
}
146146

147+
if (!config.event_callback) {
148+
config.event_callback = () => null
149+
}
150+
147151
if (document.querySelector(config.element) === null) {
148152
config.console.error(`SOCKET: page element "${config.element}" does not exist, unable to start socket view.`)
149153
return
@@ -228,7 +232,7 @@ ${xhr.responseText}`)
228232
}
229233
xhr.send(data || null)
230234
},
231-
request_list (url, data_property) {
235+
request_list (url, data_property, callback) {
232236
this.request(url, (xhr) => {
233237
let items
234238
if (xhr.status !== 200) {
@@ -238,6 +242,7 @@ ${xhr.responseText}`)
238242
}
239243
data_property.splice(0)
240244
items.forEach(con => data_property.push(con))
245+
callback && callback(this)
241246
})
242247
},
243248
get_contractor_list () {
@@ -265,7 +270,8 @@ ${xhr.responseText}`)
265270
if (arg_list.length > 0) {
266271
url += '?' + arg_list.join('&')
267272
}
268-
this.request_list(url, this.contractors)
273+
const cb = (t) => this.config.event_callback('updated_contractors', t)
274+
this.request_list(url, this.contractors, cb)
269275
},
270276
get_contractor_details (url, link) {
271277
if (this.contractors_extra[link] !== undefined) {

0 commit comments

Comments
 (0)