Socket
Socket
Sign inDemoInstall

@adrianhelvik/bind

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.2 to 1.2.3

35

lib/reaction.js

@@ -36,36 +36,15 @@ "use strict";

if (updated.size) {
var _iterator = _createForOfIteratorHelper(updated),
_step;
var _iterator = _createForOfIteratorHelper(accessed),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var binding = _step.value;
if (accessed.has(binding)) {
throw Error("The binding \"".concat(binding.name, "\" is both read and mutated in a reaction."));
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
var _iterator2 = _createForOfIteratorHelper(accessed),
_step2;
try {
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _binding = _step2.value;
var removeListener = _binding.onUpdate(update);
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var binding = _step.value;
var removeListener = binding.onUpdate(update);
removers.push(removeListener);
}
} catch (err) {
_iterator2.e(err);
_iterator.e(err);
} finally {
_iterator2.f();
_iterator.f();
}

@@ -72,0 +51,0 @@

22

lib/reaction.spec.js

@@ -109,3 +109,3 @@ "use strict";

});
it('throws if a dependency is updated in a reaction', function () {
xit('throws if a dependency is updated in a reaction', function () {
var state = (0, _observable["default"])({

@@ -115,6 +115,20 @@ count: 0

expect(function () {
return (0, _reaction["default"])(function () {
return state.count++;
(0, _reaction["default"])(function () {
state.count += 1;
console.log("The count is: ".concat(state.count));
});
}).toThrow();
}).not.toThrow();
});
it('does not throw if a reaction triggers a reaction', function () {
var state = (0, _observable["default"])({
message: '',
greetings: 0
});
(0, _reaction["default"])(function () {
console.log("Greetings delivered: ".concat(state.greetings));
});
(0, _reaction["default"])(function () {
console.log(state.message);
state.greetings += 1;
});
});
{
"name": "@adrianhelvik/bind",
"version": "1.2.2",
"version": "1.2.3",
"main": "lib/index.js",

@@ -5,0 +5,0 @@ "module": "src/index.js",

@@ -18,12 +18,2 @@ import { manager } from './state.js'

if (updated.size) {
for (const binding of updated) {
if (accessed.has(binding)) {
throw Error(
`The binding "${binding.name}" is both read and mutated in a reaction.`,
)
}
}
}
for (let binding of accessed) {

@@ -30,0 +20,0 @@ const removeListener = binding.onUpdate(update)

@@ -85,3 +85,3 @@ import observable from './observable.js'

it('throws if a dependency is updated in a reaction', () => {
xit('throws if a dependency is updated in a reaction', () => {
const state = observable({

@@ -91,3 +91,24 @@ count: 0,

expect(() => reaction(() => state.count++)).toThrow()
expect(() => {
reaction(() => {
state.count += 1
console.log(`The count is: ${state.count}`)
})
}).not.toThrow()
})
it('does not throw if a reaction triggers a reaction', () => {
const state = observable({
message: '',
greetings: 0,
})
reaction(() => {
console.log(`Greetings delivered: ${state.greetings}`)
})
reaction(() => {
console.log(state.message)
state.greetings += 1
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc