@lark.js/mvc 0.0.12 → 0.0.14

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/index.js CHANGED
@@ -366,61 +366,6 @@ function unmark(host) {
366
366
  }
367
367
  }
368
368
 
369
- // src/safeguard.ts
370
- var proxiesPool = /* @__PURE__ */ new Map();
371
- var SAFEGUARD_SENTINEL = "_safe_";
372
- function safeguard(data, getter, setter, isRoot) {
373
- if (typeof window.__lark_Debug === "undefined" || !window.__lark_Debug) {
374
- return data;
375
- }
376
- if (typeof Proxy === "undefined") {
377
- return data;
378
- }
379
- if (isPrimitive(data)) {
380
- return data;
381
- }
382
- const build = (prefix, obj) => {
383
- const cacheKey = (getter || "") + "" + (setter || "");
384
- const cached = proxiesPool.get(obj);
385
- if (cached && cached.cacheKey === cacheKey) {
386
- return cached.entity;
387
- }
388
- if (Reflect.get(obj, SAFEGUARD_SENTINEL)) {
389
- return obj;
390
- }
391
- const entity = new Proxy(obj, {
392
- set(target, property, value) {
393
- if (!setter && !prefix) {
394
- throw new Error(
395
- "Avoid write back, key: " + prefix + property + " value:" + value + " more: https://github.com/hangtiancheng/lark"
396
- );
397
- }
398
- Reflect.set(target, property, value);
399
- if (setter) {
400
- setter(prefix + property, value);
401
- }
402
- return true;
403
- },
404
- get(target, property) {
405
- if (property === SAFEGUARD_SENTINEL) {
406
- return true;
407
- }
408
- const out = Reflect.get(target, property);
409
- if (!prefix && getter) {
410
- getter(property);
411
- }
412
- if (!isRoot && hasOwnProperty(target, property) && (Array.isArray(out) || isPlainObject(out))) {
413
- return build(prefix + property + ".", out);
414
- }
415
- return out;
416
- }
417
- });
418
- proxiesPool.set(obj, { cacheKey, entity });
419
- return entity;
420
- };
421
- return build("", data);
422
- }
423
-
424
369
  // src/cache.ts
425
370
  function sortCacheEntries(a, b) {
426
371
  return b.frequency - a.frequency || b.lastTimestamp - a.lastTimestamp;
@@ -696,7 +641,6 @@ var keyRefCounts = {};
696
641
  var changedKeys = /* @__PURE__ */ new Set();
697
642
  var stashedChangedKeys = EMPTY_STRING_SET;
698
643
  var dataIsChanged = false;
699
- var dataWhereSet = {};
700
644
  var emitter = new EventEmitter();
701
645
  var booted = false;
702
646
  function markBooted() {
@@ -720,47 +664,16 @@ function teardownKeysRef(keyList) {
720
664
  if (count <= 0) {
721
665
  Reflect.deleteProperty(keyRefCounts, key);
722
666
  Reflect.deleteProperty(appData, key);
723
- if (typeof window.__lark_Debug !== "undefined" && window.__lark_Debug) {
724
- Reflect.deleteProperty(dataWhereSet, key);
725
- }
726
667
  }
727
668
  }
728
669
  }
729
670
  }
