@viewfly/core 1.0.0-alpha.4 → 1.0.0-alpha.6

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.
@@ -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;
@@ -4,14 +4,14 @@ export interface Props {
4
4
  }
5
5
  export declare function Fragment(props: Props): () => any;
6
6
  export type Key = number | string;
7
- 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;
8
8
  export declare const jsxs: typeof jsx;
9
9
  export interface JSXNode<T = string | JSXInternal.ComponentSetup> {
10
10
  type: T;
11
- props: Props;
11
+ props: Props & Record<string, any>;
12
12
  key?: Key;
13
13
  on?: Record<string, ListenDelegate>;
14
14
  }
15
15
  export declare const JSXNodeFactory: {
16
- 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>;
17
17
  };
@@ -1289,6 +1289,7 @@ function createRenderer(component, nativeRenderer) {
1289
1289
  isInit = false;
1290
1290
  const atom = {
1291
1291
  type: 'component',
1292
+ index: 0,
1292
1293
  jsxNode: component,
1293
1294
  sibling: null,
1294
1295
  child: null,
@@ -1367,58 +1368,34 @@ function applyChanges(nativeRenderer, component) {
1367
1368
  isParent,
1368
1369
  rootHost
1369
1370
  };
1370
- diff(nativeRenderer, component, atom.child, diffAtom, context, 0, 0);
1371
+ diff(nativeRenderer, component, atom.child, diffAtom, context);
1371
1372
  const next = atom.sibling;
1372
1373
  if (next && next.jsxNode instanceof Component) {
1373
1374
  next.jsxNode.$$view.host = context.host;
1374
1375
  next.jsxNode.$$view.isParent = context.isParent;
1375
1376
  }
1376
1377
  }
1377
- function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expectIndex, index) {
1378
- let prevDiffAtom = null;
1379
- let firstDiffAtomIndexed = null;
1380
- if (oldAtom) {
1381
- prevDiffAtom = {
1382
- index,
1383
- atom: oldAtom,
1384
- prev: null
1385
- };
1386
- index++;
1387
- firstDiffAtomIndexed = prevDiffAtom;
1388
- oldAtom = oldAtom.sibling;
1389
- while (oldAtom) {
1390
- const diffAtom = {
1391
- index,
1392
- atom: oldAtom,
1393
- prev: prevDiffAtom
1394
- };
1395
- prevDiffAtom.next = diffAtom;
1396
- prevDiffAtom = diffAtom;
1397
- oldAtom = oldAtom.sibling;
1398
- index++;
1399
- }
1400
- }
1378
+ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1401
1379
  const commits = [];
1402
1380
  function changeOffset() {
1403
1381
  offset++;
1404
1382
  }
1405
1383
  while (newAtom) {
1406
- firstDiffAtomIndexed = createChanges(newAtom, expectIndex, firstDiffAtomIndexed, nativeRenderer, commits, context, parentComponent, changeOffset);
1384
+ oldAtom = createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, changeOffset);
1407
1385
  newAtom = newAtom.sibling;
1408
- expectIndex++;
1409
1386
  }
1410
- let dirtyDiffAtom = firstDiffAtomIndexed;
1387
+ let dirtyDiffAtom = oldAtom;
1411
1388
  while (dirtyDiffAtom) {
1412
- cleanView(nativeRenderer, dirtyDiffAtom.atom, false);
1413
- dirtyDiffAtom = dirtyDiffAtom.next;
1389
+ cleanView(nativeRenderer, dirtyDiffAtom, false);
1390
+ dirtyDiffAtom = dirtyDiffAtom.sibling;
1414
1391
  }
1415
1392
  let offset = 0;
