bobe 0.0.47 → 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.cjs.js +46 -14
- package/dist/bobe.cjs.js.map +1 -1
- package/dist/bobe.compiler.cjs.js +46 -14
- package/dist/bobe.compiler.cjs.js.map +1 -1
- package/dist/bobe.compiler.esm.js +44 -11
- package/dist/bobe.compiler.esm.js.map +1 -1
- package/dist/bobe.esm.js +44 -11
- package/dist/bobe.esm.js.map +1 -1
- package/dist/index.d.ts +13 -5
- package/dist/index.umd.js +46 -14
- package/dist/index.umd.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Queue } from 'bobe-shared';
|
|
2
|
-
import
|
|
3
|
-
|
|
2
|
+
import * as aoye from 'aoye';
|
|
3
|
+
import { Store, Effect, effect as effect$1, Scope, Signal, Computed, SignalNode, ValueDiff, CustomEffectOpt } from 'aoye';
|
|
4
|
+
export { Store } from 'aoye';
|
|
4
5
|
|
|
5
6
|
declare class Interpreter {
|
|
6
7
|
private tokenizer;
|
|
@@ -92,6 +93,8 @@ declare class Interpreter {
|
|
|
92
93
|
remove(node: any, parent?: any, prev?: any): void;
|
|
93
94
|
defaultRemove(node: any, parent: any, prevSibling: any): void;
|
|
94
95
|
setProp(node: any, key: string, value: any, hookI?: number): void | undefined | (() => void);
|
|
96
|
+
Effect: typeof Effect;
|
|
97
|
+
effect: typeof effect$1;
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
interface StackNode<T> {
|
|
@@ -179,7 +182,9 @@ type HookProps = {
|
|
|
179
182
|
/** 父节点 */
|
|
180
183
|
parentNode?: any;
|
|
181
184
|
};
|
|
182
|
-
type TerpConf = Partial<Pick<Interpreter, 'createNode' | 'setProp' | 'insertAfter' | 'remove' | 'createAnchor' | 'firstChild' | 'nextSib'
|
|
185
|
+
type TerpConf = Partial<Pick<Interpreter, 'createNode' | 'setProp' | 'insertAfter' | 'remove' | 'createAnchor' | 'firstChild' | 'nextSib'>> & {
|
|
186
|
+
noopEffect?: boolean;
|
|
187
|
+
};
|
|
183
188
|
type CustomRenderConf = Pick<TerpConf, 'createNode' | 'setProp' | 'insertAfter' | 'remove' | 'createAnchor' | 'firstChild' | 'nextSib'>;
|
|
184
189
|
type Hook = (props: HookProps) => any;
|
|
185
190
|
type HookType = 'dynamic' | 'static';
|
|
@@ -273,6 +278,7 @@ type FragmentNode$1 = LogicNode & {
|
|
|
273
278
|
type ComponentNode$1 = LogicNode & {
|
|
274
279
|
tokenizer: Tokenizer;
|
|
275
280
|
};
|
|
281
|
+
type Dep = Signal | Computed | (() => any) | string;
|
|
276
282
|
|
|
277
283
|
declare class Tokenizer {
|
|
278
284
|
private hook;
|
|
@@ -356,7 +362,7 @@ declare class Tokenizer {
|
|
|
356
362
|
private dent;
|
|
357
363
|
private shorterThanBaseDentEof;
|
|
358
364
|
private identifier;
|
|
359
|
-
|
|
365
|
+
getStr(head: string, parseEscape?: boolean): string;
|
|
360
366
|
private str;
|
|
361
367
|
private number;
|
|
362
368
|
private eof;
|
|
@@ -535,5 +541,7 @@ type IContext = {
|
|
|
535
541
|
};
|
|
536
542
|
declare const context: IContext;
|
|
537
543
|
|
|
538
|
-
|
|
544
|
+
declare const effect: (callback: (...args: ValueDiff[]) => void, depOrOpt?: Dep[] | Dep | CustomEffectOpt, opt?: CustomEffectOpt) => aoye.Effect;
|
|
545
|
+
|
|
546
|
+
export { Compiler, NodeType, ParseErrorCode, ParseSyntaxError, Tokenizer, bobe, context, customRender, effect };
|
|
539
547
|
export type { ASTNodeType, BaseNode, CommentNode, ComponentNode, ConditionalNode, DynamicValue, ElementNode, FragmentNode, IContext, InterpolationNode, LoopNode, ParseError, Program, Property, PropertyKeyNode, PropertyValue, SourceLocation, StaticValue, TemplateNode, TextNode };
|
package/dist/index.umd.js
CHANGED
|
@@ -82,6 +82,7 @@
|
|
|
82
82
|
this.loc = loc;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
+
const isDep = target => target && (target instanceof aoye.Signal || target instanceof aoye.Computed || typeof target === 'function' || typeof target === 'string');
|
|
85
86
|
|
|
86
87
|
class Tokenizer {
|
|
87
88
|
TabSize = 2;
|
|
@@ -1665,7 +1666,7 @@
|
|
|
1665
1666
|
_forNode$snapshot.isFirstToken;
|
|
1666
1667
|
const snapshotForUpdate = _objectWithoutProperties(_forNode$snapshot, _excluded);
|
|
1667
1668
|
let isFirstRender = true;
|
|
1668
|
-
forNode.effect = new
|
|
1669
|
+
forNode.effect = new this.Effect(() => {
|
|
1669
1670
|
let arr = arrSignal.get();
|
|
1670
1671
|
arr[aoye.Keys.Iterator];
|
|
1671
1672
|
const prevCtx = aoye.getPulling();
|
|
@@ -1836,7 +1837,7 @@
|
|
|
1836
1837
|
}
|
|
1837
1838
|
}
|
|
1838
1839
|
};
|
|
1839
|
-
});
|
|
1840
|
+
}, aoye.ScheduleType.Render);
|
|
1840
1841
|
return forNode.children[0] || forNode;
|
|
1841
1842
|
}
|
|
1842
1843
|
insertForItem(forNode, i, parentData, newChildren, before, snapshotForUpdate) {
|
|
@@ -1942,17 +1943,17 @@
|
|
|
1942
1943
|
return this.setProp(node, key, value, hookI);
|
|
1943
1944
|
}).get();
|
|
1944
1945
|
} else if (typeof value === 'function') {
|
|
1945
|
-
new
|
|
1946
|
+
new this.Effect(() => {
|
|
1946
1947
|
const res = value(data);
|
|
1947
1948
|
const dispose = this.setProp(node, key, res, hookI);
|
|
1948
1949
|
return dispose;
|
|
1949
|
-
});
|
|
1950
|
+
}, aoye.ScheduleType.Render);
|
|
1950
1951
|
} else if (valueIsMapKey) {
|
|
1951
|
-
new
|
|
1952
|
+
new this.Effect(() => {
|
|
1952
1953
|
const res = data[value];
|
|
1953
1954
|
const dispose = this.setProp(node, key, res, hookI);
|
|
1954
1955
|
return dispose;
|
|
1955
|
-
});
|
|
1956
|
+
}, aoye.ScheduleType.Render);
|
|
1956
1957
|
} else {
|
|
1957
1958
|
this.setProp(node, key, value, hookI);
|
|
1958
1959
|
}
|
|
@@ -2075,7 +2076,7 @@
|
|
|
2075
2076
|
}
|
|
2076
2077
|
ifNode.condition = signal;
|
|
2077
2078
|
ifNode.realAfter = this.insertAfterAnchor(`${keyWord.value}-after`);
|
|
2078
|
-
const ef =
|
|
2079
|
+
const ef = this.effect(({
|
|
2079
2080
|
val
|
|
2080
2081
|
}) => {
|
|
2081
2082
|
if (val) {
|
|
@@ -2096,7 +2097,9 @@
|
|
|
2096
2097
|
}
|
|
2097
2098
|
}
|
|
2098
2099
|
ifNode.isFirstRender = false;
|
|
2099
|
-
}, [signal]
|
|
2100
|
+
}, [signal], {
|
|
2101
|
+
type: 'render'
|
|
2102
|
+
});
|
|
2100
2103
|
ifNode.effect = ef;
|
|
2101
2104
|
return ifNode;
|
|
2102
2105
|
}
|
|
@@ -2182,6 +2185,10 @@
|
|
|
2182
2185
|
config(opt) {
|
|
2183
2186
|
Object.assign(this, opt);
|
|
2184
2187
|
this.opt = opt;
|
|
2188
|
+
if (opt.noopEffect) {
|
|
2189
|
+
this.effect = aoye.noopEffect;
|
|
2190
|
+
this.Effect = aoye.NoopEffect;
|
|
2191
|
+
}
|
|
2185
2192
|
}
|
|
2186
2193
|
createNode(name) {
|
|
2187
2194
|
return {
|
|
@@ -2231,6 +2238,8 @@
|
|
|
2231
2238
|
setProp(node, key, value, hookI) {
|
|
2232
2239
|
node.props[key] = value;
|
|
2233
2240
|
}
|
|
2241
|
+
Effect = aoye.Effect;
|
|
2242
|
+
effect = aoye.effect;
|
|
2234
2243
|
}
|
|
2235
2244
|
function createStoreOnePropParsed(child) {
|
|
2236
2245
|
const onePropParsed = (data, _, key, value, valueIsMapKey, isFn, hookI) => {
|
|
@@ -2301,6 +2310,34 @@
|
|
|
2301
2310
|
return context;
|
|
2302
2311
|
};
|
|
2303
2312
|
|
|
2313
|
+
const depTokenizer = new Tokenizer(() => '', false);
|
|
2314
|
+
const effect = (callback, depOrOpt, opt) => {
|
|
2315
|
+
const isArray = Array.isArray(depOrOpt);
|
|
2316
|
+
const isSingleDep = isDep(depOrOpt);
|
|
2317
|
+
const deps = isArray ? depOrOpt : isSingleDep ? [depOrOpt] : [];
|
|
2318
|
+
const option = isArray || isSingleDep ? opt : depOrOpt;
|
|
2319
|
+
const newDeps = [];
|
|
2320
|
+
for (let i = 0; i < deps.length; i++) {
|
|
2321
|
+
const dep = deps[i];
|
|
2322
|
+
if (typeof dep === 'string') {
|
|
2323
|
+
depTokenizer.code = dep.trim() + '\n';
|
|
2324
|
+
let exp;
|
|
2325
|
+
while (depTokenizer.i < depTokenizer.code.length) {
|
|
2326
|
+
exp = depTokenizer.jsExp().value;
|
|
2327
|
+
depTokenizer.nextToken();
|
|
2328
|
+
newDeps.push(new Function('data', `let v;with(data){v=${exp};}return v;`).bind(undefined, aoye.Store.Current));
|
|
2329
|
+
}
|
|
2330
|
+
} else {
|
|
2331
|
+
newDeps.push(dep);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
return aoye.effect(callback, newDeps, option);
|
|
2335
|
+
};
|
|
2336
|
+
|
|
2337
|
+
Object.defineProperty(exports, "Store", {
|
|
2338
|
+
enumerable: true,
|
|
2339
|
+
get: function () { return aoye.Store; }
|
|
2340
|
+
});
|
|
2304
2341
|
exports.Compiler = Compiler;
|
|
2305
2342
|
exports.NodeType = NodeType;
|
|
2306
2343
|
exports.ParseSyntaxError = ParseSyntaxError;
|
|
@@ -2308,12 +2345,7 @@
|
|
|
2308
2345
|
exports.bobe = bobe;
|
|
2309
2346
|
exports.context = context;
|
|
2310
2347
|
exports.customRender = customRender;
|
|
2311
|
-
|
|
2312
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
2313
|
-
enumerable: true,
|
|
2314
|
-
get: function () { return aoye[k]; }
|
|
2315
|
-
});
|
|
2316
|
-
});
|
|
2348
|
+
exports.effect = effect;
|
|
2317
2349
|
|
|
2318
2350
|
}));
|
|
2319
2351
|
//# sourceMappingURL=index.umd.js.map
|