730
- var warnedKeys = /* @__PURE__ */ new Set();
731
- function clearNotify(key) {
732
- warnedKeys.delete(key);
733
- }
734
- function delayNotify(key, message) {
735
- if (warnedKeys.has(key)) return;
736
- warnedKeys.add(key);
737
- console.warn(message);
738
- }
739
671
  var State = {
740
672
  /**
741
673
  * Get data from state.
742
674
  */
743
675
  get(key) {
744
676
  const result = key ? appData[key] : appData;
745
- if (typeof window.__lark_Debug !== "undefined" && window.__lark_Debug) {
746
- return safeguard(
747
- result,
748
- (dataKey) => {
749
- if (booted && hasOwnProperty(dataWhereSet, dataKey) && dataWhereSet[dataKey] !== window.location.pathname) {
750
- console.warn(
751
- `beware! You get state:"{State}.${dataKey}" where it set by page:${dataWhereSet[dataKey]}`
752
- );
753
- }
754
- },
755
- (path, _value) => {
756
- const sub = key || path;
757
- delayNotify(
758
- sub,
759
- `beware! You direct modify "{State}.${sub}" You should call State.set() and State.digest() to notify other views`
760
- );
761
- }
762
- );
763
- }
764
677
  return result;
765
678
  },
766
679
  /**
@@ -768,11 +681,6 @@ var State = {
768
681
  */
769
682
  set(data, excludes) {
770
683
  dataIsChanged = setData(data, appData, changedKeys, excludes || EMPTY_STRING_SET) || dataIsChanged;
771
- if (typeof window.__lark_Debug !== "undefined" && window.__lark_Debug && booted) {
772
- for (const p in data) {
773
- dataWhereSet[p] = window.location.pathname;
774
- }
775
- }
776
684
  return State;
777
685
  },
778
686
  /**
@@ -783,11 +691,6 @@ var State = {
783
691
  State.set(data, excludes);
784
692
  }
785
693
  if (dataIsChanged) {
786
- if (typeof window.__lark_Debug !== "undefined" && window.__lark_Debug) {
787
- for (const p of changedKeys) {
788
- clearNotify(p);
789
- }
790
- }
791
694
  dataIsChanged = false;
792
695
  const keys2 = changedKeys;
793
696
  stashedChangedKeys = keys2;
@@ -1029,9 +932,6 @@ var Router = {
1029
932
  attachViewAndPath(location);
1030
933
  hrefCache.set(href, location);
1031
934
  }
1032
- if (typeof window.__lark_Debug !== "undefined" && window.__lark_Debug) {
1033
- location["params"] = safeguard(location["params"]);
1034
- }
1035
935
  return location;
1036
936
  },
1037
937
  /**
@@ -1050,9 +950,6 @@ var Router = {
1050
950
  emitter2.fire(RouterEvents.CHANGED, asRecord(lastChanged));
1051
951
  }
1052
952
  silent = 0;
1053
- if (typeof window.__lark_Debug !== "undefined" && window.__lark_Debug && lastChanged) {
1054
- lastChanged = safeguard(lastChanged);
1055
- }
1056
953
  return lastChanged;
1057
954
  },
1058
955
  /**
@@ -1499,6 +1396,21 @@ function use(names, callback) {
1499
1396
  return loadPromise;
1500
1397
  }
1501
1398
 
1399
+ // src/frame-registry.ts
1400
+ var frameRegistry = /* @__PURE__ */ new Map();
1401
+ function getFrame(id) {
1402
+ return frameRegistry.get(id);
1403
+ }
1404
+ function getAllFrames() {
1405
+ return frameRegistry;
1406
+ }
1407
+ function registerFrame(id, frame) {
1408
+ frameRegistry.set(id, frame);
1409
+ }
1410
+ function removeFrame(id) {
1411
+ frameRegistry.delete(id);
1412
+ }
1413
+
1502
1414
  // src/dom.ts
1503
1415
  var wrapMeta = {
1504
1416
  option: [1, "<select multiple>"],
@@ -1809,6 +1721,13 @@ function vdomCreate(tag, props, children, specials) {
1809
1721
  reused[c.compareKey] = (reused[c.compareKey] || 0) + 1;
1810
1722
  reusedTotal++;
1811
1723
  }
1724
+ if (c.reused) {
1725
+ if (!reused) reused = {};
1726
+ for (const key in c.reused) {
1727
+ reused[key] = (reused[key] || 0) + c.reused[key];
1728
+ reusedTotal += c.reused[key];
1729
+ }
1730
+ }
1812
1731
  if (c.views) {
1813
1732
  if (!viewList) viewList = [];
1814
1733
  viewList.push(...c.views);
@@ -2260,9 +2179,6 @@ var Updater = class {
2260
2179
  if (key) {
2261
2180
  result = this.data[key];
2262
2181
  }
2263
- if (typeof window !== "undefined" && window.__lark_Debug) {
2264
- return safeguard(result);
2265
- }
2266
2182
  return result;
2267
2183
  }
2268
2184
  /**
@@ -2316,7 +2232,7 @@ var Updater = class {
2316
2232
  const changed = this.hasChangedFlag;
2317
2233
  this.hasChangedFlag = 0;
2318
2234
  this.changedKeys = /* @__PURE__ */ new Set();
2319
- const frame = Frame.get(this.viewId);
2235
+ const frame = getFrame(this.viewId);
2320
2236
  const view = frame?.view;
2321
2237
  const node = getById(this.viewId);
2322
2238
  if (changed && view && node && view.signature > 0 && frame) {
@@ -2473,7 +2389,7 @@ function getViewClassRegistry() {
2473
2389
 
2474
2390
  // src/hmr.ts
2475
2391
  function reloadViews(viewPath) {
2476
- const allFrames = Frame.getAll();
2392
+ const allFrames = getAllFrames();
2477
2393
  const toReload = [];
2478
2394
  for (const [, frame] of allFrames) {
2479
2395
  if (frame.viewPath) {
@@ -2494,9 +2410,13 @@ function acceptView(hot, viewPath) {
2494
2410
  const NewViewClass = candidate;
2495
2411
  registerViewClass(viewPath, NewViewClass);
2496
2412
  reloadViews(viewPath);
2497
- } else {
2498
- hot.invalidate();
2413
+ return;
2499
2414
  }
2415
+ if (getViewClass(viewPath)) {
2416
+ reloadViews(viewPath);
2417
+ return;
2418
+ }
2419
+ hot.invalidate();
2500
2420
  });
2501
2421
  }
2502
2422
  function disposeView(hot, viewPath) {
@@ -3141,7 +3061,6 @@ function defineView(props, statics) {
3141
3061
  }
3142
3062
 
3143
3063
  // src/frame.ts
3144
- var frameRegistry = /* @__PURE__ */ new Map();
3145
3064
  var rootFrame;
3146
3065
  var globalAlter;
3147
3066
  var MAX_FRAME_POOL = 64;
@@ -3193,7 +3112,7 @@ var Frame = class _Frame extends EventEmitter {
3193
3112
  if (parentId) {
3194
3113
  this._parentId = parentId;
3195
3114
  }
3196
- frameRegistry.set(id, this);
3115
+ registerFrame(id, this);
3197
3116
  const element = document.getElementById(id);
3198
3117
  if (element) {
3199
3118
  element.frame = this;
@@ -3324,7 +3243,7 @@ var Frame = class _Frame extends EventEmitter {
3324
3243
  */
3325
3244
  mountFrame(frameId, viewPath, viewInitParams) {
3326
3245
  notifyAlter(this, { id: frameId });
3327
- let childFrame = frameRegistry.get(frameId);
3246
+ let childFrame = getFrame(frameId);
3328
3247
  if (!childFrame) {
3329
3248
  if (!this.childrenMap[frameId]) {
3330
3249
  this.childrenCount++;
@@ -3345,17 +3264,17 @@ var Frame = class _Frame extends EventEmitter {
3345
3264
  */
3346
3265
  unmountFrame(id) {
3347
3266
  const targetId = id ? this.childrenMap[id] : this.id;
3348
- const frame = frameRegistry.get(targetId);
3267
+ const frame = getFrame(targetId);
3349
3268
  if (!frame) return;
3350
3269
  const wasCreated = frame.readyCount > 0;
3351
3270
  const pId = frame.parentId;
3352
3271
  frame.unmountView();
3353
- removeFrame(targetId, wasCreated);
3272
+ removeFrame2(targetId, wasCreated);
3354
3273
  reInitFrameForCache(frame);
3355
3274
  if (frameCache.length < MAX_FRAME_POOL) {
3356
3275
  frameCache.push(frame);
3357
3276
  }
3358
- const parent = frameRegistry.get(pId || "");
3277
+ const parent = getFrame(pId || "");
3359
3278
  if (parent && parent.childrenMap[targetId]) {
3360
3279
  Reflect.deleteProperty(parent.childrenMap, targetId);
3361
3280
  parent.childrenCount--;
@@ -3420,7 +3339,7 @@ var Frame = class _Frame extends EventEmitter {
3420
3339
  let currentPid = this.parentId;
3421
3340
  let n = level >>> 0 || 1;
3422
3341
  while (currentPid && n--) {
3423
- frame = frameRegistry.get(currentPid);
3342
+ frame = getFrame(currentPid);
3424
3343
  currentPid = frame?.parentId;
3425
3344
  }
3426
3345
  return frame;
@@ -3481,11 +3400,11 @@ var Frame = class _Frame extends EventEmitter {
3481
3400
  // ============================================================
3482
3401
  /** Get frame by ID */
3483
3402
  static get(id) {
3484
- return frameRegistry.get(id);
3403
+ return getFrame(id);
3485
3404
  }
3486
3405
  /** Get all frames */
3487
3406
  static getAll() {
3488
- return frameRegistry;
3407
+ return getAllFrames();
3489
3408
  }
3490
3409
  /**
3491
3410
  * Returns the existing root frame, or `undefined` if none has been created.
@@ -3535,10 +3454,10 @@ var Frame = class _Frame extends EventEmitter {
3535
3454
  function htmlElIsBound(element) {
3536
3455
  return !!element.frameBound;
3537
3456
  }
3538
- function removeFrame(id, wasCreated) {
3539
- const frameInstance = frameRegistry.get(id);
3457
+ function removeFrame2(id, wasCreated) {
3458
+ const frameInstance = getFrame(id);
3540
3459
  if (!frameInstance) return;
3541
- frameRegistry.delete(id);
3460
+ removeFrame(id);
3542
3461
  Frame.fire("remove", { frame: frameInstance, fcc: wasCreated });
3543
3462
  const element = document.getElementById(id);
3544
3463
  if (element) {
@@ -3555,7 +3474,7 @@ function notifyCreated(frameInstance) {
3555
3474
  }
3556
3475
  const pId = frameInstance.parentId;
3557
3476
  if (pId) {
3558
- const parent = frameRegistry.get(pId);
3477
+ const parent = getFrame(pId);
3559
3478
  if (parent && !parent.readyMap.has(frameInstance.id)) {
3560
3479
  parent.readyMap.add(frameInstance.id);
3561
3480
  parent.readyCount++;
@@ -3571,7 +3490,7 @@ function notifyAlter(frameInstance, data) {
3571
3490
  frameInstance.fire("alter", data);
3572
3491
  const pId = frameInstance.parentId;
3573
3492
  if (pId) {
3574
- const parent = frameRegistry.get(pId);
3493
+ const parent = getFrame(pId);
3575
3494
  if (parent && parent.readyMap.has(frameInstance.id)) {
3576
3495
  parent.readyCount--;
3577
3496
  parent.readyMap.delete(frameInstance.id);
@@ -3589,7 +3508,7 @@ function reInitFrame(frame, id, parentId) {
3589
3508
  frame["signature"] = 1;
3590
3509
  frame["readyMap"] = /* @__PURE__ */ new Set();
3591
3510
  frame["invokeList"] = [];
3592
- frameRegistry.set(id, frame);
3511
+ registerFrame(id, frame);
3593
3512
  }
3594
3513
  function reInitFrameForCache(frame) {
3595
3514
  Reflect.set(frame, "id", "");
@@ -3598,7 +3517,7 @@ function reInitFrameForCache(frame) {
3598
3517
  frame["readyMap"] = /* @__PURE__ */ new Set();
3599
3518
  }
3600
3519
  function translateQuery(pId, src, params) {
3601
- const parentFrame = frameRegistry.get(pId);
3520
+ const parentFrame = getFrame(pId);
3602
3521
  const parentView = parentFrame?.view;
3603
3522
  if (!parentView) return;
3604
3523
  const parentRefData = parentView.updater.refData;
@@ -4489,19 +4408,6 @@ var Framework = {
4489
4408
  }
4490
4409
  return config;
4491
4410
  },
4492
- /**
4493
- * @deprecated Use `getConfig()` / `setConfig()`. Behavior unchanged.
4494
- */
4495
- config(cfg) {
4496
- if (!cfg) {
4497
- return config;
4498
- }
4499
- if (typeof cfg === "string") {
4500
- return config[cfg];
4501
- }
4502
- assign(config, cfg);
4503
- return config;
4504
- },
4505
4411
  /**
4506
4412
  * Boot the framework.
4507
4413
  */
@@ -4597,10 +4503,6 @@ var Framework = {
4597
4503
  * Generate globally unique ID.
4598
4504
  */
4599
4505
  guid: generateId,
4600
- /**
4601
- * Proxy-based debug guard.
4602
- */
4603
- guard: safeguard,
4604
4506
  /**
4605
4507
  * Cache class.
4606
4508
  */
@@ -4822,7 +4724,6 @@ export {
4822
4724
  registerViewClass,
4823
4725
  reloadViews,
4824
4726
  resetProjectsMap,
4825
- safeguard,
4826
4727
  unmark,
4827
4728
  use,
4828
4729
  useUrlState,