@viewfly/core 1.0.0-alpha.1 → 1.0.0-alpha.10

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.
@@ -22,5 +22,5 @@ export type ExtractValueType<T> = T extends Type<any> ? InstanceType<T> : T exte
22
22
  */
23
23
  export declare abstract class Injector {
24
24
  abstract parentInjector: Injector | null;
25
- abstract get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, flags?: InjectFlags, notFoundValue?: U): ExtractValueType<T> | U;
25
+ abstract get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, notFoundValue?: U, flags?: InjectFlags): ExtractValueType<T> | U;
26
26
  }
@@ -37,7 +37,7 @@ export declare const Optional: OptionalDecorator;
37
37
  export interface Prop {
38
38
  }
39
39
  export interface PropDecorator {
40
- <T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token?: T | ForwardRef<ExtractValueType<T>>, flags?: InjectFlags, notFoundValue?: U): PropertyDecorator;
40
+ <T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token?: T | ForwardRef<ExtractValueType<T>>, notFoundValue?: U, flags?: InjectFlags): PropertyDecorator;
41
41
  new (token: any): Prop;
42
42
  }
43
43
  export declare const Prop: PropDecorator;
@@ -2,5 +2,5 @@ import { InjectFlags, Injector } from './injector';
2
2
  export declare const THROW_IF_NOT_FOUND: any;
3
3
  export declare class NullInjector extends Injector {
4
4
  parentInjector: null;
5
- get(token: any, flag?: InjectFlags, notFoundValue?: any): any;
5
+ get(token: any, notFoundValue?: any, _?: InjectFlags): any;
6
6
  }
@@ -17,10 +17,10 @@ export declare class ReflectiveInjector extends Injector {
17
17
  /**
18
18
  * 用于获取当前注入器上下文内的实例、对象或数据
19
19
  * @param token 访问 token
20
- * @param flags 查询规则
21
20
  * @param notFoundValue 如未查找到的返回值
21
+ * @param flags 查询规则
22
22
  */
23
- get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, flags?: InjectFlags, notFoundValue?: U): ExtractValueType<T> | U;
23
+ get<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, notFoundValue?: U, flags?: InjectFlags): ExtractValueType<T> | U;
24
24
  private getValue;
25
25
  /**
26
26
  * 解决并获取依赖参数
@@ -21,6 +21,7 @@ export declare function classToString(config: unknown): string;
21
21
  export declare function styleToObject(style: string | Record<string, any>): Record<string, any>;
22
22
  export interface TextAtom {
23
23
  type: 'text';
24
+ index: number;
24
25
  jsxNode: string;
25
26
  nativeNode: NativeNode | null;
26
27
  child: Atom | null;
@@ -29,6 +30,7 @@ export interface TextAtom {
29
30
  }
30
31
  export interface ElementAtom {
31
32
  type: 'element';
33
+ index: number;
32
34
  jsxNode: JSXNode<string>;
33
35
  nativeNode: NativeNode | null;
34
36
  child: Atom | null;
@@ -37,6 +39,7 @@ export interface ElementAtom {
37
39
  }
38
40
  export interface ComponentAtom {
39
41
  type: 'component';
42
+ index: number;
40
43
  jsxNode: JSXNode<JSXInternal.ComponentSetup> | Component;
41
44
  nativeNode: NativeNode | null;
42
45
  child: Atom | null;
@@ -1,6 +1,5 @@
1
1
  import { AbstractType, ExtractValueType, InjectFlags, InjectionToken, Injector, Provider, ReflectiveInjector, Type } from '../di/_api';
2
2
  import { Key, Props } from './jsx-element';
3
- import { ComponentView } from './_utils';
4
3
  /**
5
4
  * Viewfly 组件管理类,用于管理组件的生命周期,上下文等
6
5
  */
