Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reactive-box

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reactive-box - npm Package Compare versions

Comparing version 0.1.7 to 0.2.0

4

package.json
{
"name": "reactive-box",
"version": "0.1.7",
"version": "0.2.0",
"description": "Minimalistic, fast, and highly efficient reactivity",

@@ -47,3 +47,3 @@ "scripts": {

"homepage": "https://github.com/betula/reactive-box#readme",
"gitHead": "0f115d5d63ce4be2d932f2ef57a4b24aefda0d3c"
"gitHead": "fb575f497551405fc044780b73f21c787656f8ed"
}

@@ -5,2 +5,3 @@ /**

* 2: (valid for sel)
* 3: (recalc for sel)
*/

@@ -28,5 +29,5 @@ let context_node;

else {
const syncs = new Set();
const exprs = new Set();
const sels = new Set();
let limit = 10000;
let next_bound = new Set();

@@ -37,19 +38,25 @@ active_bound = new Set(box_node[0]);

active_bound.forEach((node) => {
if (node.length === 2) syncs.add(node[0]);
if (node.length === 2) exprs.add(node);
else {
node[2] = 0; // sel invalidate
node[0].forEach((next_node) => next_bound.add(next_node));
free(node, 0);
if (node[0].size) sels.add(node);
else node[2] = 0;
}
free(node, 1);
});
[active_bound, next_bound] = [next_bound, active_bound];
next_bound.clear();
active_bound.clear();
sels.forEach((sel_node) => {
if (sel_node[3]()) {
sel_node[0].forEach((rel) => active_bound.add(rel));
free(sel_node, 0);
}
});
sels.clear();
if (!active_bound.size) {
const iter = syncs.values();
let sync;
while ((sync = iter.next().value)) {
sync();
syncs.delete(sync);
const iter = exprs.values();
let expr_node;
while ((expr_node = iter.next().value)) {
expr_node[0]();
exprs.delete(expr_node);
if (active_bound.size) break;

@@ -81,4 +88,6 @@ }

: (next_value) => {
Object.is(value, next_value) ||
((value = next_value), write(box_node));
if (!Object.is(value, next_value)) {
value = next_value;
write(box_node);
}
},

@@ -89,7 +98,20 @@ ];

const sel = (body) => {
const sel_node = [new Set(), new Set(), 0];
let cache;
let last_context;
const recalc = () => {
let prev = cache;
const stack = context_node;
context_node = sel_node;
try {
cache = body.call(last_context);
} finally {
context_node = stack;
}
return !Object.is(prev, cache);
};
const sel_node = [new Set(), new Set(), 0, recalc];
return [
function () {
read(sel_node);
last_context = this;
if (!sel_node[2]) {

@@ -99,3 +121,3 @@ const stack = context_node;

try {
cache = body.call(this);
cache = body.call(last_context);
} finally {

@@ -112,2 +134,3 @@ context_node = stack;

sel_node[2] = cache = 0;
last_context = null;
},

@@ -118,3 +141,5 @@ ];

const expr = (body, sync) => {
const expr_node = [sync || run, new Set()];
let last_context;
if (!sync) sync = () => run.call(last_context);
const expr_node = [sync, new Set()];
function run() {

@@ -127,3 +152,3 @@ let result;

try {
result = body.apply(this, arguments);
result = body.apply((last_context = this), arguments);
} finally {

@@ -134,5 +159,11 @@ context_node = stack;

}
return [run, () => free(expr_node, 1)];
return [
run,
() => {
free(expr_node, 1);
last_context = null;
},
];
};
module.exports = { box, sel, expr };
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