1416
1393
  for (let i = 0; i < commits.length; i++) {
1417
1394
  const commit = commits[i];
1418
- while (firstDiffAtomIndexed) {
1419
- if (firstDiffAtomIndexed.index <= i) {
1395
+ while (oldAtom) {
1396
+ if (oldAtom.index <= i) {
1420
1397
  offset--;
1421
- firstDiffAtomIndexed = firstDiffAtomIndexed.next;
1398
+ oldAtom = oldAtom.sibling;
1422
1399
  continue;
1423
1400
  }
1424
1401
  break;
@@ -1426,47 +1403,42 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1426
1403
  commit(offset);
1427
1404
  }
1428
1405
  }
1429
- function createChanges(newAtom, expectIndex, diffAtomIndexed, nativeRenderer, commits, context, parentComponent, effect) {
1430
- const startDiffAtom = diffAtomIndexed;
1406
+ function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
1407
+ const startDiffAtom = oldAtom;
1431
1408
  const { jsxNode: newJsxNode, type } = newAtom;
1432
1409
  const key = newJsxNode.key;
1433
- while (diffAtomIndexed) {
1434
- const { atom: diffAtom, index: diffIndex } = diffAtomIndexed;
1435
- if (type === diffAtom.type) {
1410
+ let prev = null;
1411
+ while (oldAtom) {
1412
+ const diffIndex = oldAtom.index;
1413
+ if (type === oldAtom.type) {
1436
1414
  let commit;
1437
1415
  if (type === 'text') {
1438
- commit = updateText(newAtom, diffAtom, nativeRenderer, context);
1416
+ commit = updateText(newAtom, oldAtom, nativeRenderer, context);
1439
1417
  }
1440
1418
  else {
1441
- const { key: diffKey, type: diffType } = diffAtom.jsxNode;
1419
+ const { key: diffKey, type: diffType } = oldAtom.jsxNode;
1442
1420
  if (diffKey !== key || newJsxNode.type !== diffType) {
1443
- diffAtomIndexed = diffAtomIndexed.next;
1421
+ prev = oldAtom;
1422
+ oldAtom = oldAtom.sibling;
1444
1423
  continue;
1445
1424
  }
1446
1425
  if (type === 'component') {
1447
- commit = updateComponent(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context);
1426
+ commit = updateComponent(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context);
1448
1427
  }
1449
1428
  else {
1450
- commit = updateElement(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context, parentComponent);
1429
+ commit = updateElement(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context, parentComponent);
1451
1430
  }
1452
1431
  }
1453
1432
  commits.push(commit);
1454
- const next = diffAtomIndexed.next;
1455
- const prev = diffAtomIndexed.prev;
1433
+ const next = oldAtom.sibling;
1456
1434
  if (!prev) {
1457
- diffAtomIndexed = next;
1458
- if (diffAtomIndexed) {
1459
- diffAtomIndexed.prev = null;
1460
- }
1461
- return diffAtomIndexed;
1462
- }
1463
- prev.next = next;
1464
- if (next) {
1465
- next.prev = prev;
1435
+ return next;
1466
1436
  }
1437
+ prev.sibling = next;
1467
1438
  return startDiffAtom;
1468
1439
  }
1469
- diffAtomIndexed = diffAtomIndexed.next;
1440
+ prev = oldAtom;
1441
+ oldAtom = oldAtom.sibling;
1470
1442
  }
1471
1443
  commits.push(createNewView(newAtom, nativeRenderer, context, parentComponent, effect));
1472
1444
  return startDiffAtom;
@@ -1502,7 +1474,7 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
1502
1474
  host: newAtom.nativeNode,
1503
1475
  isParent: true,
1504
1476
  rootHost: context.rootHost
1505
- }, 0, 0);
1477
+ });
1506
1478
  }
1507
1479
  else if (oldAtom.child) {
1508
1480
  let atom = oldAtom.child;
@@ -1534,7 +1506,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
1534
1506
  newAtom.child = createChildChain(newTemplate, newAtom.isSvg);
1535
1507
  }
1536
1508
  if (newAtom.child) {
1537
- diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex + offset);
1509
+ diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context);
1538
1510
  }