@@ -14,7 +13,6 @@ export declare class Component extends ReflectiveInjector {
14
13
  changedSubComponents: Set<Component>;
15
14
  get dirty(): boolean;
16
15
  get changed(): boolean;
17
- $$view: ComponentView;
18
16
  unmountedCallbacks?: LifeCycleCallback[] | null;
19
17
  mountCallbacks?: LifeCycleCallback[] | null;
20
18
  propsChangedCallbacks?: PropsChangedCallback<any>[] | null;
@@ -33,7 +31,7 @@ export declare class Component extends ReflectiveInjector {
33
31
  template: any;
34
32
  portalHost: import("./injection-tokens").NativeNode | undefined;
35
33
  };
36
- update(newProps: Props, forceUpdate?: boolean): any;
34
+ update(newProps: Record<string, any>, forceUpdate?: boolean): any;
37
35
  provide<T>(providers: Provider<T> | Provider<T>[]): void;
38
36
  rendered(): void;
39
37
  destroy(): void;
@@ -237,7 +235,7 @@ export declare function withAnnotation<T extends JSXInternal.ComponentSetup>(ann
237
235
  /**
238
236
  * 通过组件上下文获取 IoC 容器内数据的勾子方法
239
237
  */
240
- export declare function inject<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, flags?: InjectFlags, notFoundValue?: U): ExtractValueType<T> | U;
238
+ export declare function inject<T extends Type<any> | AbstractType<any> | InjectionToken<any>, U = never>(token: T, notFoundValue?: U, flags?: InjectFlags): ExtractValueType<T> | U;
241
239
  /**
242
240
  * 获取当前组件实例
243
241
  */
@@ -1,19 +1,17 @@
1
1
  import { ListenDelegate } from './_utils';
2
2
  export interface Props {
3
3
  children?: JSXInternal.ViewNode | JSXInternal.ViewNode[];
4
- [key: string]: any;
5
- [key: symbol]: any;
6
4
  }
7
5
  export declare function Fragment(props: Props): () => any;
8
6
  export type Key = number | string;
9
- export declare function jsx(type: string | JSXInternal.ComponentSetup, props: Props, key?: Key): JSXNode;
7
+ export declare function jsx(type: string | JSXInternal.ComponentSetup, props: Props & Record<string, any>, key?: Key): JSXNode;
10
8
  export declare const jsxs: typeof jsx;
11
9
  export interface JSXNode<T = string | JSXInternal.ComponentSetup> {
12
10
  type: T;
13
- props: Props;
11
+ props: Props & Record<string, any>;
14
12
  key?: Key;
15
13
  on?: Record<string, ListenDelegate>;
16
14
  }
17
15
  export declare const JSXNodeFactory: {
18
- createNode<T = string | JSXInternal.ComponentSetup<any>>(type: T, props: Props, key?: Key): JSXNode<T>;
16
+ createNode<T = string | JSXInternal.ComponentSetup<any>>(type: T, props: Props & Record<string, any>, key?: Key): JSXNode<T>;
19
17
  };
@@ -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
- get(token, flag, notFoundValue = THROW_IF_NOT_FOUND) {
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, flags = InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
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, InjectFlags.Default, notFoundValue);
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, notFoundValue);
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, tryValue);
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, InjectFlags.Default, tryValue);
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, InjectFlags.Default, tryValue);
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
- else if (Array.isArray(config)) {
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
- else if (typeof config === 'object') {
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
- const oldProps = this.props;
741
- const { add, remove, replace } = getObjectChanges(newProps, this.props);
742
- if (add.length || remove.length || replace.length) {
743
- this.invokePropsChangedHooks(newProps);
744
- }
745
- else if (!this.dirty) {
746
- return this.template;
747
- }
748
- const newRefs = toRefs(newProps.ref);
749
- if (this.refs) {
750
- for (const oldRef of this.refs) {
751
- if (!newRefs.includes(oldRef)) {
752
- oldRef.unBind(this.instance);
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
- for (const newRef of newRefs) {
757
- newRef.bind(this.instance);
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 = 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, flags = InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
1246
+ function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
1236
1247
  const component = getSetupContext();
1237
- return component.get(token, flags, notFoundValue);
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.$$view;
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, 0, 0);
1374
+ diff(nativeRenderer, component, atom.child, diffAtom, context);
1362
1375
  const next = atom.sibling;
1363
1376
  if (next && next.jsxNode instanceof Component) {
1364
- next.jsxNode.$$view.host = context.host;
1365
- next.jsxNode.$$view.isParent = context.isParent;
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
- firstDiffAtomIndexed = createChanges(newAtom, expectIndex, firstDiffAtomIndexed, nativeRenderer, commits, context, parentComponent, changeOffset);
1388
+ oldAtom = createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, changeOffset);
1398
1389
  newAtom = newAtom.sibling;
1399
- expectIndex++;
1400
1390
  }
1401
- let dirtyDiffAtom = firstDiffAtomIndexed;
1391
+ let dirtyDiffAtom = oldAtom;
1402
1392
  while (dirtyDiffAtom) {
1403
- cleanView(nativeRenderer, dirtyDiffAtom.atom, false);
1404
- dirtyDiffAtom = dirtyDiffAtom.next;
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 (firstDiffAtomIndexed) {
1410
- if (firstDiffAtomIndexed.index <= i) {
1399
+ while (oldAtom) {
1400
+ if (oldAtom.index <= i) {
1411
1401
  offset--;
1412
- firstDiffAtomIndexed = firstDiffAtomIndexed.next;
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, expectIndex, diffAtomIndexed, nativeRenderer, commits, context, parentComponent, effect) {
1421
- const startDiffAtom = diffAtomIndexed;
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
- while (diffAtomIndexed) {
1425
- const { atom: diffAtom, index: diffIndex } = diffAtomIndexed;
1426
- if (type === diffAtom.type) {
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, diffAtom, nativeRenderer, context);
1420
+ commit = updateText(newAtom, oldAtom, nativeRenderer, context);
1430
1421
  }
1431
1422
  else {
1432
- const { key: diffKey, type: diffType } = diffAtom.jsxNode;
1423
+ const { key: diffKey, type: diffType } = oldAtom.jsxNode;
1433
1424
  if (diffKey !== key || newJsxNode.type !== diffType) {
1434
- diffAtomIndexed = diffAtomIndexed.next;
1425
+ prev = oldAtom;
1426
+ oldAtom = oldAtom.sibling;
1435
1427
  continue;
1436
1428
  }
1437
1429
  if (type === 'component') {
1438
- commit = updateComponent(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context);
1430
+ commit = updateComponent(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context);
1439
1431
  }
1440
1432
  else {
1441
- commit = updateElement(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context, parentComponent);
1433
+ commit = updateElement(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context, parentComponent);
1442
1434
  }
1443
1435
  }
1444
1436
  commits.push(commit);
1445
- const next = diffAtomIndexed.next;
1446
- const prev = diffAtomIndexed.prev;
1437
+ const next = oldAtom.sibling;
1447
1438
  if (!prev) {
1448
- diffAtomIndexed = next;
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
- diffAtomIndexed = diffAtomIndexed.next;
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
- }, 0, 0);
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, true);
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.$$view = Object.assign({ atom: newAtom }, context);
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, expectIndex, oldIndex + offset);
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, false);
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 (!needClean) {
1551
+ if (needClean) {
1567
1552
  nativeRenderer.remove(atom.nativeNode, atom.isSvg);
1568
- needClean = true;
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 = false;
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.$$view = Object.assign({ atom: from }, context);
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(() => {
package/bundles/index.js CHANGED
@@ -163,6 +163,40 @@ exports.InjectFlags = void 0;
163
163
  class Injector {
164
164
  }
165
165
 
166
+ /**
167
+ * 构造函数参数装饰器,用于改变注入 token
168
+ */
169
+ const Inject = function InjectDecorator(token) {
170
+ if (this instanceof Inject) {
171
+ this.token = token;
172
+ }
173
+ else {
174
+ return makeParamDecorator(Inject, new Inject(token));
175
+ }
176
+ };
177
+ const Self = function SelfDecorator() {
178
+ if (!(this instanceof Self)) {
179
+ return makeParamDecorator(Self, new Self());
180
+ }
181
+ };
182
+ const SkipSelf = function SkipSelfDecorator() {
183
+ if (!(this instanceof SkipSelf)) {
184
+ return makeParamDecorator(SkipSelf, new SkipSelf());
185
+ }
186
+ };
187
+ const Optional = function OptionalDecorator() {
188
+ if (!(this instanceof Optional)) {
189
+ return makeParamDecorator(Optional, new Optional());
190
+ }
191
+ };
192
+ const Prop = function PropDecorator(token, notFoundValue, flags) {
193
+ if (!(this instanceof Prop)) {
194
+ return makePropertyDecorator(Prop, token, function (instance, propertyName, token, injector) {
195
+ instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, notFoundValue, flags);
196
+ });
197
+ }
198
+ };
199
+
166
200
  function stringify(token) {
167
201
  if (typeof token === 'string') {
168
202
  return token;
@@ -207,7 +241,8 @@ class NullInjector extends Injector {
207
241
  super(...arguments);
208
242
  this.parentInjector = null;
209
243
  }
210
- get(token, flag, notFoundValue = THROW_IF_NOT_FOUND) {
244
+ /* eslint-disable-next-line */
245
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, _) {
211
246
  if (notFoundValue === THROW_IF_NOT_FOUND) {
212
247
  throw nullInjectorErrorFn(token);
213
248
  }
@@ -215,40 +250,6 @@ class NullInjector extends Injector {
215
250
  }
216
251
  }
217
252
 
218
- /**
219
- * 构造函数参数装饰器,用于改变注入 token
220
- */
221
- const Inject = function InjectDecorator(token) {
222
- if (this instanceof Inject) {
223
- this.token = token;
224
- }
225
- else {
226
- return makeParamDecorator(Inject, new Inject(token));
227
- }
228
- };
229
- const Self = function SelfDecorator() {
230
- if (!(this instanceof Self)) {
231
- return makeParamDecorator(Self, new Self());
232
- }
233
- };
234
- const SkipSelf = function SkipSelfDecorator() {
235
- if (!(this instanceof SkipSelf)) {
236
- return makeParamDecorator(SkipSelf, new SkipSelf());
237
- }
238
- };
239
- const Optional = function OptionalDecorator() {
240
- if (!(this instanceof Optional)) {
241
- return makeParamDecorator(Optional, new Optional());
242
- }
243
- };
244
- const Prop = function PropDecorator(token, flags, notFoundValue = THROW_IF_NOT_FOUND) {
245
- if (!(this instanceof Prop)) {
246
- return makePropertyDecorator(Prop, token, function (instance, propertyName, token, injector) {
247
- instance[propertyName] = injector.get(token instanceof ForwardRef ? token.getRef() : token, flags, notFoundValue);
248
- });
249
- }
250
- };
251
-
252
253
  /**
253
254
  * 标准化 provide,并返回统一数据结构
254
255
  * @param provider
@@ -426,15 +427,15 @@ class ReflectiveInjector extends Injector {
426
427
  /**
427
428
  * 用于获取当前注入器上下文内的实例、对象或数据
428
429
  * @param token 访问 token
429
- * @param flags 查询规则
430
430
  * @param notFoundValue 如未查找到的返回值
431
+ * @param flags 查询规则
431
432
  */
432
- get(token, flags = exports.InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
433
+ get(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
433
434
  var _a;
434
435
  flags = flags || exports.InjectFlags.Default;
435
436
  if (flags === exports.InjectFlags.SkipSelf) {
436
437
  if (this.parentInjector) {
437
- return this.parentInjector.get(token, exports.InjectFlags.Default, notFoundValue);
438
+ return this.parentInjector.get(token, notFoundValue);
438
439
  }
439
440
  if (notFoundValue !== THROW_IF_NOT_FOUND) {
440
441
  return notFoundValue;
@@ -478,9 +479,12 @@ class ReflectiveInjector extends Injector {
478
479
  return notFoundValue;
479
480
  }
480
481
  if (this.parentInjector) {
481
- return this.parentInjector.get(token, flags === exports.InjectFlags.Optional ? exports.InjectFlags.Optional : exports.InjectFlags.Default, notFoundValue);
482
+ return this.parentInjector.get(token, notFoundValue, flags === exports.InjectFlags.Optional ? exports.InjectFlags.Optional : exports.InjectFlags.Default);
482
483
  }
483
484
  if (notFoundValue === THROW_IF_NOT_FOUND) {
485
+ // if (flags === InjectFlags.Optional) {
486
+ // return null as U
487
+ // }
484
488
  throw reflectiveInjectorErrorFn(token);
485
489
  }
486
490
  return notFoundValue;
@@ -510,11 +514,11 @@ class ReflectiveInjector extends Injector {
510
514
  const tryValue = {};
511
515
  const injectToken = dep.injectKey instanceof ForwardRef ? dep.injectKey.getRef() : dep.injectKey;
512
516
  if (dep.visibility instanceof Self) {
513
- reflectiveValue = this.get(injectToken, exports.InjectFlags.Self, tryValue);
517
+ reflectiveValue = this.get(injectToken, tryValue, exports.InjectFlags.Self);
514
518
  }
515
519
  else if (dep.visibility instanceof SkipSelf) {
516
520
  if (this.parentInjector) {
517
- reflectiveValue = this.parentInjector.get(injectToken, exports.InjectFlags.Default, tryValue);
521
+ reflectiveValue = this.parentInjector.get(injectToken, tryValue);
518
522
  }
519
523
  else {
520
524
  if (dep.optional) {
@@ -527,7 +531,7 @@ class ReflectiveInjector extends Injector {
527
531
  }
528
532
  }
529
533
  else {
530
- reflectiveValue = this.get(injectToken, exports.InjectFlags.Default, tryValue);
534
+ reflectiveValue = this.get(injectToken, tryValue);
531
535
  }
532
536
  if (reflectiveValue === tryValue) {
533
537
  if (dep.optional) {
@@ -589,13 +593,13 @@ function getArrayChanges(left, right) {
589
593
  return changes;
590
594
  }
591
595
  function classToString(config) {
592
- if (!config) {
593
- return '';
594
- }
595
596
  if (typeof config === 'string') {
596
597
  return config;
597
598
  }
598
- else if (Array.isArray(config)) {
599
+ if (!config) {
600
+ return '';
601
+ }
602
+ if (Array.isArray(config)) {
599
603
  const classes = [];
600
604
  for (const i of config) {
601
605
  const v = classToString(i);
@@ -605,7 +609,7 @@ function classToString(config) {
605
609
  }
606
610
  return classes.join(' ');
607
611
  }
608
- else if (typeof config === 'object') {
612
+ if (typeof config === 'object') {
609
613
  if (config.toString !== Object.prototype.toString && !config.toString.toString().includes('[native code]')) {
610
614
  return config.toString();
611
615
  }
@@ -739,30 +743,32 @@ class Component extends ReflectiveInjector {
739
743
  };
740
744
  }
741
745
  update(newProps, forceUpdate = false) {
742
- const oldProps = this.props;
743
- const { add, remove, replace } = getObjectChanges(newProps, this.props);
744
- if (add.length || remove.length || replace.length) {
745
- this.invokePropsChangedHooks(newProps);
746
- }
747
- else if (!this.dirty) {
748
- return this.template;
749
- }
750
- const newRefs = toRefs(newProps.ref);
751
- if (this.refs) {
752
- for (const oldRef of this.refs) {
753
- if (!newRefs.includes(oldRef)) {
754
- oldRef.unBind(this.instance);
746
+ if (!forceUpdate) {
747
+ const { add, remove, replace } = getObjectChanges(newProps, this.props);
748
+ if (add.length || remove.length || replace.length) {
749
+ this.invokePropsChangedHooks(newProps);
750
+ }
751
+ else if (!this.dirty) {
752
+ this.props = newProps;
753
+ return this.template;
754
+ }
755
+ const newRefs = toRefs(newProps.ref);
756
+ if (this.refs) {
757
+ for (const oldRef of this.refs) {
758
+ if (!newRefs.includes(oldRef)) {
759
+ oldRef.unBind(this.instance);
760
+ }
755
761
  }
756
762
  }
763
+ for (const newRef of newRefs) {
764
+ newRef.bind(this.instance);
765
+ }
766
+ if (newRefs.length) {
767
+ this.refs = newRefs;
768
+ }
757
769
  }
758
- for (const newRef of newRefs) {
759
- newRef.bind(this.instance);
760
- }
761
- if (newRefs.length) {
762
- this.refs = newRefs;
763
- }
764
- if (!forceUpdate && typeof this.instance.$useMemo === 'function') {
765
- if (this.instance.$useMemo(newProps, oldProps)) {
770
+ if (typeof this.instance.$useMemo === 'function') {
771
+ if (this.instance.$useMemo(newProps, this.props)) {
766
772
  return this.template;
767
773
  }
768
774
  }
@@ -845,7 +851,12 @@ class Component extends ReflectiveInjector {
845
851
  }
846
852
  }
847
853
  if (unmountedCallbacks.length) {
848
- this.unmountedCallbacks = unmountedCallbacks;
854
+ if (this.unmountedCallbacks) {
855
+ this.unmountedCallbacks.push(...unmountedCallbacks);
856
+ }
857
+ else {
858
+ this.unmountedCallbacks = unmountedCallbacks;
859
+ }
849
860
  }
850
861
  this.mountCallbacks = null;
851
862
  }
@@ -1234,9 +1245,9 @@ function withAnnotation(annotation, componentSetup) {
1234
1245
  /**
1235
1246
  * 通过组件上下文获取 IoC 容器内数据的勾子方法
1236
1247
  */
1237
- function inject(token, flags = exports.InjectFlags.Default, notFoundValue = THROW_IF_NOT_FOUND) {
1248
+ function inject(token, notFoundValue = THROW_IF_NOT_FOUND, flags) {
1238
1249
  const component = getSetupContext();
1239
- return component.get(token, flags, notFoundValue);
1250
+ return component.get(token, notFoundValue, flags);
1240
1251
  }
1241
1252
  /**
1242
1253
  * 获取当前组件实例
@@ -1274,6 +1285,7 @@ function withMemo(canUseMemo, render) {
1274
1285
  };
1275
1286
  }
1276
1287
 
1288
+ const componentViewCache = new WeakMap();
1277
1289
  const listenerReg = /^on(?=[A-Z])/;
1278
1290
  function createRenderer(component, nativeRenderer) {
1279
1291
  let isInit = true;
@@ -1282,6 +1294,7 @@ function createRenderer(component, nativeRenderer) {
1282
1294
  isInit = false;
1283
1295
  const atom = {
1284
1296
  type: 'component',
1297
+ index: 0,
1285
1298
  jsxNode: component,
1286
1299
  sibling: null,
1287
1300
  child: null,
@@ -1351,7 +1364,7 @@ function updateView(nativeRenderer, component) {
1351
1364
  }
1352
1365
  }
1353
1366
  function applyChanges(nativeRenderer, component) {
1354
- const { atom, host, isParent, rootHost } = component.$$view;
1367
+ const { atom, host, isParent, rootHost } = componentViewCache.get(component);
1355
1368
  const diffAtom = atom.child;
1356
1369
  const template = component.update(component.props, true);
1357
1370
  atom.child = createChildChain(template, atom.isSvg);
@@ -1360,58 +1373,35 @@ function applyChanges(nativeRenderer, component) {
1360
1373
  isParent,
1361
1374
  rootHost
1362
1375
  };
1363
- diff(nativeRenderer, component, atom.child, diffAtom, context, 0, 0);
1376
+ diff(nativeRenderer, component, atom.child, diffAtom, context);
1364
1377
  const next = atom.sibling;
1365
1378
  if (next && next.jsxNode instanceof Component) {
1366
- next.jsxNode.$$view.host = context.host;
1367
- next.jsxNode.$$view.isParent = context.isParent;
1368
- }
1369
- }
1370
- function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expectIndex, index) {
1371
- let prevDiffAtom = null;
1372
- let firstDiffAtomIndexed = null;
1373
- if (oldAtom) {
1374
- prevDiffAtom = {
1375
- index,
1376
- atom: oldAtom,
1377
- prev: null
1378
- };
1379
- index++;
1380
- firstDiffAtomIndexed = prevDiffAtom;
1381
- oldAtom = oldAtom.sibling;
1382
- while (oldAtom) {
1383
- const diffAtom = {
1384
- index,
1385
- atom: oldAtom,
1386
- prev: prevDiffAtom
1387
- };
1388
- prevDiffAtom.next = diffAtom;
1389
- prevDiffAtom = diffAtom;
1390
- oldAtom = oldAtom.sibling;
1391
- index++;
1392
- }
1379
+ const view = componentViewCache.get(next.jsxNode);
1380
+ view.host = context.host;
1381
+ view.isParent = context.isParent;
1393
1382
  }
1383
+ }
1384
+ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1394
1385
  const commits = [];
1395
1386
  function changeOffset() {
1396
1387
  offset++;
1397
1388
  }
1398
1389
  while (newAtom) {
1399
- firstDiffAtomIndexed = createChanges(newAtom, expectIndex, firstDiffAtomIndexed, nativeRenderer, commits, context, parentComponent, changeOffset);
1390
+ oldAtom = createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, changeOffset);
1400
1391
  newAtom = newAtom.sibling;
1401
- expectIndex++;
1402
1392
  }
1403
- let dirtyDiffAtom = firstDiffAtomIndexed;
1393
+ let dirtyDiffAtom = oldAtom;
1404
1394
  while (dirtyDiffAtom) {
1405
- cleanView(nativeRenderer, dirtyDiffAtom.atom, false);
1406
- dirtyDiffAtom = dirtyDiffAtom.next;
1395
+ cleanView(nativeRenderer, dirtyDiffAtom, true);
1396
+ dirtyDiffAtom = dirtyDiffAtom.sibling;
1407
1397
  }
1408
1398
  let offset = 0;
1409
1399
  for (let i = 0; i < commits.length; i++) {
1410
1400
  const commit = commits[i];
1411
- while (firstDiffAtomIndexed) {
1412
- if (firstDiffAtomIndexed.index <= i) {
1401
+ while (oldAtom) {
1402
+ if (oldAtom.index <= i) {
1413
1403
  offset--;
1414
- firstDiffAtomIndexed = firstDiffAtomIndexed.next;
1404
+ oldAtom = oldAtom.sibling;
1415
1405
  continue;
1416
1406
  }
1417
1407
  break;
@@ -1419,47 +1409,42 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1419
1409
  commit(offset);
1420
1410
  }
1421
1411
  }
1422
- function createChanges(newAtom, expectIndex, diffAtomIndexed, nativeRenderer, commits, context, parentComponent, effect) {
1423
- const startDiffAtom = diffAtomIndexed;
1412
+ function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
1413
+ const startDiffAtom = oldAtom;
1424
1414
  const { jsxNode: newJsxNode, type } = newAtom;
1425
1415
  const key = newJsxNode.key;
1426
- while (diffAtomIndexed) {
1427
- const { atom: diffAtom, index: diffIndex } = diffAtomIndexed;
1428
- if (type === diffAtom.type) {
1416
+ let prev = null;
1417
+ while (oldAtom) {
1418
+ const diffIndex = oldAtom.index;
1419
+ if (type === oldAtom.type) {
1429
1420
  let commit;
1430
1421
  if (type === 'text') {
1431
- commit = updateText(newAtom, diffAtom, nativeRenderer, context);
1422
+ commit = updateText(newAtom, oldAtom, nativeRenderer, context);
1432
1423
  }
1433
1424
  else {
1434
- const { key: diffKey, type: diffType } = diffAtom.jsxNode;
1425
+ const { key: diffKey, type: diffType } = oldAtom.jsxNode;
1435
1426
  if (diffKey !== key || newJsxNode.type !== diffType) {
1436
- diffAtomIndexed = diffAtomIndexed.next;
1427
+ prev = oldAtom;
1428
+ oldAtom = oldAtom.sibling;
1437
1429
  continue;
1438
1430
  }
1439
1431
  if (type === 'component') {
1440
- commit = updateComponent(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context);
1432
+ commit = updateComponent(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context);
1441
1433
  }
1442
1434
  else {
1443
- commit = updateElement(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context, parentComponent);
1435
+ commit = updateElement(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context, parentComponent);
1444
1436
  }
1445
1437
  }
1446
1438
  commits.push(commit);
1447
- const next = diffAtomIndexed.next;
1448
- const prev = diffAtomIndexed.prev;
1439
+ const next = oldAtom.sibling;
1449
1440
  if (!prev) {
1450
- diffAtomIndexed = next;
1451
- if (diffAtomIndexed) {
1452
- diffAtomIndexed.prev = null;
1453
- }
1454
- return diffAtomIndexed;
1455
- }
1456
- prev.next = next;
1457
- if (next) {
1458
- next.prev = prev;
1441
+ return next;
1459
1442
  }
1443
+ prev.sibling = next;
1460
1444
  return startDiffAtom;
1461
1445
  }
1462
- diffAtomIndexed = diffAtomIndexed.next;
1446
+ prev = oldAtom;
1447
+ oldAtom = oldAtom.sibling;
1463
1448
  }
1464
1449
  commits.push(createNewView(newAtom, nativeRenderer, context, parentComponent, effect));
1465
1450
  return startDiffAtom;
@@ -1495,13 +1480,13 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
1495
1480
  host: newAtom.nativeNode,
1496
1481
  isParent: true,
1497
1482
  rootHost: context.rootHost
1498
- }, 0, 0);
1483
+ });
1499
1484
  }
1500
1485
  else if (oldAtom.child) {
1501
1486
  let atom = oldAtom.child;
1502
1487
  nativeRenderer.cleanChildren(oldAtom.nativeNode, oldAtom.isSvg);
1503
1488
  while (atom) {
1504
- cleanView(nativeRenderer, atom, true);
1489
+ cleanView(nativeRenderer, atom, false);
1505
1490
  atom = atom.sibling;
1506
1491
  }
1507
1492
  }
@@ -1516,7 +1501,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
1516
1501
  const newTemplate = component.update(newProps);
1517
1502
  const portalHost = component.instance.$portalHost;
1518
1503
  context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
1519
- component.$$view = Object.assign({ atom: newAtom }, context);
1504
+ componentViewCache.set(component, Object.assign({ atom: newAtom }, context));
1520
1505
  newAtom.jsxNode = component;
1521
1506
  if (newTemplate === oldTemplate) {
1522
1507
  reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
@@ -1527,12 +1512,12 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
1527
1512
  newAtom.child = createChildChain(newTemplate, newAtom.isSvg);
1528
1513
  }
1529
1514
  if (newAtom.child) {
1530
- diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex + offset);
1515
+ diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context);
1531
1516
  }
1532
1517
  else if (reusedAtom.child) {
1533
1518
  let atom = reusedAtom.child;
1534
1519
  while (atom) {
1535
- cleanView(nativeRenderer, atom, false);
1520
+ cleanView(nativeRenderer, atom, true);
1536
1521
  atom = atom.sibling;
1537
1522
  }
1538
1523
  }
@@ -1565,9 +1550,9 @@ function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveVi
1565
1550
  }
1566
1551
  function cleanView(nativeRenderer, atom, needClean) {
1567
1552
  if (atom.nativeNode) {
1568
- if (!needClean) {
1553
+ if (needClean) {
1569
1554
  nativeRenderer.remove(atom.nativeNode, atom.isSvg);
1570
- needClean = true;
1555
+ needClean = false;
1571
1556
  }
1572
1557
  if (atom.type === 'element') {
1573
1558
  const ref = atom.jsxNode.props[refKey];
@@ -1577,7 +1562,7 @@ function cleanView(nativeRenderer, atom, needClean) {
1577
1562
  let child = atom.child;
1578
1563
  while (child) {
1579
1564
  if (child.jsxNode instanceof Component && child.jsxNode.instance.$portalHost) {
1580
- needClean = false;
1565
+ needClean = true;
1581
1566
  }
1582
1567
  cleanView(nativeRenderer, child, needClean);
1583
1568
  child = child.sibling;
@@ -1590,7 +1575,7 @@ function componentRender(nativeRenderer, component, from, context) {
1590
1575
  const { template, portalHost } = component.render();
1591
1576
  from.child = createChildChain(template, from.isSvg);
1592
1577
  context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
1593
- component.$$view = Object.assign({ atom: from }, context);
1578
+ componentViewCache.set(component, Object.assign({ atom: from }, context));
1594
1579
  let child = from.child;
1595
1580
  while (child) {
1596
1581
  buildView(nativeRenderer, component, child, context);
@@ -1601,6 +1586,7 @@ function componentRender(nativeRenderer, component, from, context) {
1601
1586
  function createChainByJSXComponent(jsxNode, prevAtom, isSvg) {
1602
1587
  const atom = {
1603
1588
  type: 'component',
1589
+ index: prevAtom.index + 1,
1604
1590
  jsxNode,
1605
1591
  sibling: null,
1606
1592
  child: null,
@@ -1613,6 +1599,7 @@ function createChainByJSXComponent(jsxNode, prevAtom, isSvg) {
1613
1599
  function createChainByJSXText(jsxNode, prevAtom, isSvg) {
1614
1600
  const atom = {
1615
1601
  type: 'text',
1602
+ index: prevAtom.index + 1,
1616
1603
  jsxNode,
1617
1604
  sibling: null,
1618
1605
  child: null,
@@ -1626,6 +1613,7 @@ function createChainByJSXElement(element, prevAtom, isSvg) {
1626
1613
  isSvg = isSvg || element.type === 'svg';
1627
1614
  const atom = {
1628
1615
  type: 'element',
1616
+ index: prevAtom.index + 1,
1629
1617
  jsxNode: element,
1630
1618
  sibling: null,
1631
1619
  child: null,
@@ -1665,7 +1653,7 @@ function createChainByChildren(children, prevAtom, isSvg) {
1665
1653
  return prevAtom;
1666
1654
  }
1667
1655
  function createChildChain(template, isSvg) {
1668
- const beforeAtom = { sibling: null };
1656
+ const beforeAtom = { sibling: null, index: -1 };
1669
1657
  createChainByNode(template, beforeAtom, isSvg);
1670
1658
  return beforeAtom.sibling;
1671
1659
  }
@@ -1728,6 +1716,11 @@ function createTextNode(nativeRenderer, text, isSvg) {
1728
1716
  return nativeRenderer.createTextNode(text, isSvg);
1729
1717
  }
1730
1718
  function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNode, isSvg) {
1719
+ if (newVNode === oldVNode) {
1720
+ return () => {
1721
+ //
1722
+ };
1723
+ }
1731
1724
  const changes = getObjectChanges(newVNode.props, oldVNode.props);
1732
1725
  let unBindRefs;
1733
1726
  let bindRefs;
@@ -1886,7 +1879,7 @@ function viewfly(config) {
1886
1879
  return destroyed ? null : root;
1887
1880
  };
1888
1881
  }), function () {
1889
- if (destroyed) {
1882
+ if (destroyed || !autoUpdate) {
1890
1883
  return;
1891
1884
  }
1892
1885
  nextTick(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.10",
4
4
  "description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
5
5
  "main": "./bundles/index.js",
6
6
  "module": "./bundles/index.esm.js",
@@ -47,8 +47,8 @@
47
47
  "bugs": {
48
48
  "url": "https://github.com/viewfly/viewfly.git/issues"
49
49
  },
50
- "gitHead": "8a25e6e350ba9cade6036506e7fe2aba4e4396ac",
50
+ "gitHead": "2ffc5cb30c6509aa4a5c6b0c3fe228dacd7e08de",
51
51
  "dependencies": {
52
- "reflect-metadata": "^0.1.13"
52
+ "reflect-metadata": "^0.2.2"
53
53
  }
54
54
  }