changes from review
This commit is contained in:
parent
75a117e4e2
commit
933c7330a5
2 changed files with 21 additions and 16 deletions
|
@ -20,7 +20,6 @@ class CallbacksRegistry {
|
||||||
const regexp = /at (.*)/gi
|
const regexp = /at (.*)/gi
|
||||||
const stackString = (new Error()).stack
|
const stackString = (new Error()).stack
|
||||||
|
|
||||||
let ref
|
|
||||||
let filenameAndLine
|
let filenameAndLine
|
||||||
let match
|
let match
|
||||||
|
|
||||||
|
@ -29,7 +28,7 @@ class CallbacksRegistry {
|
||||||
if (location.includes('native')) continue
|
if (location.includes('native')) continue
|
||||||
if (location.includes('electron.asar')) continue
|
if (location.includes('electron.asar')) continue
|
||||||
|
|
||||||
ref = /([^/^)]*)\)?$/gi.exec(location)
|
const ref = /([^/^)]*)\)?$/gi.exec(location)
|
||||||
filenameAndLine = ref[1]
|
filenameAndLine = ref[1]
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -40,7 +39,7 @@ class CallbacksRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
get (id) {
|
get (id) {
|
||||||
return this.callbacks[id] != null ? this.callbacks[id] : function () {}
|
return this.callbacks[id] || function () {}
|
||||||
}
|
}
|
||||||
|
|
||||||
apply (id, ...args) {
|
apply (id, ...args) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const assert = require('assert')
|
const {assert} = require('chai')
|
||||||
const {CallbacksRegistry} = require('electron')
|
const {CallbacksRegistry} = require('electron')
|
||||||
|
|
||||||
describe('CallbacksRegistry module', () => {
|
describe.only('CallbacksRegistry module', () => {
|
||||||
let registry = null
|
let registry = null
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -10,33 +10,39 @@ describe('CallbacksRegistry module', () => {
|
||||||
|
|
||||||
it('adds a callback to the registry', () => {
|
it('adds a callback to the registry', () => {
|
||||||
const cb = () => [1, 2, 3, 4, 5]
|
const cb = () => [1, 2, 3, 4, 5]
|
||||||
const id = registry.add(cb)
|
const key = registry.add(cb)
|
||||||
assert.equal(id, 1)
|
|
||||||
|
assert.exists(key)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns a specified callback if it is in the registry', () => {
|
it('returns a specified callback if it is in the registry', () => {
|
||||||
const cb = () => [1, 2, 3, 4, 5]
|
const cb = () => [1, 2, 3, 4, 5]
|
||||||
registry.add(cb)
|
const key = registry.add(cb)
|
||||||
|
const callback = registry.get(key)
|
||||||
|
|
||||||
const callback = registry.get(1)
|
|
||||||
assert.equal(callback.toString(), cb.toString())
|
assert.equal(callback.toString(), cb.toString())
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns an empty function if the cb doesnt exist', () => {
|
it('returns an empty function if the cb doesnt exist', () => {
|
||||||
const callback = registry.get(1)
|
const callback = registry.get(1)
|
||||||
assert.equal(callback.toString(), 'function () {}')
|
|
||||||
|
assert.isFunction(callback)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('removes a callback to the registry', () => {
|
it('removes a callback to the registry', () => {
|
||||||
const cb = () => [1, 2, 3, 4, 5]
|
const cb = () => [1, 2, 3, 4, 5]
|
||||||
const id = registry.add(cb)
|
const key = registry.add(cb)
|
||||||
assert.equal(id, 1)
|
|
||||||
|
assert.exists(key)
|
||||||
|
|
||||||
|
const beforeCB = registry.get(key)
|
||||||
|
|
||||||
const beforeCB = registry.get(1)
|
|
||||||
assert.equal(beforeCB.toString(), cb.toString())
|
assert.equal(beforeCB.toString(), cb.toString())
|
||||||
|
|
||||||
registry.remove(1)
|
registry.remove(key)
|
||||||
const afterCB = registry.get(1)
|
const afterCB = registry.get(key)
|
||||||
assert.equal(afterCB.toString(), 'function () {}')
|
|
||||||
|
assert.isFunction(afterCB)
|
||||||
|
assert.notEqual(afterCB.toString(), cb.toString())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue