summitjs 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/summit.js CHANGED
@@ -50,6 +50,7 @@ function track(dep) {
50
50
  }
51
51
  }
52
52
  function trigger(dep) {
53
+ if (dep.size === 0) return;
53
54
  const effects = [...dep];
54
55
  for (const eff of effects) {
55
56
  if (eff === activeEffect) continue;
@@ -83,8 +84,8 @@ function batch(fn) {
83
84
  }
84
85
  function flushBatch() {
85
86
  if (pendingEffects.size === 0) return;
86
- const effects = [...pendingEffects];
87
- pendingEffects.clear();
87
+ const effects = pendingEffects;
88
+ pendingEffects = /* @__PURE__ */ new Set();
88
89
  for (const eff of effects) {
89
90
  if (eff.active) runEffect(eff);
90
91
  }
@@ -246,8 +247,8 @@ function queueJob(job) {
246
247
  }
247
248
  }
248
249
  function flushJobs() {
249
- const jobs = [...queue];
250
- queue.clear();
250
+ const jobs = queue;
251
+ queue = /* @__PURE__ */ new Set();
251
252
  flushing = false;
252
253
  flushPromise = null;
253
254
  for (const job of jobs) job();
@@ -1361,6 +1362,10 @@ var GLOBAL_ALLOW = /* @__PURE__ */ new Set([
1361
1362
  "requestAnimationFrame",
1362
1363
  "cancelAnimationFrame",
1363
1364
  "fetch",
1365
+ "AbortController",
1366
+ "Headers",
1367
+ "Request",
1368
+ "Response",
1364
1369
  "alert",
1365
1370
  "confirm",
1366
1371
  "prompt",
@@ -1808,6 +1813,10 @@ function evaluateAction(source, root, thisVal) {
1808
1813
  const program = parse(source, "program");
1809
1814
  return new Interpreter(root).run(program, thisVal);
1810
1815
  }
1816
+ function compileExpression(source) {
1817
+ const program = parse(source, "expression");
1818
+ return (root, thisVal) => new Interpreter(root).run(program, thisVal);
1819
+ }
1811
1820
 
1812
1821
  // src/errors.ts
1813
1822
  var DOCS = "https://velofy.github.io/summit";
@@ -2885,11 +2894,13 @@ var sFor = (el, meta2, utils) => {
2885
2894
  el.remove();
2886
2895
  const parentScopes = utils.scopes;
2887
2896
  let blocks = /* @__PURE__ */ new Map();
2888
- const keyFor = (it, block) => {
2889
- if (!keyExpr) return it.objectKey ?? it.index;
2890
- const env = makeEnv(el, block).env;
2897
+ const keyEval = keyExpr ? compileExpression(keyExpr) : null;
2898
+ const keyFor = (it) => {
2899
+ if (!keyEval) return it.objectKey ?? it.index;
2900
+ const data = { [itemName]: it.value };
2901
+ if (indexName) data[indexName] = it.objectKey ?? it.index;
2891
2902
  try {
2892
- return evaluateExpression(keyExpr, env);
2903
+ return keyEval(makeEnv(el, data).env);
2893
2904
  } catch {
2894
2905
  return it.index;
2895
2906
  }
@@ -2911,8 +2922,7 @@ var sFor = (el, meta2, utils) => {
2911
2922
  const next = /* @__PURE__ */ new Map();
2912
2923
  const orderedKeys = [];
2913
2924
  for (const it of items) {
2914
- let scope = makeBlockScope(it);
2915
- const key = keyFor(it, scope);
2925
+ const key = keyFor(it);
2916
2926
  orderedKeys.push(key);
2917
2927
  const existing = blocks.get(key);
2918
2928
  if (existing) {
@@ -2921,6 +2931,7 @@ var sFor = (el, meta2, utils) => {
2921
2931
  next.set(key, existing);
2922
2932
  blocks.delete(key);
2923
2933
  } else {
2934
+ const scope = makeBlockScope(it);
2924
2935
  const node = blueprint.cloneNode(true);
2925
2936
  parent.insertBefore(node, anchor2);
2926
2937
  utils.initTree(node, [...parentScopes, scope]);
@@ -2931,9 +2942,13 @@ var sFor = (el, meta2, utils) => {
2931
2942
  utils.destroyTree(block.node);
2932
2943
  block.node.remove();
2933
2944
  }
2934
- for (const key of orderedKeys) {
2935
- const block = next.get(key);
2936
- parent.insertBefore(block.node, anchor2);
2945
+ let expected = anchor2;
2946
+ for (let i = orderedKeys.length - 1; i >= 0; i--) {
2947
+ const node = next.get(orderedKeys[i]).node;
2948
+ if (node.nextSibling !== expected) {
2949
+ parent.insertBefore(node, expected);
2950
+ }
2951
+ expected = node;
2937
2952
  }
2938
2953
  blocks = next;
2939
2954
  });