1539
1511
  else if (reusedAtom.child) {
1540
1512
  let atom = reusedAtom.child;
@@ -1608,6 +1580,7 @@ function componentRender(nativeRenderer, component, from, context) {
1608
1580
  function createChainByJSXComponent(jsxNode, prevAtom, isSvg) {
1609
1581
  const atom = {
1610
1582
  type: 'component',
1583
+ index: prevAtom.index + 1,
1611
1584
  jsxNode,
1612
1585
  sibling: null,
1613
1586
  child: null,
@@ -1620,6 +1593,7 @@ function createChainByJSXComponent(jsxNode, prevAtom, isSvg) {
1620
1593
  function createChainByJSXText(jsxNode, prevAtom, isSvg) {
1621
1594
  const atom = {
1622
1595
  type: 'text',
1596
+ index: prevAtom.index + 1,
1623
1597
  jsxNode,
1624
1598
  sibling: null,
1625
1599
  child: null,
@@ -1633,6 +1607,7 @@ function createChainByJSXElement(element, prevAtom, isSvg) {
1633
1607
  isSvg = isSvg || element.type === 'svg';
1634
1608
  const atom = {
1635
1609
  type: 'element',
1610
+ index: prevAtom.index + 1,
1636
1611
  jsxNode: element,
1637
1612
  sibling: null,
1638
1613
  child: null,
@@ -1672,7 +1647,7 @@ function createChainByChildren(children, prevAtom, isSvg) {
1672
1647
  return prevAtom;
1673
1648
  }
1674
1649
  function createChildChain(template, isSvg) {
1675
- const beforeAtom = { sibling: null };
1650
+ const beforeAtom = { sibling: null, index: -1 };
1676
1651
  createChainByNode(template, beforeAtom, isSvg);
1677
1652
  return beforeAtom.sibling;
1678
1653
  }
package/bundles/index.js CHANGED
@@ -1291,6 +1291,7 @@ function createRenderer(component, nativeRenderer) {
1291
1291
  isInit = false;
1292
1292
  const atom = {
1293
1293
  type: 'component',
1294
+ index: 0,
1294
1295
  jsxNode: component,
1295
1296
  sibling: null,
1296
1297
  child: null,
@@ -1369,58 +1370,34 @@ function applyChanges(nativeRenderer, component) {
1369
1370
  isParent,
1370
1371
  rootHost
1371
1372
  };
1372
- diff(nativeRenderer, component, atom.child, diffAtom, context, 0, 0);
1373
+ diff(nativeRenderer, component, atom.child, diffAtom, context);
1373
1374
  const next = atom.sibling;
1374
1375
  if (next && next.jsxNode instanceof Component) {
1375
1376
  next.jsxNode.$$view.host = context.host;
1376
1377
  next.jsxNode.$$view.isParent = context.isParent;
1377
1378
  }
1378
1379
  }
1379
- function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expectIndex, index) {
1380
- let prevDiffAtom = null;
1381
- let firstDiffAtomIndexed = null;
1382
- if (oldAtom) {
1383
- prevDiffAtom = {
1384
- index,
1385
- atom: oldAtom,
1386
- prev: null
1387
- };
1388
- index++;
1389
- firstDiffAtomIndexed = prevDiffAtom;
1390
- oldAtom = oldAtom.sibling;
1391
- while (oldAtom) {
1392
- const diffAtom = {
1393
- index,
1394
- atom: oldAtom,
1395
- prev: prevDiffAtom
1396
- };
1397
- prevDiffAtom.next = diffAtom;
1398
- prevDiffAtom = diffAtom;
1399
- oldAtom = oldAtom.sibling;
1400
- index++;
1401
- }
1402
- }
1380
+ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1403
1381
  const commits = [];
1404
1382
  function changeOffset() {
1405
1383
  offset++;
1406
1384
  }
1407
1385
  while (newAtom) {
1408
- firstDiffAtomIndexed = createChanges(newAtom, expectIndex, firstDiffAtomIndexed, nativeRenderer, commits, context, parentComponent, changeOffset);
1386
+ oldAtom = createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, changeOffset);
1409
1387
  newAtom = newAtom.sibling;
1410
- expectIndex++;
1411
1388
  }
1412
- let dirtyDiffAtom = firstDiffAtomIndexed;
1389
+ let dirtyDiffAtom = oldAtom;
1413
1390
  while (dirtyDiffAtom) {
1414
- cleanView(nativeRenderer, dirtyDiffAtom.atom, false);
1415
- dirtyDiffAtom = dirtyDiffAtom.next;
1391
+ cleanView(nativeRenderer, dirtyDiffAtom, false);
1392
+ dirtyDiffAtom = dirtyDiffAtom.sibling;
1416
1393
  }
1417
1394
  let offset = 0;
1418
1395
  for (let i = 0; i < commits.length; i++) {
1419
1396
  const commit = commits[i];
1420
- while (firstDiffAtomIndexed) {
1421
- if (firstDiffAtomIndexed.index <= i) {
1397
+ while (oldAtom) {
1398
+ if (oldAtom.index <= i) {
1422
1399
  offset--;
1423
- firstDiffAtomIndexed = firstDiffAtomIndexed.next;
1400
+ oldAtom = oldAtom.sibling;
1424
1401
  continue;
1425
1402
  }
1426
1403
  break;
@@ -1428,47 +1405,42 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1428
1405
  commit(offset);
1429
1406
  }
1430
1407
  }
1431
- function createChanges(newAtom, expectIndex, diffAtomIndexed, nativeRenderer, commits, context, parentComponent, effect) {
1432
- const startDiffAtom = diffAtomIndexed;
1408
+ function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
1409
+ const startDiffAtom = oldAtom;
1433
1410
  const { jsxNode: newJsxNode, type } = newAtom;
1434
1411
  const key = newJsxNode.key;
1435
- while (diffAtomIndexed) {
1436
- const { atom: diffAtom, index: diffIndex } = diffAtomIndexed;
1437
- if (type === diffAtom.type) {
1412
+ let prev = null;
1413
+ while (oldAtom) {
1414
+ const diffIndex = oldAtom.index;
1415
+ if (type === oldAtom.type) {
1438
1416
  let commit;
1439
1417
  if (type === 'text') {
1440
- commit = updateText(newAtom, diffAtom, nativeRenderer, context);
1418
+ commit = updateText(newAtom, oldAtom, nativeRenderer, context);
1441
1419
  }
1442
1420
  else {
1443
- const { key: diffKey, type: diffType } = diffAtom.jsxNode;
1421
+ const { key: diffKey, type: diffType } = oldAtom.jsxNode;
1444
1422
  if (diffKey !== key || newJsxNode.type !== diffType) {
1445
- diffAtomIndexed = diffAtomIndexed.next;
1423
+ prev = oldAtom;
1424
+ oldAtom = oldAtom.sibling;
1446
1425
  continue;
1447
1426
  }
1448
1427
  if (type === 'component') {
1449
- commit = updateComponent(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context);
1428
+ commit = updateComponent(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context);
1450
1429
  }
1451
1430
  else {
1452
- commit = updateElement(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context, parentComponent);
1431
+ commit = updateElement(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context, parentComponent);
1453
1432
  }
1454
1433
  }
1455
1434
  commits.push(commit);
1456
- const next = diffAtomIndexed.next;
1457
- const prev = diffAtomIndexed.prev;
1435
+ const next = oldAtom.sibling;
1458
1436
  if (!prev) {
1459
- diffAtomIndexed = next;
1460
- if (diffAtomIndexed) {
1461
- diffAtomIndexed.prev = null;
1462
- }
1463
- return diffAtomIndexed;
1464
- }
1465
- prev.next = next;
1466
- if (next) {
1467
- next.prev = prev;
1437
+ return next;
1468
1438
  }
1439
+ prev.sibling = next;
1469
1440
  return startDiffAtom;
1470
1441
  }
1471
- diffAtomIndexed = diffAtomIndexed.next;
1442
+ prev = oldAtom;
1443
+ oldAtom = oldAtom.sibling;
1472
1444
  }
1473
1445
  commits.push(createNewView(newAtom, nativeRenderer, context, parentComponent, effect));
1474
1446
  return startDiffAtom;
@@ -1504,7 +1476,7 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
1504
1476
  host: newAtom.nativeNode,
1505
1477
  isParent: true,
1506
1478
  rootHost: context.rootHost
1507
- }, 0, 0);
1479
+ });
1508
1480
  }
1509
1481
  else if (oldAtom.child) {
1510
1482
  let atom = oldAtom.child;
@@ -1536,7 +1508,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
1536
1508
  newAtom.child = createChildChain(newTemplate, newAtom.isSvg);
1537
1509
  }
1538
1510
  if (newAtom.child) {
1539
- diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex + offset);
1511
+ diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context);
1540
1512
  }
1541
1513
  else if (reusedAtom.child) {
1542
1514
  let atom = reusedAtom.child;
@@ -1610,6 +1582,7 @@ function componentRender(nativeRenderer, component, from, context) {
1610
1582
  function createChainByJSXComponent(jsxNode, prevAtom, isSvg) {
1611
1583
  const atom = {
1612
1584
  type: 'component',
1585
+ index: prevAtom.index + 1,
1613
1586
  jsxNode,
1614
1587
  sibling: null,
1615
1588
  child: null,
@@ -1622,6 +1595,7 @@ function createChainByJSXComponent(jsxNode, prevAtom, isSvg) {
1622
1595
  function createChainByJSXText(jsxNode, prevAtom, isSvg) {
1623
1596
  const atom = {
1624
1597
  type: 'text',
1598
+ index: prevAtom.index + 1,
1625
1599
  jsxNode,
1626
1600
  sibling: null,
1627
1601
  child: null,
@@ -1635,6 +1609,7 @@ function createChainByJSXElement(element, prevAtom, isSvg) {
1635
1609
  isSvg = isSvg || element.type === 'svg';
1636
1610
  const atom = {
1637
1611
  type: 'element',
1612
+ index: prevAtom.index + 1,
1638
1613
  jsxNode: element,
1639
1614
  sibling: null,
1640
1615
  child: null,
@@ -1674,7 +1649,7 @@ function createChainByChildren(children, prevAtom, isSvg) {
1674
1649
  return prevAtom;
1675
1650
  }
1676
1651
  function createChildChain(template, isSvg) {
1677
- const beforeAtom = { sibling: null };
1652
+ const beforeAtom = { sibling: null, index: -1 };
1678
1653
  createChainByNode(template, beforeAtom, isSvg);
1679
1654
  return beforeAtom.sibling;
1680
1655
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "1.0.0-alpha.4",
3
+ "version": "1.0.0-alpha.6",
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": "176e9fdb7415d029541a1da102001d9bab6c3319",
50
+ "gitHead": "f92d3c923b1b9f115b928bc57f4d8adf1f8100c9",
51
51
  "dependencies": {
52
- "reflect-metadata": "^0.1.13"
52
+ "reflect-metadata": "^0.2.2"
53
53
  }
54
54
  }