@viewfly/core 0.2.1 → 0.2.2

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.
@@ -1332,7 +1332,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1332
1332
  }
1333
1333
  const commits = [];
1334
1334
  const changeCommits = {
1335
- updateComponent: (newAtom, reusedAtom, expectIndex, diffIndex) => {
1335
+ updateComponent: (newAtom, reusedAtom, expectIndex, oldIndex) => {
1336
1336
  commits.push((offset) => {
1337
1337
  const instance = reusedAtom.jsxNode;
1338
1338
  const newProps = newAtom.jsxNode.props;
@@ -1341,7 +1341,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1341
1341
  instance.$$view = Object.assign({ atom: newAtom }, context);
1342
1342
  newAtom.jsxNode = instance;
1343
1343
  if (newTemplate === oldTemplate) {
1344
- reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex !== diffIndex - offset);
1344
+ reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
1345
1345
  updateView(nativeRenderer, instance);
1346
1346
  return;
1347
1347
  }
@@ -1349,7 +1349,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1349
1349
  linkTemplate(newTemplate, newAtom.jsxNode, newAtom);
1350
1350
  }
1351
1351
  if (newAtom.child) {
1352
- diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex, diffIndex);
1352
+ diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex);
1353
1353
  }
1354
1354
  else if (reusedAtom.child) {
1355
1355
  let atom = reusedAtom.child;
@@ -1365,7 +1365,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1365
1365
  commits.push((offset) => {
1366
1366
  newAtom.nativeNode = oldAtom.nativeNode;
1367
1367
  const host = context.host;
1368
- if (expectIndex !== oldIndex - offset) {
1368
+ if (expectIndex - offset !== oldIndex) {
1369
1369
  if (context.isParent) {
1370
1370
  nativeRenderer.prependChild(host, newAtom.nativeNode);
1371
1371
  }
@@ -1406,6 +1406,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1406
1406
  create: (start) => {
1407
1407
  commits.push(() => {
1408
1408
  buildView(nativeRenderer, parentComponent, start, context);
1409
+ offset++;
1409
1410
  });
1410
1411
  }
1411
1412
  };
@@ -1424,7 +1425,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1424
1425
  const commit = commits[i];
1425
1426
  while (firstDiffAtomIndexed) {
1426
1427
  if (firstDiffAtomIndexed.index <= i) {
1427
- offset++;
1428
+ offset--;
1428
1429
  firstDiffAtomIndexed = firstDiffAtomIndexed.next;
1429
1430
  continue;
1430
1431
  }
@@ -1433,40 +1434,6 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1433
1434
  commit(offset);
1434
1435
  }
1435
1436
  }
1436
- function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
1437
- let child = reusedAtom.child;
1438
- newAtom.child = child;
1439
- const children = [];
1440
- while (child) {
1441
- children.push(child);
1442
- child.parent = newAtom;
1443
- child = child.sibling;
1444
- }
1445
- const updateContext = (atom) => {
1446
- if (atom.jsxNode instanceof Component) {
1447
- let child = atom.child;
1448
- while (child) {
1449
- updateContext(child);
1450
- child = child.sibling;
1451
- }
1452
- }
1453
- else {
1454
- if (moveView) {
1455
- if (context.isParent) {
1456
- nativeRenderer.prependChild(context.host, atom.nativeNode);
1457
- }
1458
- else {
1459
- nativeRenderer.insertAfter(atom.nativeNode, context.host);
1460
- }
1461
- }
1462
- context.isParent = false;
1463
- context.host = atom.nativeNode;
1464
- }
1465
- };
1466
- for (const atom of children) {
1467
- updateContext(atom);
1468
- }
1469
- }
1470
1437
  function createChanges(newAtom, expectIndex, diffAtomIndexed, changeCommits) {
1471
1438
  const startDiffAtom = diffAtomIndexed;
1472
1439
  while (diffAtomIndexed) {
@@ -1509,6 +1476,40 @@ function createChanges(newAtom, expectIndex, diffAtomIndexed, changeCommits) {
1509
1476
  changeCommits.create(newAtom);
1510
1477
  return startDiffAtom;
1511
1478
  }
1479
+ function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
1480
+ let child = reusedAtom.child;
1481
+ newAtom.child = child;
1482
+ const children = [];
1483
+ while (child) {
1484
+ children.push(child);
1485
+ child.parent = newAtom;
1486
+ child = child.sibling;
1487
+ }
1488
+ const updateContext = (atom) => {
1489
+ if (atom.jsxNode instanceof Component) {
1490
+ let child = atom.child;
1491
+ while (child) {
1492
+ updateContext(child);
1493
+ child = child.sibling;
1494
+ }
1495
+ }
1496
+ else {
1497
+ if (moveView) {
1498
+ if (context.isParent) {
1499
+ nativeRenderer.prependChild(context.host, atom.nativeNode);
1500
+ }
1501
+ else {
1502
+ nativeRenderer.insertAfter(atom.nativeNode, context.host);
1503
+ }
1504
+ }
1505
+ context.isParent = false;
1506
+ context.host = atom.nativeNode;
1507
+ }
1508
+ };
1509
+ for (const atom of children) {
1510
+ updateContext(atom);
1511
+ }
1512
+ }
1512
1513
  function cleanView(nativeRenderer, atom, isClean) {
1513
1514
  if (atom.nativeNode) {
1514
1515
  if (!isClean) {
@@ -1802,7 +1803,7 @@ class RootComponent extends Component {
1802
1803
  }
1803
1804
 
1804
1805
  const viewflyErrorFn = makeError('Viewfly');
1805
- const VERSION = "0.2.1";
1806
+ const VERSION = "0.2.2";
1806
1807
  function viewfly(config) {
1807
1808
  const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
1808
1809
  const appProviders = [];
package/bundles/index.js CHANGED
@@ -1334,7 +1334,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1334
1334
  }
1335
1335
  const commits = [];
1336
1336
  const changeCommits = {
1337
- updateComponent: (newAtom, reusedAtom, expectIndex, diffIndex) => {
1337
+ updateComponent: (newAtom, reusedAtom, expectIndex, oldIndex) => {
1338
1338
  commits.push((offset) => {
1339
1339
  const instance = reusedAtom.jsxNode;
1340
1340
  const newProps = newAtom.jsxNode.props;
@@ -1343,7 +1343,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1343
1343
  instance.$$view = Object.assign({ atom: newAtom }, context);
1344
1344
  newAtom.jsxNode = instance;
1345
1345
  if (newTemplate === oldTemplate) {
1346
- reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex !== diffIndex - offset);
1346
+ reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
1347
1347
  updateView(nativeRenderer, instance);
1348
1348
  return;
1349
1349
  }
@@ -1351,7 +1351,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1351
1351
  linkTemplate(newTemplate, newAtom.jsxNode, newAtom);
1352
1352
  }
1353
1353
  if (newAtom.child) {
1354
- diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex, diffIndex);
1354
+ diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex);
1355
1355
  }
1356
1356
  else if (reusedAtom.child) {
1357
1357
  let atom = reusedAtom.child;
@@ -1367,7 +1367,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1367
1367
  commits.push((offset) => {
1368
1368
  newAtom.nativeNode = oldAtom.nativeNode;
1369
1369
  const host = context.host;
1370
- if (expectIndex !== oldIndex - offset) {
1370
+ if (expectIndex - offset !== oldIndex) {
1371
1371
  if (context.isParent) {
1372
1372
  nativeRenderer.prependChild(host, newAtom.nativeNode);
1373
1373
  }
@@ -1408,6 +1408,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1408
1408
  create: (start) => {
1409
1409
  commits.push(() => {
1410
1410
  buildView(nativeRenderer, parentComponent, start, context);
1411
+ offset++;
1411
1412
  });
1412
1413
  }
1413
1414
  };
@@ -1426,7 +1427,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1426
1427
  const commit = commits[i];
1427
1428
  while (firstDiffAtomIndexed) {
1428
1429
  if (firstDiffAtomIndexed.index <= i) {
1429
- offset++;
1430
+ offset--;
1430
1431
  firstDiffAtomIndexed = firstDiffAtomIndexed.next;
1431
1432
  continue;
1432
1433
  }
@@ -1435,40 +1436,6 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
1435
1436
  commit(offset);
1436
1437
  }
1437
1438
  }
1438
- function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
1439
- let child = reusedAtom.child;
1440
- newAtom.child = child;
1441
- const children = [];
1442
- while (child) {
1443
- children.push(child);
1444
- child.parent = newAtom;
1445
- child = child.sibling;
1446
- }
1447
- const updateContext = (atom) => {
1448
- if (atom.jsxNode instanceof Component) {
1449
- let child = atom.child;
1450
- while (child) {
1451
- updateContext(child);
1452
- child = child.sibling;
1453
- }
1454
- }
1455
- else {
1456
- if (moveView) {
1457
- if (context.isParent) {
1458
- nativeRenderer.prependChild(context.host, atom.nativeNode);
1459
- }
1460
- else {
1461
- nativeRenderer.insertAfter(atom.nativeNode, context.host);
1462
- }
1463
- }
1464
- context.isParent = false;
1465
- context.host = atom.nativeNode;
1466
- }
1467
- };
1468
- for (const atom of children) {
1469
- updateContext(atom);
1470
- }
1471
- }
1472
1439
  function createChanges(newAtom, expectIndex, diffAtomIndexed, changeCommits) {
1473
1440
  const startDiffAtom = diffAtomIndexed;
1474
1441
  while (diffAtomIndexed) {
@@ -1511,6 +1478,40 @@ function createChanges(newAtom, expectIndex, diffAtomIndexed, changeCommits) {
1511
1478
  changeCommits.create(newAtom);
1512
1479
  return startDiffAtom;
1513
1480
  }
1481
+ function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
1482
+ let child = reusedAtom.child;
1483
+ newAtom.child = child;
1484
+ const children = [];
1485
+ while (child) {
1486
+ children.push(child);
1487
+ child.parent = newAtom;
1488
+ child = child.sibling;
1489
+ }
1490
+ const updateContext = (atom) => {
1491
+ if (atom.jsxNode instanceof Component) {
1492
+ let child = atom.child;
1493
+ while (child) {
1494
+ updateContext(child);
1495
+ child = child.sibling;
1496
+ }
1497
+ }
1498
+ else {
1499
+ if (moveView) {
1500
+ if (context.isParent) {
1501
+ nativeRenderer.prependChild(context.host, atom.nativeNode);
1502
+ }
1503
+ else {
1504
+ nativeRenderer.insertAfter(atom.nativeNode, context.host);
1505
+ }
1506
+ }
1507
+ context.isParent = false;
1508
+ context.host = atom.nativeNode;
1509
+ }
1510
+ };
1511
+ for (const atom of children) {
1512
+ updateContext(atom);
1513
+ }
1514
+ }
1514
1515
  function cleanView(nativeRenderer, atom, isClean) {
1515
1516
  if (atom.nativeNode) {
1516
1517
  if (!isClean) {
@@ -1804,7 +1805,7 @@ class RootComponent extends Component {
1804
1805
  }
1805
1806
 
1806
1807
  const viewflyErrorFn = makeError('Viewfly');
1807
- const VERSION = "0.2.1";
1808
+ const VERSION = "0.2.2";
1808
1809
  function viewfly(config) {
1809
1810
  const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
1810
1811
  const appProviders = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
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",