bobe 0.0.46 → 0.0.48

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/bobe.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Queue, isNum, matchIdStart2, matchId, escapeMap, jsVarRegexp, date32 } from 'bobe-shared';
2
- import { getPulling, setPulling, Keys, deepSignal, Computed, Effect, toRaw, runWithPulling, Scope, Store, effect, shareSignal } from 'aoye';
3
- export * from 'aoye';
2
+ import { Signal, Computed, getPulling, setPulling, Keys, deepSignal, toRaw, ScheduleType, runWithPulling, Scope, Store, noopEffect, NoopEffect, Effect, effect as effect$1, shareSignal } from 'aoye';
3
+ export { Store } from 'aoye';
4
4
 
5
5
  let TokenType = function (TokenType) {
6
6
  TokenType[TokenType["NewLine"] = 1] = "NewLine";
@@ -80,6 +80,7 @@ class ParseSyntaxError extends SyntaxError {
80
80
  this.loc = loc;
81
81
  }
82
82
  }
83
+ const isDep = target => target && (target instanceof Signal || target instanceof Computed || typeof target === 'function' || typeof target === 'string');
83
84
 
84
85
  class Tokenizer {
85
86
  TabSize = 2;
@@ -1663,7 +1664,7 @@ class Interpreter {
1663
1664
  _forNode$snapshot.isFirstToken;
1664
1665
  const snapshotForUpdate = _objectWithoutProperties(_forNode$snapshot, _excluded);
1665
1666
  let isFirstRender = true;
1666
- forNode.effect = new Effect(() => {
1667
+ forNode.effect = new this.Effect(() => {
1667
1668
  let arr = arrSignal.get();
1668
1669
  arr[Keys.Iterator];
1669
1670
  const prevCtx = getPulling();
@@ -1834,7 +1835,7 @@ class Interpreter {
1834
1835
  }
1835
1836
  }
1836
1837
  };
1837
- });
1838
+ }, ScheduleType.Render);
1838
1839
  return forNode.children[0] || forNode;
1839
1840
  }
1840
1841
  insertForItem(forNode, i, parentData, newChildren, before, snapshotForUpdate) {
@@ -1940,17 +1941,17 @@ class Interpreter {
1940
1941
  return this.setProp(node, key, value, hookI);
1941
1942
  }).get();
1942
1943
  } else if (typeof value === 'function') {
1943
- new Effect(() => {
1944
+ new this.Effect(() => {
1944
1945
  const res = value(data);
1945
1946
  const dispose = this.setProp(node, key, res, hookI);
1946
1947
  return dispose;
1947
- });
1948
+ }, ScheduleType.Render);
1948
1949
  } else if (valueIsMapKey) {
1949
- new Effect(() => {
1950
+ new this.Effect(() => {
1950
1951
  const res = data[value];
1951
1952
  const dispose = this.setProp(node, key, res, hookI);
1952
1953
  return dispose;
1953
- });
1954
+ }, ScheduleType.Render);
1954
1955
  } else {
1955
1956
  this.setProp(node, key, value, hookI);
1956
1957
  }
@@ -2073,7 +2074,7 @@ class Interpreter {
2073
2074
  }
2074
2075
  ifNode.condition = signal;
2075
2076
  ifNode.realAfter = this.insertAfterAnchor(`${keyWord.value}-after`);
2076
- const ef = effect(({
2077
+ const ef = this.effect(({
2077
2078
  val
2078
2079
  }) => {
2079
2080
  if (val) {
@@ -2094,7 +2095,9 @@ class Interpreter {
2094
2095
  }
2095
2096
  }
2096
2097
  ifNode.isFirstRender = false;
2097
- }, [signal]);
2098
+ }, [signal], {
2099
+ type: 'render'
2100
+ });
2098
2101
  ifNode.effect = ef;
2099
2102
  return ifNode;
2100
2103
  }
@@ -2180,6 +2183,10 @@ class Interpreter {
2180
2183
  config(opt) {
2181
2184
  Object.assign(this, opt);
2182
2185
  this.opt = opt;
2186
+ if (opt.noopEffect) {
2187
+ this.effect = noopEffect;
2188
+ this.Effect = NoopEffect;
2189
+ }
2183
2190
  }
2184
2191
  createNode(name) {
2185
2192
  return {
@@ -2229,6 +2236,8 @@ class Interpreter {
2229
2236
  setProp(node, key, value, hookI) {
2230
2237
  node.props[key] = value;
2231
2238
  }
2239
+ Effect = Effect;
2240
+ effect = effect$1;
2232
2241
  }
2233
2242
  function createStoreOnePropParsed(child) {
2234
2243
  const onePropParsed = (data, _, key, value, valueIsMapKey, isFn, hookI) => {
@@ -2299,5 +2308,29 @@ const context = name => {
2299
2308
  return context;
2300
2309
  };
2301
2310
 
2302
- export { Compiler, NodeType, ParseSyntaxError, Tokenizer, bobe, context, customRender };
2311
+ const depTokenizer = new Tokenizer(() => '', false);
2312
+ const effect = (callback, depOrOpt, opt) => {
2313
+ const isArray = Array.isArray(depOrOpt);
2314
+ const isSingleDep = isDep(depOrOpt);
2315
+ const deps = isArray ? depOrOpt : isSingleDep ? [depOrOpt] : [];
2316
+ const option = isArray || isSingleDep ? opt : depOrOpt;
2317
+ const newDeps = [];
2318
+ for (let i = 0; i < deps.length; i++) {
2319
+ const dep = deps[i];
2320
+ if (typeof dep === 'string') {
2321
+ depTokenizer.code = dep.trim() + '\n';
2322
+ let exp;
2323
+ while (depTokenizer.i < depTokenizer.code.length) {
2324
+ exp = depTokenizer.jsExp().value;
2325
+ depTokenizer.nextToken();
2326
+ newDeps.push(new Function('data', `let v;with(data){v=${exp};}return v;`).bind(undefined, Store.Current));
2327
+ }
2328
+ } else {
2329
+ newDeps.push(dep);
2330
+ }
2331
+ }
2332
+ return effect$1(callback, newDeps, option);
2333
+ };
2334
+
2335
+ export { Compiler, NodeType, ParseSyntaxError, Tokenizer, bobe, context, customRender, effect };
2303
2336
  //# sourceMappingURL=bobe.esm.js.map