@adrianhelvik/bind
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -12,2 +12,10 @@ "use strict"; | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -34,22 +42,30 @@ | ||
value: function addUpdated(binding) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
if (this.trackers.size === 0) { | ||
var updateHandlers = _toConsumableArray(binding.updateHandlers); | ||
try { | ||
for (var _iterator = this.trackers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var tracker = _step.value; | ||
tracker.updated.add(binding); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
updateHandlers.forEach(function (fn) { | ||
fn(); | ||
}); | ||
} else { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator["return"] != null) { | ||
_iterator["return"](); | ||
for (var _iterator = this.trackers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var tracker = _step.value; | ||
tracker.updated.add(binding); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator["return"] != null) { | ||
_iterator["return"](); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
@@ -56,0 +72,0 @@ } |
@@ -10,3 +10,3 @@ "use strict"; | ||
function autorun(fn, whenTrue, whenFalse) { | ||
function reaction(fn, whenTrue, whenFalse) { | ||
var removers = []; | ||
@@ -30,3 +30,7 @@ var accessed; | ||
updated = _manager$track.updated; | ||
if (updated.size) throw Error('Encountered mutation in an autorun function.'); | ||
if (updated.size) { | ||
throw Error('Encountered mutation in a reaction.'); | ||
} | ||
var _iteratorNormalCompletion = true; | ||
@@ -39,3 +43,4 @@ var _didIteratorError = false; | ||
var binding = _step.value; | ||
removers.push(binding.onUpdate(update)); | ||
var removeListener = binding.onUpdate(update); | ||
removers.push(removeListener); | ||
} | ||
@@ -73,3 +78,3 @@ } catch (err) { | ||
var _default = autorun; | ||
var _default = reaction; | ||
exports["default"] = _default; |
{ | ||
"name": "@adrianhelvik/bind", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "module": "src/index.js", |
@@ -12,7 +12,18 @@ import Tracker from './Tracker.js' | ||
addUpdated(binding) { | ||
for (const tracker of this.trackers) tracker.updated.add(binding) | ||
if (this.trackers.size === 0) { | ||
const updateHandlers = [...binding.updateHandlers] | ||
updateHandlers.forEach(fn => { | ||
fn() | ||
}) | ||
} else { | ||
for (const tracker of this.trackers) { | ||
tracker.updated.add(binding) | ||
} | ||
} | ||
} | ||
addAccessed(binding) { | ||
for (const tracker of this.trackers) tracker.accessed.add(binding) | ||
for (const tracker of this.trackers) { | ||
tracker.accessed.add(binding) | ||
} | ||
} | ||
@@ -19,0 +30,0 @@ |
import { manager } from './state.js' | ||
function autorun(fn, whenTrue, whenFalse) { | ||
function reaction(fn, whenTrue, whenFalse) { | ||
let removers = [] | ||
@@ -18,7 +18,9 @@ let accessed | ||
if (updated.size) | ||
throw Error('Encountered mutation in an autorun function.') | ||
if (updated.size) { | ||
throw Error('Encountered mutation in a reaction.') | ||
} | ||
for (let binding of accessed) { | ||
removers.push(binding.onUpdate(update)) | ||
const removeListener = binding.onUpdate(update) | ||
removers.push(removeListener) | ||
} | ||
@@ -40,2 +42,2 @@ | ||
export default autorun | ||
export default reaction |
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
77005
43
2242