@viewfly/core 1.0.0-alpha.1 → 1.0.0-alpha.11
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/bundles/index.d.ts +590 -0
- package/bundles/index.esm.js +134 -141
- package/bundles/index.js +134 -141
- package/package.json +9 -6
- package/rollup-d.config.ts +14 -0
- package/bundles/_utils/make-error.d.ts +0 -1
- package/bundles/di/_api.d.ts +0 -10
- package/bundles/di/forward-ref.d.ts +0 -10
- package/bundles/di/injectable.d.ts +0 -20
- package/bundles/di/injection-token.d.ts +0 -8
- package/bundles/di/injector.d.ts +0 -26
- package/bundles/di/metadata.d.ts +0 -43
- package/bundles/di/null-injector.d.ts +0 -6
- package/bundles/di/provider.d.ts +0 -30
- package/bundles/di/reflective-injector.d.ts +0 -31
- package/bundles/di/reflective-provider.d.ts +0 -20
- package/bundles/di/type.d.ts +0 -7
- package/bundles/di/utils/_api.d.ts +0 -3
- package/bundles/di/utils/annotations.d.ts +0 -33
- package/bundles/di/utils/decorators.d.ts +0 -17
- package/bundles/di/utils/stringify.d.ts +0 -1
- package/bundles/foundation/_api.d.ts +0 -8
- package/bundles/foundation/_utils.d.ts +0 -52
- package/bundles/foundation/component.d.ts +0 -245
- package/bundles/foundation/injection-tokens.d.ts +0 -18
- package/bundles/foundation/jsx-element.d.ts +0 -19
- package/bundles/foundation/memo.d.ts +0 -2
- package/bundles/foundation/renderer.d.ts +0 -3
- package/bundles/foundation/root.component.d.ts +0 -10
- package/bundles/foundation/types.d.ts +0 -43
- package/bundles/public-api.d.ts +0 -5
- package/bundles/viewfly.d.ts +0 -29
package/bundles/index.esm.js
CHANGED
|
@@ -161,6 +161,40 @@ var InjectFlags;
|
|
|
161
161
|
class Injector {
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/**
|
|
165
|
+
* 构造函数参数装饰器,用于改变注入 token
|
|
166
|
+
*/
|
|
167
|
+
const Inject = function InjectDecorator(token) {
|
|
168
|
+
if (this instanceof Inject) {
|
|
169
|
+
this.token = token;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
return makeParamDecorator(Inject, new Inject(token));
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
const Self = function SelfDecorator() {
|
|
176
|
+
if (!(this instanceof Self)) {
|
|
177
|
+
return makeParamDecorator(Self, new Self());
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
const SkipSelf = function SkipSelfDecorator() {
|
|
181
|
+
if (!(this instanceof SkipSelf)) {
|
|
182
|
+
return makeParamDecorator(SkipSelf, new SkipSelf());
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const Optional = function OptionalDecorator() {
|
|
186
|
+
if (!(this instanceof Optional)) {
|
|
187
|
+
return makeParamDecorator(Optional, new Optional());
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const Prop = function PropDecorator(token, notFoundValue, flags) {
|
|
191
|
+
if (!(this instanceof Prop)) {
|
|
192
|
+
return makePropertyDecorator(Prop, token, function (instance, propertyName, token, injector) {
|
|
193
|
+
instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, notFoundValue, flags);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
164
198
|
function stringify(token) {
|
|
165
199
|
if (typeof token === 'string') {
|
|
166
200
|
return token;
|
|
@@ -205,7 +239,8 @@ class NullInjector extends Injector {
|
|
|
205
239
|
super(...arguments);
|
|
206
240
|
this.parentInjector = null;
|
|
207
241
|
}
|
|
208
|
-
|
|
242
|
+
/* eslint-disable-next-line */
|
|
243
|
+
get(token, notFoundValue = THROW_IF_NOT_FOUND, _) {
|
|
209
244
|
if (notFoundValue === THROW_IF_NOT_FOUND) {
|
|
210
245
|
throw nullInjectorErrorFn(token);
|
|
211
246
|
}
|
|
@@ -213,40 +248,6 @@ class NullInjector extends Injector {
|
|
|
213
248
|
}
|
|
214
249
|
}
|
|
215
250
|
|
|
216
|
-
/**
|
|
217
|
-
* 构造函数参数装饰器,用于改变注入 token
|
|
218
|
-
*/
|
|
219
|
-
const Inject = function InjectDecorator(token) {
|
|
220
|
-
if (this instanceof Inject) {
|
|
221
|
-
this.token = token;
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
return makeParamDecorator(Inject, new Inject(token));
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
const Self = function SelfDecorator() {
|
|
228
|
-
if (!(this instanceof Self)) {
|
|
229
|
-
return makeParamDecorator(Self, new Self());
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
const SkipSelf = function SkipSelfDecorator() {
|
|
233
|
-
if (!(this instanceof SkipSelf)) {
|
|
234
|
-
return makeParamDecorator(SkipSelf, new SkipSelf());
|
|
235
|
-
}
|
|
236
|
-
};
|
|
237
|
-
const Optional = function OptionalDecorator() {
|
|
238
|
-
if (!(this instanceof Optional)) {
|
|
239
|
-
return makeParamDecorator(Optional, new Optional());
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
const Prop = function PropDecorator(token, flags, notFoundValue = THROW_IF_NOT_FOUND) {
|
|
243
|
-
if (!(this instanceof Prop)) {
|
|
244
|
-
return makePropertyDecorator(Prop, token, function (instance, propertyName, token, injector) {
|
|
245
|
-
instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, flags, notFoundValue);
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
|
|
250
251
|
/**
|
|
251
252
|
* 标准化 provide,并返回统一数据结构
|
|
252
253
|
* @param provider
|
|
@@ -424,15 +425,15 @@ class ReflectiveInjector extends Injector {
|
|
|
424
425
|
/**
|
|
425
426
|
* 用于获取当前注入器上下文内的实例、对象或数据
|
|
426
427
|
* @param token 访问 token
|
|
427
|
-
* @param flags 查询规则
|
|
428
428
|
* @param notFoundValue 如未查找到的返回值
|
|
429
|
+
* @param flags 查询规则
|
|
429
430
|
*/
|
|
430
|
-
get(token,
|
|
431
|
+
get(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
|
|
431
432
|
var _a;
|
|
432
433
|
flags = flags || InjectFlags.Default;
|
|
433
434
|
if (flags === InjectFlags.SkipSelf) {
|
|
434
435
|
if (this.parentInjector) {
|
|
435
|
-
return this.parentInjector.get(token,
|
|
436
|
+
return this.parentInjector.get(token, notFoundValue);
|
|
436
437
|
}
|
|
437
438
|
if (notFoundValue !== THROW_IF_NOT_FOUND) {
|
|
438
439
|
return notFoundValue;
|
|
@@ -476,9 +477,12 @@ class ReflectiveInjector extends Injector {
|
|
|
476
477
|
return notFoundValue;
|
|
477
478
|
}
|
|
478
479
|
if (this.parentInjector) {
|
|
479
|
-
return this.parentInjector.get(token, flags === InjectFlags.Optional ? InjectFlags.Optional : InjectFlags.Default
|
|
480
|
+
return this.parentInjector.get(token, notFoundValue, flags === InjectFlags.Optional ? InjectFlags.Optional : InjectFlags.Default);
|
|
480
481
|
}
|
|
481
482
|
if (notFoundValue === THROW_IF_NOT_FOUND) {
|
|
483
|
+
// if (flags === InjectFlags.Optional) {
|
|
484
|
+
// return null as U
|
|
485
|
+
// }
|
|
482
486
|
throw reflectiveInjectorErrorFn(token);
|
|
483
487
|
}
|
|
484
488
|
return notFoundValue;
|
|
@@ -508,11 +512,11 @@ class ReflectiveInjector extends Injector {
|
|
|
508
512
|
const tryValue = {};
|
|
509
513
|
const injectToken = dep.injectKey instanceof ForwardRef ? dep.injectKey.getRef() : dep.injectKey;
|
|
510
514
|
if (dep.visibility instanceof Self) {
|
|
511
|
-
reflectiveValue = this.get(injectToken, InjectFlags.Self
|
|
515
|
+
reflectiveValue = this.get(injectToken, tryValue, InjectFlags.Self);
|
|
512
516
|
}
|
|
513
517
|
else if (dep.visibility instanceof SkipSelf) {
|
|
514
518
|
if (this.parentInjector) {
|
|
515
|
-
reflectiveValue = this.parentInjector.get(injectToken,
|
|
519
|
+
reflectiveValue = this.parentInjector.get(injectToken, tryValue);
|
|
516
520
|
}
|
|
517
521
|
else {
|
|
518
522
|
if (dep.optional) {
|
|
@@ -525,7 +529,7 @@ class ReflectiveInjector extends Injector {
|
|
|
525
529
|
}
|
|
526
530
|
}
|
|
527
531
|
else {
|
|
528
|
-
reflectiveValue = this.get(injectToken,
|
|
532
|
+
reflectiveValue = this.get(injectToken, tryValue);
|
|
529
533
|
}
|
|
530
534
|
if (reflectiveValue === tryValue) {
|
|
531
535
|
if (dep.optional) {
|
|
@@ -587,13 +591,13 @@ function getArrayChanges(left, right) {
|
|
|
587
591
|
return changes;
|
|
588
592
|
}
|
|
589
593
|
function classToString(config) {
|
|
590
|
-
if (!config) {
|
|
591
|
-
return '';
|
|
592
|
-
}
|
|
593
594
|
if (typeof config === 'string') {
|
|
594
595
|
return config;
|
|
595
596
|
}
|
|
596
|
-
|
|
597
|
+
if (!config) {
|
|
598
|
+
return '';
|
|
599
|
+
}
|
|
600
|
+
if (Array.isArray(config)) {
|
|
597
601
|
const classes = [];
|
|
598
602
|
for (const i of config) {
|
|
599
603
|
const v = classToString(i);
|
|
@@ -603,7 +607,7 @@ function classToString(config) {
|
|
|
603
607
|
}
|
|
604
608
|
return classes.join(' ');
|
|
605
609
|
}
|
|
606
|
-
|
|
610
|
+
if (typeof config === 'object') {
|
|
607
611
|
if (config.toString !== Object.prototype.toString && !config.toString.toString().includes('[native code]')) {
|
|
608
612
|
return config.toString();
|
|
609
613
|
}
|
|
@@ -737,30 +741,32 @@ class Component extends ReflectiveInjector {
|
|
|
737
741
|
};
|
|
738
742
|
}
|
|
739
743
|
update(newProps, forceUpdate = false) {
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
744
|
+
if (!forceUpdate) {
|
|
745
|
+
const { add, remove, replace } = getObjectChanges(newProps, this.props);
|
|
746
|
+
if (add.length || remove.length || replace.length) {
|
|
747
|
+
this.invokePropsChangedHooks(newProps);
|
|
748
|
+
}
|
|
749
|
+
else if (!this.dirty) {
|
|
750
|
+
this.props = newProps;
|
|
751
|
+
return this.template;
|
|
752
|
+
}
|
|
753
|
+
const newRefs = toRefs(newProps.ref);
|
|
754
|
+
if (this.refs) {
|
|
755
|
+
for (const oldRef of this.refs) {
|
|
756
|
+
if (!newRefs.includes(oldRef)) {
|
|
757
|
+
oldRef.unBind(this.instance);
|
|
758
|
+
}
|
|
753
759
|
}
|
|
754
760
|
}
|
|
761
|
+
for (const newRef of newRefs) {
|
|
762
|
+
newRef.bind(this.instance);
|
|
763
|
+
}
|
|
764
|
+
if (newRefs.length) {
|
|
765
|
+
this.refs = newRefs;
|
|
766
|
+
}
|
|
755
767
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
}
|
|
759
|
-
if (newRefs.length) {
|
|
760
|
-
this.refs = newRefs;
|
|
761
|
-
}
|
|
762
|
-
if (!forceUpdate && typeof this.instance.$useMemo === 'function') {
|
|
763
|
-
if (this.instance.$useMemo(newProps, oldProps)) {
|
|
768
|
+
if (typeof this.instance.$useMemo === 'function') {
|
|
769
|
+
if (this.instance.$useMemo(newProps, this.props)) {
|
|
764
770
|
return this.template;
|
|
765
771
|
}
|
|
766
772
|
}
|
|
@@ -843,7 +849,12 @@ class Component extends ReflectiveInjector {
|
|
|
843
849
|
}
|
|
844
850
|
}
|
|
845
851
|
if (unmountedCallbacks.length) {
|
|
846
|
-
this.unmountedCallbacks
|
|
852
|
+
if (this.unmountedCallbacks) {
|
|
853
|
+
this.unmountedCallbacks.push(...unmountedCallbacks);
|
|
854
|
+
}
|
|
855
|
+
else {
|
|
856
|
+
this.unmountedCallbacks = unmountedCallbacks;
|
|
857
|
+
}
|
|
847
858
|
}
|
|
848
859
|
this.mountCallbacks = null;
|
|
849
860
|
}
|
|
@@ -1232,9 +1243,9 @@ function withAnnotation(annotation, componentSetup) {
|
|
|
1232
1243
|
/**
|
|
1233
1244
|
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
1234
1245
|
*/
|
|
1235
|
-
function inject(token,
|
|
1246
|
+
function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
|
|
1236
1247
|
const component = getSetupContext();
|
|
1237
|
-
return component.get(token,
|
|
1248
|
+
return component.get(token, notFoundValue, flags);
|
|
1238
1249
|
}
|
|
1239
1250
|
/**
|
|
1240
1251
|
* 获取当前组件实例
|
|
@@ -1272,6 +1283,7 @@ function withMemo(canUseMemo, render) {
|
|
|
1272
1283
|
};
|
|
1273
1284
|
}
|
|
1274
1285
|
|
|
1286
|
+
const componentViewCache = new WeakMap();
|
|
1275
1287
|
const listenerReg = /^on(?=[A-Z])/;
|
|
1276
1288
|
function createRenderer(component, nativeRenderer) {
|
|
1277
1289
|
let isInit = true;
|
|
@@ -1280,6 +1292,7 @@ function createRenderer(component, nativeRenderer) {
|
|
|
1280
1292
|
isInit = false;
|
|
1281
1293
|
const atom = {
|
|
1282
1294
|
type: 'component',
|
|
1295
|
+
index: 0,
|
|
1283
1296
|
jsxNode: component,
|
|
1284
1297
|
sibling: null,
|
|
1285
1298
|
child: null,
|
|
@@ -1349,7 +1362,7 @@ function updateView(nativeRenderer, component) {
|
|
|
1349
1362
|
}
|
|
1350
1363
|
}
|
|
1351
1364
|
function applyChanges(nativeRenderer, component) {
|
|
1352
|
-
const { atom, host, isParent, rootHost } = component
|
|
1365
|
+
const { atom, host, isParent, rootHost } = componentViewCache.get(component);
|
|
1353
1366
|
const diffAtom = atom.child;
|
|
1354
1367
|
const template = component.update(component.props, true);
|
|
1355
1368
|
atom.child = createChildChain(template, atom.isSvg);
|
|
@@ -1358,58 +1371,35 @@ function applyChanges(nativeRenderer, component) {
|
|
|
1358
1371
|
isParent,
|
|
1359
1372
|
rootHost
|
|
1360
1373
|
};
|
|
1361
|
-
diff(nativeRenderer, component, atom.child, diffAtom, context
|
|
1374
|
+
diff(nativeRenderer, component, atom.child, diffAtom, context);
|
|
1362
1375
|
const next = atom.sibling;
|
|
1363
1376
|
if (next && next.jsxNode instanceof Component) {
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
}
|
|
1368
|
-
function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expectIndex, index) {
|
|
1369
|
-
let prevDiffAtom = null;
|
|
1370
|
-
let firstDiffAtomIndexed = null;
|
|
1371
|
-
if (oldAtom) {
|
|
1372
|
-
prevDiffAtom = {
|
|
1373
|
-
index,
|
|
1374
|
-
atom: oldAtom,
|
|
1375
|
-
prev: null
|
|
1376
|
-
};
|
|
1377
|
-
index++;
|
|
1378
|
-
firstDiffAtomIndexed = prevDiffAtom;
|
|
1379
|
-
oldAtom = oldAtom.sibling;
|
|
1380
|
-
while (oldAtom) {
|
|
1381
|
-
const diffAtom = {
|
|
1382
|
-
index,
|
|
1383
|
-
atom: oldAtom,
|
|
1384
|
-
prev: prevDiffAtom
|
|
1385
|
-
};
|
|
1386
|
-
prevDiffAtom.next = diffAtom;
|
|
1387
|
-
prevDiffAtom = diffAtom;
|
|
1388
|
-
oldAtom = oldAtom.sibling;
|
|
1389
|
-
index++;
|
|
1390
|
-
}
|
|
1377
|
+
const view = componentViewCache.get(next.jsxNode);
|
|
1378
|
+
view.host = context.host;
|
|
1379
|
+
view.isParent = context.isParent;
|
|
1391
1380
|
}
|
|
1381
|
+
}
|
|
1382
|
+
function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
|
|
1392
1383
|
const commits = [];
|
|
1393
1384
|
function changeOffset() {
|
|
1394
1385
|
offset++;
|
|
1395
1386
|
}
|
|
1396
1387
|
while (newAtom) {
|
|
1397
|
-
|
|
1388
|
+
oldAtom = createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, changeOffset);
|
|
1398
1389
|
newAtom = newAtom.sibling;
|
|
1399
|
-
expectIndex++;
|
|
1400
1390
|
}
|
|
1401
|
-
let dirtyDiffAtom =
|
|
1391
|
+
let dirtyDiffAtom = oldAtom;
|
|
1402
1392
|
while (dirtyDiffAtom) {
|
|
1403
|
-
cleanView(nativeRenderer, dirtyDiffAtom
|
|
1404
|
-
dirtyDiffAtom = dirtyDiffAtom.
|
|
1393
|
+
cleanView(nativeRenderer, dirtyDiffAtom, true);
|
|
1394
|
+
dirtyDiffAtom = dirtyDiffAtom.sibling;
|
|
1405
1395
|
}
|
|
1406
1396
|
let offset = 0;
|
|
1407
1397
|
for (let i = 0; i < commits.length; i++) {
|
|
1408
1398
|
const commit = commits[i];
|
|
1409
|
-
while (
|
|
1410
|
-
if (
|
|
1399
|
+
while (oldAtom) {
|
|
1400
|
+
if (oldAtom.index <= i) {
|
|
1411
1401
|
offset--;
|
|
1412
|
-
|
|
1402
|
+
oldAtom = oldAtom.sibling;
|
|
1413
1403
|
continue;
|
|
1414
1404
|
}
|
|
1415
1405
|
break;
|
|
@@ -1417,47 +1407,42 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1417
1407
|
commit(offset);
|
|
1418
1408
|
}
|
|
1419
1409
|
}
|
|
1420
|
-
function createChanges(newAtom,
|
|
1421
|
-
const startDiffAtom =
|
|
1410
|
+
function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
|
|
1411
|
+
const startDiffAtom = oldAtom;
|
|
1422
1412
|
const { jsxNode: newJsxNode, type } = newAtom;
|
|
1423
1413
|
const key = newJsxNode.key;
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1414
|
+
let prev = null;
|
|
1415
|
+
while (oldAtom) {
|
|
1416
|
+
const diffIndex = oldAtom.index;
|
|
1417
|
+
if (type === oldAtom.type) {
|
|
1427
1418
|
let commit;
|
|
1428
1419
|
if (type === 'text') {
|
|
1429
|
-
commit = updateText(newAtom,
|
|
1420
|
+
commit = updateText(newAtom, oldAtom, nativeRenderer, context);
|
|
1430
1421
|
}
|
|
1431
1422
|
else {
|
|
1432
|
-
const { key: diffKey, type: diffType } =
|
|
1423
|
+
const { key: diffKey, type: diffType } = oldAtom.jsxNode;
|
|
1433
1424
|
if (diffKey !== key || newJsxNode.type !== diffType) {
|
|
1434
|
-
|
|
1425
|
+
prev = oldAtom;
|
|
1426
|
+
oldAtom = oldAtom.sibling;
|
|
1435
1427
|
continue;
|
|
1436
1428
|
}
|
|
1437
1429
|
if (type === 'component') {
|
|
1438
|
-
commit = updateComponent(newAtom,
|
|
1430
|
+
commit = updateComponent(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context);
|
|
1439
1431
|
}
|
|
1440
1432
|
else {
|
|
1441
|
-
commit = updateElement(newAtom,
|
|
1433
|
+
commit = updateElement(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context, parentComponent);
|
|
1442
1434
|
}
|
|
1443
1435
|
}
|
|
1444
1436
|
commits.push(commit);
|
|
1445
|
-
const next =
|
|
1446
|
-
const prev = diffAtomIndexed.prev;
|
|
1437
|
+
const next = oldAtom.sibling;
|
|
1447
1438
|
if (!prev) {
|
|
1448
|
-
|
|
1449
|
-
if (diffAtomIndexed) {
|
|
1450
|
-
diffAtomIndexed.prev = null;
|
|
1451
|
-
}
|
|
1452
|
-
return diffAtomIndexed;
|
|
1453
|
-
}
|
|
1454
|
-
prev.next = next;
|
|
1455
|
-
if (next) {
|
|
1456
|
-
next.prev = prev;
|
|
1439
|
+
return next;
|
|
1457
1440
|
}
|
|
1441
|
+
prev.sibling = next;
|
|
1458
1442
|
return startDiffAtom;
|
|
1459
1443
|
}
|
|
1460
|
-
|
|
1444
|
+
prev = oldAtom;
|
|
1445
|
+
oldAtom = oldAtom.sibling;
|
|
1461
1446
|
}
|
|
1462
1447
|
commits.push(createNewView(newAtom, nativeRenderer, context, parentComponent, effect));
|
|
1463
1448
|
return startDiffAtom;
|
|
@@ -1493,13 +1478,13 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
|
|
|
1493
1478
|
host: newAtom.nativeNode,
|
|
1494
1479
|
isParent: true,
|
|
1495
1480
|
rootHost: context.rootHost
|
|
1496
|
-
}
|
|
1481
|
+
});
|
|
1497
1482
|
}
|
|
1498
1483
|
else if (oldAtom.child) {
|
|
1499
1484
|
let atom = oldAtom.child;
|
|
1500
1485
|
nativeRenderer.cleanChildren(oldAtom.nativeNode, oldAtom.isSvg);
|
|
1501
1486
|
while (atom) {
|
|
1502
|
-
cleanView(nativeRenderer, atom,
|
|
1487
|
+
cleanView(nativeRenderer, atom, false);
|
|
1503
1488
|
atom = atom.sibling;
|
|
1504
1489
|
}
|
|
1505
1490
|
}
|
|
@@ -1514,7 +1499,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
|
|
|
1514
1499
|
const newTemplate = component.update(newProps);
|
|
1515
1500
|
const portalHost = component.instance.$portalHost;
|
|
1516
1501
|
context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
|
|
1517
|
-
component
|
|
1502
|
+
componentViewCache.set(component, Object.assign({ atom: newAtom }, context));
|
|
1518
1503
|
newAtom.jsxNode = component;
|
|
1519
1504
|
if (newTemplate === oldTemplate) {
|
|
1520
1505
|
reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
|
|
@@ -1525,12 +1510,12 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
|
|
|
1525
1510
|
newAtom.child = createChildChain(newTemplate, newAtom.isSvg);
|
|
1526
1511
|
}
|
|
1527
1512
|
if (newAtom.child) {
|
|
1528
|
-
diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context
|
|
1513
|
+
diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context);
|
|
1529
1514
|
}
|
|
1530
1515
|
else if (reusedAtom.child) {
|
|
1531
1516
|
let atom = reusedAtom.child;
|
|
1532
1517
|
while (atom) {
|
|
1533
|
-
cleanView(nativeRenderer, atom,
|
|
1518
|
+
cleanView(nativeRenderer, atom, true);
|
|
1534
1519
|
atom = atom.sibling;
|
|
1535
1520
|
}
|
|
1536
1521
|
}
|
|
@@ -1563,9 +1548,9 @@ function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveVi
|
|
|
1563
1548
|
}
|
|
1564
1549
|
function cleanView(nativeRenderer, atom, needClean) {
|
|
1565
1550
|
if (atom.nativeNode) {
|
|
1566
|
-
if (
|
|
1551
|
+
if (needClean) {
|
|
1567
1552
|
nativeRenderer.remove(atom.nativeNode, atom.isSvg);
|
|
1568
|
-
needClean =
|
|
1553
|
+
needClean = false;
|
|
1569
1554
|
}
|
|
1570
1555
|
if (atom.type === 'element') {
|
|
1571
1556
|
const ref = atom.jsxNode.props[refKey];
|
|
@@ -1575,7 +1560,7 @@ function cleanView(nativeRenderer, atom, needClean) {
|
|
|
1575
1560
|
let child = atom.child;
|
|
1576
1561
|
while (child) {
|
|
1577
1562
|
if (child.jsxNode instanceof Component && child.jsxNode.instance.$portalHost) {
|
|
1578
|
-
needClean =
|
|
1563
|
+
needClean = true;
|
|
1579
1564
|
}
|
|
1580
1565
|
cleanView(nativeRenderer, child, needClean);
|
|
1581
1566
|
child = child.sibling;
|
|
@@ -1588,7 +1573,7 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
1588
1573
|
const { template, portalHost } = component.render();
|
|
1589
1574
|
from.child = createChildChain(template, from.isSvg);
|
|
1590
1575
|
context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
|
|
1591
|
-
component
|
|
1576
|
+
componentViewCache.set(component, Object.assign({ atom: from }, context));
|
|
1592
1577
|
let child = from.child;
|
|
1593
1578
|
while (child) {
|
|
1594
1579
|
buildView(nativeRenderer, component, child, context);
|
|
@@ -1599,6 +1584,7 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
1599
1584
|
function createChainByJSXComponent(jsxNode, prevAtom, isSvg) {
|
|
1600
1585
|
const atom = {
|
|
1601
1586
|
type: 'component',
|
|
1587
|
+
index: prevAtom.index + 1,
|
|
1602
1588
|
jsxNode,
|
|
1603
1589
|
sibling: null,
|
|
1604
1590
|
child: null,
|
|
@@ -1611,6 +1597,7 @@ function createChainByJSXComponent(jsxNode, prevAtom, isSvg) {
|
|
|
1611
1597
|
function createChainByJSXText(jsxNode, prevAtom, isSvg) {
|
|
1612
1598
|
const atom = {
|
|
1613
1599
|
type: 'text',
|
|
1600
|
+
index: prevAtom.index + 1,
|
|
1614
1601
|
jsxNode,
|
|
1615
1602
|
sibling: null,
|
|
1616
1603
|
child: null,
|
|
@@ -1624,6 +1611,7 @@ function createChainByJSXElement(element, prevAtom, isSvg) {
|
|
|
1624
1611
|
isSvg = isSvg || element.type === 'svg';
|
|
1625
1612
|
const atom = {
|
|
1626
1613
|
type: 'element',
|
|
1614
|
+
index: prevAtom.index + 1,
|
|
1627
1615
|
jsxNode: element,
|
|
1628
1616
|
sibling: null,
|
|
1629
1617
|
child: null,
|
|
@@ -1663,7 +1651,7 @@ function createChainByChildren(children, prevAtom, isSvg) {
|
|
|
1663
1651
|
return prevAtom;
|
|
1664
1652
|
}
|
|
1665
1653
|
function createChildChain(template, isSvg) {
|
|
1666
|
-
const beforeAtom = { sibling: null };
|
|
1654
|
+
const beforeAtom = { sibling: null, index: -1 };
|
|
1667
1655
|
createChainByNode(template, beforeAtom, isSvg);
|
|
1668
1656
|
return beforeAtom.sibling;
|
|
1669
1657
|
}
|
|
@@ -1726,6 +1714,11 @@ function createTextNode(nativeRenderer, text, isSvg) {
|
|
|
1726
1714
|
return nativeRenderer.createTextNode(text, isSvg);
|
|
1727
1715
|
}
|
|
1728
1716
|
function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNode, isSvg) {
|
|
1717
|
+
if (newVNode === oldVNode) {
|
|
1718
|
+
return () => {
|
|
1719
|
+
//
|
|
1720
|
+
};
|
|
1721
|
+
}
|
|
1729
1722
|
const changes = getObjectChanges(newVNode.props, oldVNode.props);
|
|
1730
1723
|
let unBindRefs;
|
|
1731
1724
|
let bindRefs;
|
|
@@ -1884,7 +1877,7 @@ function viewfly(config) {
|
|
|
1884
1877
|
return destroyed ? null : root;
|
|
1885
1878
|
};
|
|
1886
1879
|
}), function () {
|
|
1887
|
-
if (destroyed) {
|
|
1880
|
+
if (destroyed || !autoUpdate) {
|
|
1888
1881
|
return;
|
|
1889
1882
|
}
|
|
1890
1883
|
nextTick(() => {
|