@viewfly/core 1.0.0-alpha.14 → 1.0.0-alpha.16

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.
@@ -191,6 +191,22 @@ declare class ReflectiveInjector implements Injector {
191
191
 
192
192
  declare function makeError(name: string): (message: string) => Error;
193
193
 
194
+ interface Props {
195
+ children?: JSXNode | JSXNode[];
196
+ }
197
+ declare function Fragment(props: Props): () => any;
198
+ type Key = number | string;
199
+ declare function jsx(type: string | ComponentSetup, props: Props & Record<string, any>, key?: Key): ViewFlyNode;
200
+ declare const jsxs: typeof jsx;
201
+ interface ViewFlyNode<T = string | ComponentSetup> {
202
+ type: T;
203
+ props: Props & Record<string, any>;
204
+ key?: Key;
205
+ }
206
+ declare const JSXNodeFactory: {
207
+ createNode<T = string | ComponentSetup<any>>(type: T, props: Props & Record<string, any>, key?: Key): ViewFlyNode<T>;
208
+ };
209
+
194
210
  type NativeNode = Record<string, any>;
195
211
  declare abstract class NativeRenderer<ElementNode = NativeNode, TextNode = NativeNode> {
196
212
  abstract createElement(name: string, isSvg: boolean): ElementNode;
@@ -210,32 +226,52 @@ declare abstract class NativeRenderer<ElementNode = NativeNode, TextNode = Nativ
210
226
  abstract insertAfter(newNode: ElementNode | TextNode, ref: ElementNode | TextNode, isSvg: boolean): void;
211
227
  }
212
228
 
213
- interface Props {
214
- children?: JSXInternal.ViewNode | JSXInternal.ViewNode[];
215
- }
216
- declare function Fragment(props: Props): () => any;
217
- type Key = number | string;
218
- declare function jsx(type: string | JSXInternal.ComponentSetup, props: Props & Record<string, any>, key?: Key): JSXNode;
219
- declare const jsxs: typeof jsx;
220
- interface JSXNode<T = string | JSXInternal.ComponentSetup> {
221
- type: T;
222
- props: Props & Record<string, any>;
223
- key?: Key;
229
+ declare namespace JSX {
230
+ type Element<P = any> = IntrinsicElements[string] | ComponentSetup<P>;
231
+ interface IntrinsicAttributes {
232
+ key?: Key;
233
+ ref?: any;
234
+ }
235
+ interface RefAttributes<T> extends IntrinsicAttributes {
236
+ ref?: DynamicRef<ExtractInstanceType<T>> | DynamicRef<ExtractInstanceType<T>>[];
237
+ }
238
+ interface ElementClass<P = any> extends ComponentInstance<P> {
239
+ }
240
+ interface ElementChildrenAttribute {
241
+ }
242
+ interface IntrinsicElements {
243
+ [name: string]: any;
244
+ }
245
+ interface IntrinsicClassAttributes<T> {
246
+ ref?: DynamicRef<T>;
247
+ }
224
248
  }
225
- declare const JSXNodeFactory: {
226
- createNode<T = string | JSXInternal.ComponentSetup<any>>(type: T, props: Props & Record<string, any>, key?: Key): JSXNode<T>;
227
- };
228
249
 
250
+ type ClassNames = string | Record<string, unknown> | false | null | undefined | ClassNames[];
251
+ interface ComponentInstance<P> {
252
+ $portalHost?: NativeNode;
253
+ $render(): JSXNode;
254
+ $useMemo?(currentProps: P, prevProps: P): boolean;
255
+ }
256
+ type JSXNode = JSX.Element | JSX.ElementClass | string | number | boolean | null | undefined | Iterable<JSXNode>;
257
+ interface ComponentAnnotation {
258
+ scope?: Scope;
259
+ providers?: Provider[];
260
+ }
261
+ interface ComponentSetup<P = any> {
262
+ (props: P): (() => JSXNode) | ComponentInstance<P>;
263
+ annotation?: ComponentAnnotation;
264
+ }
229
265
  /**
230
266
  * Viewfly 组件管理类,用于管理组件的生命周期,上下文等
231
267
  */
232
268
  declare class Component extends ReflectiveInjector {
233
269
  private readonly parentComponent;
234
- readonly type: JSXInternal.ComponentSetup;
270
+ readonly type: ComponentSetup;
235
271
  props: Props;
236
272
  readonly key?: Key | undefined;
237
- instance: JSXInternal.ComponentInstance<Props>;
238
- template: JSXInternal.ViewNode;
273
+ instance: ComponentInstance<Props>;
274
+ template: JSXNode;
239
275
  changedSubComponents: Set<Component>;
240
276
  get dirty(): boolean;
241
277
  get changed(): boolean;
@@ -250,7 +286,7 @@ declare class Component extends ReflectiveInjector {
250
286
  private unWatch?;
251
287
  private isFirstRendering;
252
288
  private refs;
253
- constructor(parentComponent: Injector | null, type: JSXInternal.ComponentSetup, props: Props, key?: Key | undefined);
289
+ constructor(parentComponent: Injector | null, type: ComponentSetup, props: Props, key?: Key | undefined);
254
290
  markAsDirtied(): void;
255
291
  markAsChanged(changedComponent?: Component): void;
256
292
  render(): {
@@ -328,9 +364,9 @@ declare function onUnmounted(callback: () => void): void;
328
364
  interface RefListener<T> {
329
365
  (current: T): void | (() => void);
330
366
  }
331
- type ExtractInstanceType<T, U = T extends (...args: any) => any ? ReturnType<T> : T> = U extends JSXInternal.ComponentInstance<any> ? Omit<U, keyof JSXInternal.ComponentInstance<any>> : U extends Function ? never : T;
367
+ type ExtractInstanceType<T, U = T extends (...args: any) => any ? ReturnType<T> : T> = U extends ComponentInstance<any> ? Omit<U, keyof ComponentInstance<any>> : U extends Function ? never : T;
332
368
  interface AbstractInstanceType<T extends Record<string, any>> {
333
- (): T & JSXInternal.ComponentInstance<any>;
369
+ (): T & ComponentInstance<any>;
334
370
  }
335
371
  declare class DynamicRef<T> {
336
372
  private callback;
@@ -457,7 +493,7 @@ declare function watch<T = any>(deps: Signal<any>[], callback: WatchCallback<T[]
457
493
  * })
458
494
  * ```
459
495
  */
460
- declare function withAnnotation<T extends JSXInternal.ComponentSetup>(annotation: JSXInternal.ComponentAnnotation, componentSetup: T): T;
496
+ declare function withAnnotation<T extends ComponentSetup>(annotation: ComponentAnnotation, componentSetup: T): T;
461
497
  /**
462
498
  * 通过组件上下文获取 IoC 容器内数据的勾子方法
463
499
  */
@@ -467,7 +503,7 @@ declare function inject<T extends Type<any> | AbstractType<any> | InjectionToken
467
503
  */
468
504
  declare function getCurrentInstance(): Component;
469
505
 
470
- declare function withMemo<T extends Props = Props>(canUseMemo: JSXInternal.ComponentInstance<T>['$useMemo'], render: () => JSXInternal.ViewNode): JSXInternal.ComponentInstance<T>;
506
+ declare function withMemo<T extends Props = Props>(canUseMemo: ComponentInstance<T>['$useMemo'], render: () => JSXNode): ComponentInstance<T>;
471
507
 
472
508
  declare function createRenderer(component: Component, nativeRenderer: NativeRenderer): (host: NativeNode) => void;
473
509
 
@@ -476,49 +512,10 @@ declare function createRenderer(component: Component, nativeRenderer: NativeRend
476
512
  */
477
513
  declare class RootComponent extends Component {
478
514
  private refresh;
479
- constructor(parentInjector: Injector | null, factory: JSXInternal.ComponentSetup, refresh: () => void);
515
+ constructor(parentInjector: Injector | null, factory: ComponentSetup, refresh: () => void);
480
516
  markAsChanged(changedComponent?: Component): void;
481
517
  }
482
518
 
483
- type ViewNode = JSXInternal.ViewNode;
484
- declare global {
485
- namespace JSXInternal {
486
- type ClassNames = string | Record<string, unknown> | false | null | undefined | ClassNames[];
487
- interface ComponentInstance<P> {
488
- $portalHost?: NativeNode;
489
- $render(): ViewNode;
490
- $useMemo?(currentProps: P, prevProps: P): boolean;
491
- }
492
- type ViewNode = Element | JSXInternal.ElementClass | string | number | boolean | null | undefined | Iterable<ViewNode>;
493
- interface ComponentAnnotation {
494
- scope?: Scope;
495
- providers?: Provider[];
496
- }
497
- interface ComponentSetup<P = any> {
498
- (props: P): (() => ViewNode) | ComponentInstance<P>;
499
- annotation?: ComponentAnnotation;
500
- }
501
- type Element<P = any, C extends string | ComponentSetup<P> = string | ComponentSetup<P>> = C extends string ? IntrinsicElements[C] : (() => Element) | ComponentInstance<P>;
502
- interface IntrinsicAttributes {
503
- key?: Key;
504
- ref?: any;
505
- }
506
- interface RefAttributes<T> extends IntrinsicAttributes {
507
- ref?: DynamicRef<ExtractInstanceType<T>> | DynamicRef<ExtractInstanceType<T>>[];
508
- }
509
- interface ElementClass<P = any> extends ComponentInstance<P> {
510
- }
511
- interface ElementChildrenAttribute {
512
- }
513
- interface IntrinsicElements {
514
- [name: string]: any;
515
- }
516
- interface IntrinsicClassAttributes<T> {
517
- ref?: DynamicRef<T>;
518
- }
519
- }
520
- }
521
-
522
519
  declare const TextAtomType: unique symbol;
523
520
  declare const ElementAtomType: unique symbol;
524
521
  declare const ComponentAtomType: unique symbol;
@@ -530,30 +527,24 @@ interface TextAtom {
530
527
  child: Atom | null;
531
528
  sibling: Atom | null;
532
529
  isSvg: boolean;
533
- update: null | ((insertOffset: number) => void);
534
- next: Atom | null;
535
530
  }
536
531
  interface ElementAtom {
537
532
  type: typeof ElementAtomType;
538
533
  index: number;
539
- jsxNode: JSXNode<string>;
534
+ jsxNode: ViewFlyNode<string>;
540
535
  nativeNode: NativeNode | null;
541
536
  child: Atom | null;
542
537
  sibling: Atom | null;
543
538
  isSvg: boolean;
544
- update: null | ((insertOffset: number) => void);
545
- next: Atom | null;
546
539
  }
547
540
  interface ComponentAtom {
548
541
  type: typeof ComponentAtomType;
549
542
  index: number;
550
- jsxNode: JSXNode<JSXInternal.ComponentSetup> | Component;
543
+ jsxNode: ViewFlyNode<ComponentSetup> | Component;
551
544
  nativeNode: NativeNode | null;
552
545
  child: Atom | null;
553
546
  sibling: Atom | null;
554
547
  isSvg: boolean;
555
- update: null | ((insertOffset: number) => void);
556
- next: Atom | null;
557
548
  }
558
549
  type Atom = TextAtom | ElementAtom | ComponentAtom;
559
550
  interface ComponentView {
@@ -568,7 +559,7 @@ interface ComponentView {
568
559
  */
569
560
  interface Config {
570
561
  /** 根节点 */
571
- root: JSXInternal.ViewNode;
562
+ root: JSXNode;
572
563
  /** 平台渲染器 */
573
564
  nativeRenderer: NativeRenderer;
574
565
  /** 应用的上下文 */
@@ -590,4 +581,4 @@ interface Module {
590
581
  }
591
582
  declare function viewfly<T extends NativeNode>(config: Config): Application<T>;
592
583
 
593
- export { type AbstractInstanceType, type AbstractProvider, type AbstractType, type Application, type Atom, type ClassProvider, Component, type ComponentView, type Config, type ConstructorProvider, DynamicRef, type ExistingProvider, type ExtractInstanceType, type ExtractValueType, type FactoryProvider, ForwardRef, Fragment, Inject, type InjectDecorator, InjectFlags, Injectable, type InjectableDecorator, type InjectableOptions, InjectionToken, Injector, type JSXNode, JSXNodeFactory, type Key, type LifeCycleCallback, type Module, type NativeNode, NativeRenderer, type NormalizedProvider, NullInjector, Optional, type OptionalDecorator, Prop, type PropDecorator, type Props, type PropsChangedCallback, type ProvideScope, type Provider, type RefListener, type ReflectiveDependency, ReflectiveInjector, RootComponent, Scope, Self, type SelfDecorator, type Signal, SkipSelf, type SkipSelfDecorator, type StaticProvider, StaticRef, THROW_IF_NOT_FOUND, Type, type TypeProvider, type ValueProvider, type ViewNode, type WatchCallback, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withAnnotation, withMemo };
584
+ export { type AbstractInstanceType, type AbstractProvider, type AbstractType, type Application, type Atom, type ClassNames, type ClassProvider, Component, type ComponentAnnotation, type ComponentInstance, type ComponentSetup, type ComponentView, type Config, type ConstructorProvider, DynamicRef, type ExistingProvider, type ExtractInstanceType, type ExtractValueType, type FactoryProvider, ForwardRef, Fragment, Inject, type InjectDecorator, InjectFlags, Injectable, type InjectableDecorator, type InjectableOptions, InjectionToken, Injector, JSX, type JSXNode, JSXNodeFactory, type Key, type LifeCycleCallback, type Module, type NativeNode, NativeRenderer, type NormalizedProvider, NullInjector, Optional, type OptionalDecorator, Prop, type PropDecorator, type Props, type PropsChangedCallback, type ProvideScope, type Provider, type RefListener, type ReflectiveDependency, ReflectiveInjector, RootComponent, Scope, Self, type SelfDecorator, type Signal, SkipSelf, type SkipSelfDecorator, type StaticProvider, StaticRef, THROW_IF_NOT_FOUND, Type, type TypeProvider, type ValueProvider, type ViewFlyNode, type WatchCallback, createDerived, createDynamicRef, createRef, createRenderer, createSignal, forwardRef, getCurrentInstance, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, viewfly, watch, withAnnotation, withMemo };
@@ -1298,9 +1298,7 @@ function createRenderer(component, nativeRenderer) {
1298
1298
  sibling: null,
1299
1299
  child: null,
1300
1300
  nativeNode: null,
1301
- isSvg: false,
1302
- update: null,
1303
- next: null
1301
+ isSvg: false
1304
1302
  };
1305
1303
  componentRender(nativeRenderer, component, atom, {
1306
1304
  isParent: true,
@@ -1370,61 +1368,71 @@ function applyChanges(nativeRenderer, component) {
1370
1368
  }
1371
1369
  }
1372
1370
  function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1373
- let updateAtom = newAtom;
1374
- let insertOffset = 0;
1375
- let deleteOffset = 0;
1371
+ const commits = [];
1372
+ function changeOffset() {
1373
+ offset++;
1374
+ }
1375
+ while (newAtom) {
1376
+ oldAtom = createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, changeOffset);
1377
+ newAtom = newAtom.sibling;
1378
+ }
1379
+ let dirtyDiffAtom = oldAtom;
1380
+ while (dirtyDiffAtom) {
1381
+ cleanView(nativeRenderer, dirtyDiffAtom, true);
1382
+ dirtyDiffAtom = dirtyDiffAtom.sibling;
1383
+ }
1384
+ let offset = 0;
1385
+ for (let i = 0; i < commits.length; i++) {
1386
+ const commit = commits[i];
1387
+ while (oldAtom) {
1388
+ if (oldAtom.index <= i) {
1389
+ offset--;
1390
+ oldAtom = oldAtom.sibling;
1391
+ continue;
1392
+ }
1393
+ break;
1394
+ }
1395
+ commit(offset);
1396
+ }
1397
+ }
1398
+ function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
1399
+ const startDiffAtom = oldAtom;
1400
+ const { jsxNode: newJsxNode, type } = newAtom;
1401
+ const key = newJsxNode.key;
1402
+ let prev = null;
1376
1403
  while (oldAtom) {
1377
- const startDiffAtom = newAtom;
1378
- let prev = null;
1379
- let isUsed = false;
1380
- while (newAtom) {
1381
- const newAtomType = newAtom.type;
1382
- if (oldAtom.type === newAtomType) {
1383
- if (newAtomType === TextAtomType) {
1384
- newAtom.update = updateText(newAtom, oldAtom, nativeRenderer, context);
1385
- isUsed = true;
1404
+ if (type === oldAtom.type) {
1405
+ let commit;
1406
+ if (type === TextAtomType) {
1407
+ commit = updateText(newAtom, oldAtom, nativeRenderer, context);
1408
+ }
1409
+ else {
1410
+ const { key: diffKey, type: diffType } = oldAtom.jsxNode;
1411
+ if (diffKey !== key || newJsxNode.type !== diffType) {
1412
+ prev = oldAtom;
1413
+ oldAtom = oldAtom.sibling;
1414
+ continue;
1415
+ }
1416
+ if (type === ComponentAtomType) {
1417
+ commit = updateComponent(newAtom, oldAtom, nativeRenderer, context);
1386
1418
  }
1387
1419
  else {
1388
- const { key: newKey, type: newType } = newAtom.jsxNode;
1389
- const { key: oldKey, type: oldType } = oldAtom.jsxNode;
1390
- if (newType === oldType && newKey === oldKey) {
1391
- if (newAtomType === ComponentAtomType) {
1392
- newAtom.update = updateComponent(newAtom, oldAtom, deleteOffset, nativeRenderer, context);
1393
- }
1394
- else {
1395
- newAtom.update = updateElement(newAtom, oldAtom, deleteOffset, nativeRenderer, context, parentComponent);
1396
- }
1397
- isUsed = true;
1398
- }
1420
+ commit = updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent);
1399
1421
  }
1400
1422
  }
1401
- if (isUsed) {
1402
- const sibling = newAtom.next || newAtom.sibling;
1403
- if (prev) {
1404
- prev.next = sibling;
1405
- }
1406
- newAtom = newAtom === startDiffAtom ? sibling : startDiffAtom;
1407
- break;
1423
+ commits.push(commit);
1424
+ const next = oldAtom.sibling;
1425
+ if (!prev) {
1426
+ return next;
1408
1427
  }
1409
- prev = newAtom;
1410
- newAtom = newAtom.next || newAtom.sibling;
1411
- }
1412
- if (!isUsed) {
1413
- newAtom = startDiffAtom;
1414
- deleteOffset++;
1415
- cleanView(nativeRenderer, oldAtom, true);
1428
+ prev.sibling = next;
1429
+ return startDiffAtom;
1416
1430
  }
1431
+ prev = oldAtom;
1417
1432
  oldAtom = oldAtom.sibling;
1418
1433
  }
1419
- function changeOffset() {
1420
- insertOffset++;
1421
- }
1422
- while (updateAtom) {
1423
- const update = updateAtom.update || createNewView(updateAtom, nativeRenderer, context, parentComponent, changeOffset);
1424
- update(insertOffset);
1425
- updateAtom.next = updateAtom.update = null;
1426
- updateAtom = updateAtom.sibling;
1427
- }
1434
+ commits.push(createNewView(newAtom, nativeRenderer, context, parentComponent, effect));
1435
+ return startDiffAtom;
1428
1436
  }
1429
1437
  function createNewView(start, nativeRenderer, context, parentComponent, effect) {
1430
1438
  return function () {
@@ -1443,10 +1451,10 @@ function updateText(newAtom, oldAtom, nativeRenderer, context) {
1443
1451
  context.isParent = false;
1444
1452
  };
1445
1453
  }
1446
- function updateElement(newAtom, oldAtom, deleteOffset, nativeRenderer, context, parentComponent) {
1447
- return function (insertOffset) {
1454
+ function updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent) {
1455
+ return function (offset) {
1448
1456
  newAtom.nativeNode = oldAtom.nativeNode;
1449
- if (newAtom.index - insertOffset !== oldAtom.index - deleteOffset) {
1457
+ if (newAtom.index - offset !== oldAtom.index) {
1450
1458
  insertNode(nativeRenderer, newAtom, context);
1451
1459
  }
1452
1460
  context.host = newAtom.nativeNode;
@@ -1454,8 +1462,8 @@ function updateElement(newAtom, oldAtom, deleteOffset, nativeRenderer, context,
1454
1462
  updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComponent, context);
1455
1463
  };
1456
1464
  }
1457
- function updateComponent(newAtom, reusedAtom, deleteOffset, nativeRenderer, context) {
1458
- return function (insertOffset) {
1465
+ function updateComponent(newAtom, reusedAtom, nativeRenderer, context) {
1466
+ return function (offset) {
1459
1467
  const component = reusedAtom.jsxNode;
1460
1468
  const newProps = newAtom.jsxNode.props;
1461
1469
  const oldTemplate = component.template;
@@ -1465,7 +1473,7 @@ function updateComponent(newAtom, reusedAtom, deleteOffset, nativeRenderer, cont
1465
1473
  componentViewCache.set(component, Object.assign({ atom: newAtom }, context));
1466
1474
  newAtom.jsxNode = component;
1467
1475
  if (newTemplate === oldTemplate) {
1468
- reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, newAtom.index - insertOffset !== reusedAtom.index - deleteOffset);
1476
+ reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, newAtom.index - offset !== reusedAtom.index);
1469
1477
  updateView(nativeRenderer, component);
1470
1478
  return;
1471
1479
  }
@@ -1560,9 +1568,7 @@ function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
1560
1568
  sibling: null,
1561
1569
  child: null,
1562
1570
  nativeNode: null,
1563
- isSvg,
1564
- update: null,
1565
- next: null
1571
+ isSvg
1566
1572
  };
1567
1573
  prevAtom.sibling = atom;
1568
1574
  return atom;
package/bundles/index.js CHANGED
@@ -1300,9 +1300,7 @@ function createRenderer(component, nativeRenderer) {
1300
1300
  sibling: null,
1301
1301
  child: null,
1302
1302
  nativeNode: null,
1303
- isSvg: false,
1304
- update: null,
1305
- next: null
1303
+ isSvg: false
1306
1304
  };
1307
1305
  componentRender(nativeRenderer, component, atom, {
1308
1306
  isParent: true,
@@ -1372,61 +1370,71 @@ function applyChanges(nativeRenderer, component) {
1372
1370
  }
1373
1371
  }
1374
1372
  function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1375
- let updateAtom = newAtom;
1376
- let insertOffset = 0;
1377
- let deleteOffset = 0;
1373
+ const commits = [];
1374
+ function changeOffset() {
1375
+ offset++;
1376
+ }
1377
+ while (newAtom) {
1378
+ oldAtom = createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, changeOffset);
1379
+ newAtom = newAtom.sibling;
1380
+ }
1381
+ let dirtyDiffAtom = oldAtom;
1382
+ while (dirtyDiffAtom) {
1383
+ cleanView(nativeRenderer, dirtyDiffAtom, true);
1384
+ dirtyDiffAtom = dirtyDiffAtom.sibling;
1385
+ }
1386
+ let offset = 0;
1387
+ for (let i = 0; i < commits.length; i++) {
1388
+ const commit = commits[i];
1389
+ while (oldAtom) {
1390
+ if (oldAtom.index <= i) {
1391
+ offset--;
1392
+ oldAtom = oldAtom.sibling;
1393
+ continue;
1394
+ }
1395
+ break;
1396
+ }
1397
+ commit(offset);
1398
+ }
1399
+ }
1400
+ function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
1401
+ const startDiffAtom = oldAtom;
1402
+ const { jsxNode: newJsxNode, type } = newAtom;
1403
+ const key = newJsxNode.key;
1404
+ let prev = null;
1378
1405
  while (oldAtom) {
1379
- const startDiffAtom = newAtom;
1380
- let prev = null;
1381
- let isUsed = false;
1382
- while (newAtom) {
1383
- const newAtomType = newAtom.type;
1384
- if (oldAtom.type === newAtomType) {
1385
- if (newAtomType === TextAtomType) {
1386
- newAtom.update = updateText(newAtom, oldAtom, nativeRenderer, context);
1387
- isUsed = true;
1406
+ if (type === oldAtom.type) {
1407
+ let commit;
1408
+ if (type === TextAtomType) {
1409
+ commit = updateText(newAtom, oldAtom, nativeRenderer, context);
1410
+ }
1411
+ else {
1412
+ const { key: diffKey, type: diffType } = oldAtom.jsxNode;
1413
+ if (diffKey !== key || newJsxNode.type !== diffType) {
1414
+ prev = oldAtom;
1415
+ oldAtom = oldAtom.sibling;
1416
+ continue;
1417
+ }
1418
+ if (type === ComponentAtomType) {
1419
+ commit = updateComponent(newAtom, oldAtom, nativeRenderer, context);
1388
1420
  }
1389
1421
  else {
1390
- const { key: newKey, type: newType } = newAtom.jsxNode;
1391
- const { key: oldKey, type: oldType } = oldAtom.jsxNode;
1392
- if (newType === oldType && newKey === oldKey) {
1393
- if (newAtomType === ComponentAtomType) {
1394
- newAtom.update = updateComponent(newAtom, oldAtom, deleteOffset, nativeRenderer, context);
1395
- }
1396
- else {
1397
- newAtom.update = updateElement(newAtom, oldAtom, deleteOffset, nativeRenderer, context, parentComponent);
1398
- }
1399
- isUsed = true;
1400
- }
1422
+ commit = updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent);
1401
1423
  }
1402
1424
  }
1403
- if (isUsed) {
1404
- const sibling = newAtom.next || newAtom.sibling;
1405
- if (prev) {
1406
- prev.next = sibling;
1407
- }
1408
- newAtom = newAtom === startDiffAtom ? sibling : startDiffAtom;
1409
- break;
1425
+ commits.push(commit);
1426
+ const next = oldAtom.sibling;
1427
+ if (!prev) {
1428
+ return next;
1410
1429
  }
1411
- prev = newAtom;
1412
- newAtom = newAtom.next || newAtom.sibling;
1413
- }
1414
- if (!isUsed) {
1415
- newAtom = startDiffAtom;
1416
- deleteOffset++;
1417
- cleanView(nativeRenderer, oldAtom, true);
1430
+ prev.sibling = next;
1431
+ return startDiffAtom;
1418
1432
  }
1433
+ prev = oldAtom;
1419
1434
  oldAtom = oldAtom.sibling;
1420
1435
  }
1421
- function changeOffset() {
1422
- insertOffset++;
1423
- }
1424
- while (updateAtom) {
1425
- const update = updateAtom.update || createNewView(updateAtom, nativeRenderer, context, parentComponent, changeOffset);
1426
- update(insertOffset);
1427
- updateAtom.next = updateAtom.update = null;
1428
- updateAtom = updateAtom.sibling;
1429
- }
1436
+ commits.push(createNewView(newAtom, nativeRenderer, context, parentComponent, effect));
1437
+ return startDiffAtom;
1430
1438
  }
1431
1439
  function createNewView(start, nativeRenderer, context, parentComponent, effect) {
1432
1440
  return function () {
@@ -1445,10 +1453,10 @@ function updateText(newAtom, oldAtom, nativeRenderer, context) {
1445
1453
  context.isParent = false;
1446
1454
  };
1447
1455
  }
1448
- function updateElement(newAtom, oldAtom, deleteOffset, nativeRenderer, context, parentComponent) {
1449
- return function (insertOffset) {
1456
+ function updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent) {
1457
+ return function (offset) {
1450
1458
  newAtom.nativeNode = oldAtom.nativeNode;
1451
- if (newAtom.index - insertOffset !== oldAtom.index - deleteOffset) {
1459
+ if (newAtom.index - offset !== oldAtom.index) {
1452
1460
  insertNode(nativeRenderer, newAtom, context);
1453
1461
  }
1454
1462
  context.host = newAtom.nativeNode;
@@ -1456,8 +1464,8 @@ function updateElement(newAtom, oldAtom, deleteOffset, nativeRenderer, context,
1456
1464
  updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComponent, context);
1457
1465
  };
1458
1466
  }
1459
- function updateComponent(newAtom, reusedAtom, deleteOffset, nativeRenderer, context) {
1460
- return function (insertOffset) {
1467
+ function updateComponent(newAtom, reusedAtom, nativeRenderer, context) {
1468
+ return function (offset) {
1461
1469
  const component = reusedAtom.jsxNode;
1462
1470
  const newProps = newAtom.jsxNode.props;
1463
1471
  const oldTemplate = component.template;
@@ -1467,7 +1475,7 @@ function updateComponent(newAtom, reusedAtom, deleteOffset, nativeRenderer, cont
1467
1475
  componentViewCache.set(component, Object.assign({ atom: newAtom }, context));
1468
1476
  newAtom.jsxNode = component;
1469
1477
  if (newTemplate === oldTemplate) {
1470
- reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, newAtom.index - insertOffset !== reusedAtom.index - deleteOffset);
1478
+ reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, newAtom.index - offset !== reusedAtom.index);
1471
1479
  updateView(nativeRenderer, component);
1472
1480
  return;
1473
1481
  }
@@ -1562,9 +1570,7 @@ function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
1562
1570
  sibling: null,
1563
1571
  child: null,
1564
1572
  nativeNode: null,
1565
- isSvg,
1566
- update: null,
1567
- next: null
1573
+ isSvg
1568
1574
  };
1569
1575
  prevAtom.sibling = atom;
1570
1576
  return atom;
@@ -1,4 +1,4 @@
1
- import { jsx, jsxs, Fragment } from '@viewfly/core';
1
+ import { jsx, jsxs, Fragment, JSX as ViewflyJSX } from '@viewfly/core';
2
2
  /**
3
3
  * JSX namespace for usage with @jsxImportsSource directive
4
4
  * when ts compilerOptions.jsx is 'react-jsx'
@@ -7,15 +7,15 @@ import { jsx, jsxs, Fragment } from '@viewfly/core';
7
7
  declare const jsxDEV: typeof jsx;
8
8
  export { jsx, jsxs, Fragment, jsxDEV };
9
9
  export declare namespace JSX {
10
- type Element = JSXInternal.Element;
11
- interface ElementClass extends JSXInternal.ElementClass {
10
+ type Element = ViewflyJSX.Element;
11
+ interface ElementClass extends ViewflyJSX.ElementClass {
12
12
  }
13
- interface IntrinsicElements extends JSXInternal.IntrinsicElements {
13
+ interface IntrinsicElements extends ViewflyJSX.IntrinsicElements {
14
14
  }
15
- interface IntrinsicAttributes extends JSXInternal.IntrinsicAttributes {
15
+ interface IntrinsicAttributes extends ViewflyJSX.IntrinsicAttributes {
16
16
  }
17
- interface ElementChildrenAttribute extends JSXInternal.ElementChildrenAttribute {
17
+ interface ElementChildrenAttribute extends ViewflyJSX.ElementChildrenAttribute {
18
18
  }
19
- interface IntrinsicClassAttributes<T> extends JSXInternal.IntrinsicClassAttributes<T> {
19
+ interface IntrinsicClassAttributes<T> extends ViewflyJSX.IntrinsicClassAttributes<T> {
20
20
  }
21
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "1.0.0-alpha.14",
3
+ "version": "1.0.0-alpha.16",
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",
@@ -50,7 +50,7 @@
50
50
  "bugs": {
51
51
  "url": "https://github.com/viewfly/viewfly.git/issues"
52
52
  },
53
- "gitHead": "48779d88f1390751bbd06e4c4581bf3dbe613a26",
53
+ "gitHead": "d2c8ce1c906fd80e05e27d677e7f678ccae0e9a1",
54
54
  "dependencies": {
55
55
  "reflect-metadata": "^0.2.2"
56
56
  }