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

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.
@@ -523,6 +523,8 @@ interface TextAtom {
523
523
  type: typeof TextAtomType;
524
524
  index: number;
525
525
  jsxNode: string;
526
+ nodeType: string;
527
+ key?: null;
526
528
  nativeNode: NativeNode | null;
527
529
  child: Atom | null;
528
530
  sibling: Atom | null;
@@ -531,6 +533,8 @@ interface TextAtom {
531
533
  interface ElementAtom {
532
534
  type: typeof ElementAtomType;
533
535
  index: number;
536
+ nodeType: string;
537
+ key?: Key;
534
538
  jsxNode: ViewFlyNode<string>;
535
539
  nativeNode: NativeNode | null;
536
540
  child: Atom | null;
@@ -540,6 +544,8 @@ interface ElementAtom {
540
544
  interface ComponentAtom {
541
545
  type: typeof ComponentAtomType;
542
546
  index: number;
547
+ nodeType: ComponentSetup;
548
+ key?: Key;
543
549
  jsxNode: ViewFlyNode<ComponentSetup> | Component;
544
550
  nativeNode: NativeNode | null;
545
551
  child: Atom | null;
@@ -1294,6 +1294,7 @@ function createRenderer(component, nativeRenderer) {
1294
1294
  const atom = {
1295
1295
  type: ComponentAtomType,
1296
1296
  index: 0,
1297
+ nodeType: component.type,
1297
1298
  jsxNode: component,
1298
1299
  sibling: null,
1299
1300
  child: null,
@@ -1397,28 +1398,19 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1397
1398
  }
1398
1399
  function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
1399
1400
  const startDiffAtom = oldAtom;
1400
- const { jsxNode: newJsxNode, type } = newAtom;
1401
- const key = newJsxNode.key;
1402
1401
  let prev = null;
1403
1402
  while (oldAtom) {
1404
- if (type === oldAtom.type) {
1403
+ const newAtomType = newAtom.type;
1404
+ if (oldAtom.type === newAtomType && oldAtom.nodeType === newAtom.nodeType && oldAtom.key === newAtom.key) {
1405
1405
  let commit;
1406
- if (type === TextAtomType) {
1406
+ if (newAtomType === TextAtomType) {
1407
1407
  commit = updateText(newAtom, oldAtom, nativeRenderer, context);
1408
1408
  }
1409
+ else if (newAtomType === ComponentAtomType) {
1410
+ commit = updateComponent(newAtom, oldAtom, nativeRenderer, context);
1411
+ }
1409
1412
  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);
1418
- }
1419
- else {
1420
- commit = updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent);
1421
- }
1413
+ commit = updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent);
1422
1414
  }
1423
1415
  commits.push(commit);
1424
1416
  const next = oldAtom.sibling;
@@ -1441,12 +1433,12 @@ function createNewView(start, nativeRenderer, context, parentComponent, effect)
1441
1433
  };
1442
1434
  }
1443
1435
  function updateText(newAtom, oldAtom, nativeRenderer, context) {
1444
- return function () {
1436
+ return function (offset) {
1445
1437
  const nativeNode = oldAtom.nativeNode;
1446
- if (newAtom.jsxNode !== oldAtom.jsxNode) {
1447
- nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode, newAtom.isSvg);
1448
- }
1449
1438
  newAtom.nativeNode = nativeNode;
1439
+ if (newAtom.index - offset !== oldAtom.index) {
1440
+ insertNode(nativeRenderer, newAtom, context);
1441
+ }
1450
1442
  context.host = nativeNode;
1451
1443
  context.isParent = false;
1452
1444
  };
@@ -1560,7 +1552,7 @@ function componentRender(nativeRenderer, component, from, context) {
1560
1552
  }
1561
1553
  component.rendered();
1562
1554
  }
1563
- function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
1555
+ function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, isSvg, key) {
1564
1556
  const atom = {
1565
1557
  type,
1566
1558
  index: prevAtom.index + 1,
@@ -1568,7 +1560,9 @@ function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
1568
1560
  sibling: null,
1569
1561
  child: null,
1570
1562
  nativeNode: null,
1571
- isSvg
1563
+ isSvg,
1564
+ nodeType,
1565
+ key
1572
1566
  };
1573
1567
  prevAtom.sibling = atom;
1574
1568
  return atom;
@@ -1577,7 +1571,7 @@ function createChainByNode(jsxNode, prevAtom, isSvg) {
1577
1571
  const type = typeof jsxNode;
1578
1572
  if (jsxNode !== null && type !== 'undefined' && type !== 'boolean') {
1579
1573
  if (typeof jsxNode === 'string') {
1580
- return createChainByJSXNode(TextAtomType, jsxNode, prevAtom, isSvg);
1574
+ return createChainByJSXNode(TextAtomType, jsxNode, jsxNode, prevAtom, isSvg);
1581
1575
  }
1582
1576
  if (Array.isArray(jsxNode)) {
1583
1577
  return createChainByChildren(jsxNode, prevAtom, isSvg);
@@ -1585,13 +1579,14 @@ function createChainByNode(jsxNode, prevAtom, isSvg) {
1585
1579
  if (type === 'object') {
1586
1580
  const nodeType = typeof jsxNode.type;
1587
1581
  if (nodeType === 'string') {
1588
- return createChainByJSXNode(ElementAtomType, jsxNode, prevAtom, isSvg || jsxNode.type === 'svg');
1582
+ return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, isSvg || jsxNode.type === 'svg', jsxNode.key);
1589
1583
  }
1590
1584
  else if (nodeType === 'function') {
1591
- return createChainByJSXNode(ComponentAtomType, jsxNode, prevAtom, isSvg);
1585
+ return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, isSvg, jsxNode.key);
1592
1586
  }
1593
1587
  }
1594
- return createChainByJSXNode(TextAtomType, String(jsxNode), prevAtom, isSvg);
1588
+ const text = String(jsxNode);
1589
+ return createChainByJSXNode(TextAtomType, text, text, prevAtom, isSvg);
1595
1590
  }
1596
1591
  return prevAtom;
1597
1592
  }
package/bundles/index.js CHANGED
@@ -1296,6 +1296,7 @@ function createRenderer(component, nativeRenderer) {
1296
1296
  const atom = {
1297
1297
  type: ComponentAtomType,
1298
1298
  index: 0,
1299
+ nodeType: component.type,
1299
1300
  jsxNode: component,
1300
1301
  sibling: null,
1301
1302
  child: null,
@@ -1399,28 +1400,19 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1399
1400
  }
1400
1401
  function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
1401
1402
  const startDiffAtom = oldAtom;
1402
- const { jsxNode: newJsxNode, type } = newAtom;
1403
- const key = newJsxNode.key;
1404
1403
  let prev = null;
1405
1404
  while (oldAtom) {
1406
- if (type === oldAtom.type) {
1405
+ const newAtomType = newAtom.type;
1406
+ if (oldAtom.type === newAtomType && oldAtom.nodeType === newAtom.nodeType && oldAtom.key === newAtom.key) {
1407
1407
  let commit;
1408
- if (type === TextAtomType) {
1408
+ if (newAtomType === TextAtomType) {
1409
1409
  commit = updateText(newAtom, oldAtom, nativeRenderer, context);
1410
1410
  }
1411
+ else if (newAtomType === ComponentAtomType) {
1412
+ commit = updateComponent(newAtom, oldAtom, nativeRenderer, context);
1413
+ }
1411
1414
  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);
1420
- }
1421
- else {
1422
- commit = updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent);
1423
- }
1415
+ commit = updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent);
1424
1416
  }
1425
1417
  commits.push(commit);
1426
1418
  const next = oldAtom.sibling;
@@ -1443,12 +1435,12 @@ function createNewView(start, nativeRenderer, context, parentComponent, effect)
1443
1435
  };
1444
1436
  }
1445
1437
  function updateText(newAtom, oldAtom, nativeRenderer, context) {
1446
- return function () {
1438
+ return function (offset) {
1447
1439
  const nativeNode = oldAtom.nativeNode;
1448
- if (newAtom.jsxNode !== oldAtom.jsxNode) {
1449
- nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode, newAtom.isSvg);
1450
- }
1451
1440
  newAtom.nativeNode = nativeNode;
1441
+ if (newAtom.index - offset !== oldAtom.index) {
1442
+ insertNode(nativeRenderer, newAtom, context);
1443
+ }
1452
1444
  context.host = nativeNode;
1453
1445
  context.isParent = false;
1454
1446
  };
@@ -1562,7 +1554,7 @@ function componentRender(nativeRenderer, component, from, context) {
1562
1554
  }
1563
1555
  component.rendered();
1564
1556
  }
1565
- function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
1557
+ function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, isSvg, key) {
1566
1558
  const atom = {
1567
1559
  type,
1568
1560
  index: prevAtom.index + 1,
@@ -1570,7 +1562,9 @@ function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
1570
1562
  sibling: null,
1571
1563
  child: null,
1572
1564
  nativeNode: null,
1573
- isSvg
1565
+ isSvg,
1566
+ nodeType,
1567
+ key
1574
1568
  };
1575
1569
  prevAtom.sibling = atom;
1576
1570
  return atom;
@@ -1579,7 +1573,7 @@ function createChainByNode(jsxNode, prevAtom, isSvg) {
1579
1573
  const type = typeof jsxNode;
1580
1574
  if (jsxNode !== null && type !== 'undefined' && type !== 'boolean') {
1581
1575
  if (typeof jsxNode === 'string') {
1582
- return createChainByJSXNode(TextAtomType, jsxNode, prevAtom, isSvg);
1576
+ return createChainByJSXNode(TextAtomType, jsxNode, jsxNode, prevAtom, isSvg);
1583
1577
  }
1584
1578
  if (Array.isArray(jsxNode)) {
1585
1579
  return createChainByChildren(jsxNode, prevAtom, isSvg);
@@ -1587,13 +1581,14 @@ function createChainByNode(jsxNode, prevAtom, isSvg) {
1587
1581
  if (type === 'object') {
1588
1582
  const nodeType = typeof jsxNode.type;
1589
1583
  if (nodeType === 'string') {
1590
- return createChainByJSXNode(ElementAtomType, jsxNode, prevAtom, isSvg || jsxNode.type === 'svg');
1584
+ return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, isSvg || jsxNode.type === 'svg', jsxNode.key);
1591
1585
  }
1592
1586
  else if (nodeType === 'function') {
1593
- return createChainByJSXNode(ComponentAtomType, jsxNode, prevAtom, isSvg);
1587
+ return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, isSvg, jsxNode.key);
1594
1588
  }
1595
1589
  }
1596
- return createChainByJSXNode(TextAtomType, String(jsxNode), prevAtom, isSvg);
1590
+ const text = String(jsxNode);
1591
+ return createChainByJSXNode(TextAtomType, text, text, prevAtom, isSvg);
1597
1592
  }
1598
1593
  return prevAtom;
1599
1594
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "1.0.0-alpha.16",
3
+ "version": "1.0.0-alpha.18",
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": "d2c8ce1c906fd80e05e27d677e7f678ccae0e9a1",
53
+ "gitHead": "b66ca589f7662cd518fc2e5955b3e3ff9de83f94",
54
54
  "dependencies": {
55
55
  "reflect-metadata": "^0.2.2"
56
56
  }