bobe 0.0.70 → 0.0.71

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.
@@ -1500,6 +1500,7 @@ class Interpreter {
1500
1500
  rootComponent = null;
1501
1501
  program(root, componentNode, before, ctxProvider) {
1502
1502
  this.rootComponent = componentNode;
1503
+ this.root = root;
1503
1504
  this.tokenizer.nextToken();
1504
1505
  const stack = new MultiTypeStack();
1505
1506
  setCtxStack(stack);
@@ -2703,9 +2704,6 @@ class Interpreter {
2703
2704
  };
2704
2705
  }
2705
2706
  insertAfter(parent, node, prev) {
2706
- return this.defaultInsert(parent, node, prev);
2707
- }
2708
- defaultInsert(parent, node, prev) {
2709
2707
  if (prev) {
2710
2708
  const next = prev.nextSibling;
2711
2709
  prev.nextSibling = node;
@@ -2716,10 +2714,7 @@ class Interpreter {
2716
2714
  node.nextSibling = next;
2717
2715
  }
2718
2716
  }
2719
- remove(node, parent, prev) {
2720
- return this.defaultRemove(node, parent, prev);
2721
- }
2722
- defaultRemove(node, parent, prevSibling) {
2717
+ remove(node, parent, prevSibling) {
2723
2718
  const next = node.nextSibling;
2724
2719
  if (prevSibling) {
2725
2720
  prevSibling.nextSibling = next;
@@ -2774,11 +2769,13 @@ function bobe(fragments, ...values) {
2774
2769
  return ui;
2775
2770
  }
2776
2771
  function customRender(option) {
2777
- return function render(Ctor, root) {
2772
+ const mw = new Mw();
2773
+ function render(Ctor, root) {
2778
2774
  const store = Ctor.new();
2779
2775
  const tokenizer = store.ui(false);
2780
2776
  const terp = new Interpreter(tokenizer);
2781
2777
  terp.config(option);
2778
+ mw.wrapHooks(terp);
2782
2779
  const componentNode = {
2783
2780
  __logicType: FakeType.Component,
2784
2781
  realParent: root,
@@ -2786,10 +2783,64 @@ function customRender(option) {
2786
2783
  tokenizer
2787
2784
  };
2788
2785
  terp.program(root, componentNode);
2789
- option.onBeforeFlush?.();
2786
+ const onBeforeFlush = mw.wrapHook(terp, 'onBeforeFlush', option.onBeforeFlush);
2787
+ onBeforeFlush?.();
2790
2788
  aoye.flushMicroEffectManual();
2791
2789
  return [componentNode, store];
2792
- };
2790
+ }
2791
+ render.use = mw.use.bind(mw);
2792
+ return render;
2793
+ }
2794
+ class MwCtx {
2795
+ ctx = {};
2796
+ constructor(terp, handlers = [], base) {
2797
+ this.terp = terp;
2798
+ this.handlers = [...handlers, base];
2799
+ }
2800
+ i = 0;
2801
+ get next() {
2802
+ if (this.i < this.handlers.length) {
2803
+ const handler = this.handlers[this.i];
2804
+ this.i++;
2805
+ return handler;
2806
+ }
2807
+ return null;
2808
+ }
2809
+ get hasNext() {
2810
+ return this.i < this.handlers.length && this.handlers[this.i];
2811
+ }
2812
+ }
2813
+ class Mw extends Map {
2814
+ use(mw) {
2815
+ for (const key in mw) {
2816
+ const list = this.get(key);
2817
+ if (list) {
2818
+ list.push(mw[key]);
2819
+ } else {
2820
+ this.set(key, [mw[key]]);
2821
+ }
2822
+ }
2823
+ }
2824
+ wrapHooks(terp) {
2825
+ this.forEach((list, key) => {
2826
+ let base = terp[key];
2827
+ base = base?.bind(terp);
2828
+ function wrapped(...args) {
2829
+ const ctx = new MwCtx(terp, list, base);
2830
+ return ctx.next.apply(ctx, args);
2831
+ }
2832
+ terp[key] = wrapped;
2833
+ });
2834
+ }
2835
+ wrapHook(terp, key, base) {
2836
+ const list = this.get(key);
2837
+ if (!list) return base?.bind(terp);
2838
+ function wrapped(...args) {
2839
+ const ctx = new MwCtx(terp, list, base?.bind(terp));
2840
+ return ctx.next.apply(ctx, args);
2841
+ }
2842
+ return wrapped;
2843
+ }
2793
2844
  }
2794
2845
 
2795
2846
  const context = name => {
@@ -2840,6 +2891,8 @@ Object.defineProperty(exports, "Store", {
2840
2891
  });
2841
2892
  exports.Compiler = Compiler;
2842
2893
  exports.FakeType = FakeType;
2894
+ exports.Mw = Mw;
2895
+ exports.MwCtx = MwCtx;
2843
2896
  exports.NodeType = NodeType;
2844
2897
  exports.ParseSyntaxError = ParseSyntaxError;
2845
2898
  exports.Tokenizer = Tokenizer;