Socket
Socket
Sign inDemoInstall

@adrianhelvik/bind

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adrianhelvik/bind - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

53

lib/reaction.js

@@ -31,26 +31,53 @@ "use strict";

if (updated.size) {
throw Error('Encountered mutation in a reaction.');
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = updated[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var binding = _step.value;
if (accessed.has(binding)) {
throw Error('Encountered mutation in a reaction.');
}
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator = accessed[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var binding = _step.value;
var removeListener = binding.onUpdate(update);
for (var _iterator2 = accessed[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _binding = _step2.value;
var removeListener = _binding.onUpdate(update);
removers.push(removeListener);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
_iterator["return"]();
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
_iterator2["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
if (_didIteratorError2) {
throw _iteratorError2;
}

@@ -57,0 +84,0 @@ }

@@ -104,2 +104,21 @@ "use strict";

expect(result).toEqual(['reaction 1', 'reaction 2']);
});
it('does not error when updating unrelated state in a reaction', function () {
var state = (0, _observable["default"])({
a: true
});
(0, _reaction["default"])(function () {
if (state.a) state.b = true;
});
expect(state.b).toBe(true);
});
it('throws if a dependency is updated in a reaction', function () {
var state = (0, _observable["default"])({
count: 0
});
expect(function () {
return (0, _reaction["default"])(function () {
return state.count++;
});
}).toThrow();
});
{
"name": "@adrianhelvik/bind",
"version": "1.2.0",
"version": "1.2.1",
"main": "lib/index.js",

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

@@ -19,3 +19,7 @@ import { manager } from './state.js'

if (updated.size) {
throw Error('Encountered mutation in a reaction.')
for (const binding of updated) {
if (accessed.has(binding)) {
throw Error('Encountered mutation in a reaction.')
}
}
}

@@ -22,0 +26,0 @@

@@ -72,1 +72,21 @@ import observable from './observable.js'

})
it('does not error when updating unrelated state in a reaction', () => {
const state = observable({
a: true,
})
reaction(() => {
if (state.a) state.b = true
})
expect(state.b).toBe(true)
})
it('throws if a dependency is updated in a reaction', () => {
const state = observable({
count: 0,
})
expect(() => reaction(() => state.count++)).toThrow()
})
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc