Comparing version 1.5.1 to 1.6.0
# Postman UVM Changelog | ||
#### 1.6.0 (May 30, 2017) | ||
* add support for removal of bridge events (internal) using `bridge.off` | ||
#### 1.5.1 (May 29, 2017) | ||
@@ -4,0 +7,0 @@ * uvm now dispatches `disconnect` event right before disconnecting |
@@ -39,4 +39,19 @@ /** | ||
on: function (name, listener) { | ||
if (typeof listener !== 'function') { return; } | ||
!this._events[name] && (this._events[name] = []); | ||
this._events[name].push(listener); | ||
}, | ||
off: function (name, listener) { | ||
var e = this._events[name], | ||
i = e && this._events[name].length; | ||
if (!e) { return; } | ||
if (typeof listener === 'function' && (i >= 1)) { | ||
while (i >= 0) { | ||
(e[i] === listener) && e.splice(i, 1); | ||
i -= 1; | ||
} | ||
} | ||
if (!e.length) { delete this._events[name]; } | ||
} | ||
@@ -43,0 +58,0 @@ }; |
{ | ||
"name": "uvm", | ||
"version": "1.5.1", | ||
"version": "1.6.0", | ||
"description": "Universal Virtual Machine for Node and Browser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -150,2 +150,48 @@ var vm = require('vm'); | ||
it('must be able to remove a particular registered event', function (done) { | ||
var context = vm.createContext({ | ||
expect: expect, | ||
__uvm_emit: function () { | ||
throw new Error('Nothing should be emitted'); | ||
}, | ||
done: function () { | ||
expect(arguments.length).be(0); | ||
done(); | ||
} | ||
}); | ||
vm.runInContext(bridgeClient(), context); | ||
vm.runInContext(` | ||
var one = false, | ||
two = false, | ||
updateTwo; | ||
bridge.on('loopback', function () { | ||
expect(one).be(false); | ||
expect(two).be(false); | ||
one = true; | ||
}); | ||
updateTwo = function () { | ||
expect(one).be(true); | ||
expect(two).be(false); | ||
two = true; | ||
}; | ||
bridge.on('loopback', updateTwo); | ||
bridge.on('loopback', function () { | ||
expect(one).be(true); | ||
expect(two).be(false); | ||
done(); | ||
}); | ||
bridge.off('loopback', updateTwo); // remove one event | ||
bridge.emit('loopback'); | ||
`, context); | ||
}); | ||
it('must not leave behind any additional globals except `bridge` related', function (done) { | ||
@@ -152,0 +198,0 @@ var context = vm.createContext({ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
115807
1882