@viewfly/core 1.0.0-alpha.20 → 1.0.0-alpha.21

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.
@@ -293,7 +293,7 @@ declare class Component extends ReflectiveInjector {
293
293
  template: any;
294
294
  portalHost: NativeNode | undefined;
295
295
  };
296
- update(newProps: Record<string, any>, forceUpdate?: boolean): any;
296
+ update(newProps: Record<string, any>): any;
297
297
  provide<T>(providers: Provider<T> | Provider<T>[]): void;
298
298
  rendered(): void;
299
299
  destroy(): void;
@@ -740,17 +740,13 @@ class Component extends ReflectiveInjector {
740
740
  portalHost: this.instance.$portalHost
741
741
  };
742
742
  }
743
- update(newProps, forceUpdate = false) {
743
+ update(newProps) {
744
744
  const oldProps = this.props;
745
- if (!forceUpdate) {
745
+ if (newProps !== oldProps) {
746
746
  const { add, remove, replace } = getObjectChanges(newProps, oldProps);
747
747
  if (add.length || remove.length || replace.length) {
748
748
  this.invokePropsChangedHooks(newProps);
749
749
  }
750
- else if (!this.dirty) {
751
- this.props = newProps;
752
- return this.template;
753
- }
754
750
  const newRefs = toRefs(newProps.ref);
755
751
  if (this.refs) {
756
752
  for (const oldRef of this.refs) {
@@ -1353,14 +1349,14 @@ function updateView(nativeRenderer, component) {
1353
1349
  function applyChanges(nativeRenderer, component) {
1354
1350
  const { atom, host, isParent, rootHost } = componentViewCache.get(component);
1355
1351
  const diffAtom = atom.child;
1356
- const template = component.update(component.props, true);
1352
+ const template = component.update(component.props);
1357
1353
  atom.child = createChildChain(template, atom.isSvg);
1358
1354
  const context = {
1359
1355
  host,
1360
1356
  isParent,
1361
1357
  rootHost
1362
1358
  };
1363
- diff(nativeRenderer, component, atom.child, diffAtom, context);
1359
+ diff(nativeRenderer, component, atom.child, diffAtom, context, false);
1364
1360
  const next = atom.sibling;
1365
1361
  if (next && next.jsxNode instanceof Component) {
1366
1362
  const view = componentViewCache.get(next.jsxNode);
@@ -1368,7 +1364,7 @@ function applyChanges(nativeRenderer, component) {
1368
1364
  view.isParent = context.isParent;
1369
1365
  }
1370
1366
  }
1371
- function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1367
+ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, needMove) {
1372
1368
  const commits = [];
1373
1369
  function changeOffset() {
1374
1370
  offset++;
@@ -1393,7 +1389,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1393
1389
  }
1394
1390
  break;
1395
1391
  }
1396
- commit(offset);
1392
+ commit(offset, needMove);
1397
1393
  }
1398
1394
  }
1399
1395
  function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
@@ -1433,10 +1429,10 @@ function createNewView(start, nativeRenderer, context, parentComponent, effect)
1433
1429
  };
1434
1430
  }
1435
1431
  function updateText(newAtom, oldAtom, nativeRenderer, context) {
1436
- return function (offset) {
1432
+ return function (offset, needMove) {
1437
1433
  const nativeNode = oldAtom.nativeNode;
1438
1434
  newAtom.nativeNode = nativeNode;
1439
- if (newAtom.index - offset !== oldAtom.index) {
1435
+ if (needMove || newAtom.index - offset !== oldAtom.index) {
1440
1436
  insertNode(nativeRenderer, newAtom, context);
1441
1437
  }
1442
1438
  context.host = nativeNode;
@@ -1444,9 +1440,9 @@ function updateText(newAtom, oldAtom, nativeRenderer, context) {
1444
1440
  };
1445
1441
  }
1446
1442
  function updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent) {
1447
- return function (offset) {
1443
+ return function (offset, needMove) {
1448
1444
  newAtom.nativeNode = oldAtom.nativeNode;
1449
- if (newAtom.index - offset !== oldAtom.index) {
1445
+ if (needMove || newAtom.index - offset !== oldAtom.index) {
1450
1446
  insertNode(nativeRenderer, newAtom, context);
1451
1447
  }
1452
1448
  context.host = newAtom.nativeNode;
@@ -1455,7 +1451,7 @@ function updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponen
1455
1451
  };
1456
1452
  }
1457
1453
  function updateComponent(newAtom, reusedAtom, nativeRenderer, context) {
1458
- return function (offset) {
1454
+ return function (offset, needMove) {
1459
1455
  const component = reusedAtom.jsxNode;
1460
1456
  const newProps = newAtom.jsxNode.props;
1461
1457
  const oldTemplate = component.template;
@@ -1465,15 +1461,16 @@ function updateComponent(newAtom, reusedAtom, nativeRenderer, context) {
1465
1461
  componentViewCache.set(component, Object.assign({ atom: newAtom }, context));
1466
1462
  newAtom.jsxNode = component;
1467
1463
  if (newTemplate === oldTemplate) {
1468
- reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, newAtom.index - offset !== reusedAtom.index);
1469
- updateView(nativeRenderer, component);
1464
+ newAtom.child = reusedAtom.child;
1465
+ reuseComponentView(nativeRenderer, newAtom.child, context, needMove || newAtom.index - offset !== reusedAtom.index);
1466
+ component.rendered();
1470
1467
  return;
1471
1468
  }
1472
1469
  if (newTemplate) {
1473
1470
  newAtom.child = createChildChain(newTemplate, newAtom.isSvg);
1474
1471
  }
1475
1472
  if (newAtom.child) {
1476
- diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context);
1473
+ diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context, needMove || newAtom.index - offset !== reusedAtom.index);
1477
1474
  }
1478
1475
  else if (reusedAtom.child) {
1479
1476
  let atom = reusedAtom.child;
@@ -1485,9 +1482,7 @@ function updateComponent(newAtom, reusedAtom, nativeRenderer, context) {
1485
1482
  component.rendered();
1486
1483
  };
1487
1484
  }
1488
- function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
1489
- let child = reusedAtom.child;
1490
- newAtom.child = child;
1485
+ function reuseComponentView(nativeRenderer, child, context, moveView) {
1491
1486
  const updateContext = (atom) => {
1492
1487
  if (atom.jsxNode instanceof Component) {
1493
1488
  let child = atom.child;
@@ -1792,7 +1787,7 @@ function updateElementChildren(newAtom, oldAtom, nativeRenderer, parentComponent
1792
1787
  host: newAtom.nativeNode,
1793
1788
  isParent: true,
1794
1789
  rootHost: context.rootHost
1795
- });
1790
+ }, false);
1796
1791
  }
1797
1792
  }
1798
1793
  function applyRefs(refs, nativeNode, binding) {
package/bundles/index.js CHANGED
@@ -742,17 +742,13 @@ class Component extends ReflectiveInjector {
742
742
  portalHost: this.instance.$portalHost
743
743
  };
744
744
  }
745
- update(newProps, forceUpdate = false) {
745
+ update(newProps) {
746
746
  const oldProps = this.props;
747
- if (!forceUpdate) {
747
+ if (newProps !== oldProps) {
748
748
  const { add, remove, replace } = getObjectChanges(newProps, oldProps);
749
749
  if (add.length || remove.length || replace.length) {
750
750
  this.invokePropsChangedHooks(newProps);
751
751
  }
752
- else if (!this.dirty) {
753
- this.props = newProps;
754
- return this.template;
755
- }
756
752
  const newRefs = toRefs(newProps.ref);
757
753
  if (this.refs) {
758
754
  for (const oldRef of this.refs) {
@@ -1355,14 +1351,14 @@ function updateView(nativeRenderer, component) {
1355
1351
  function applyChanges(nativeRenderer, component) {
1356
1352
  const { atom, host, isParent, rootHost } = componentViewCache.get(component);
1357
1353
  const diffAtom = atom.child;
1358
- const template = component.update(component.props, true);
1354
+ const template = component.update(component.props);
1359
1355
  atom.child = createChildChain(template, atom.isSvg);
1360
1356
  const context = {
1361
1357
  host,
1362
1358
  isParent,
1363
1359
  rootHost
1364
1360
  };
1365
- diff(nativeRenderer, component, atom.child, diffAtom, context);
1361
+ diff(nativeRenderer, component, atom.child, diffAtom, context, false);
1366
1362
  const next = atom.sibling;
1367
1363
  if (next && next.jsxNode instanceof Component) {
1368
1364
  const view = componentViewCache.get(next.jsxNode);
@@ -1370,7 +1366,7 @@ function applyChanges(nativeRenderer, component) {
1370
1366
  view.isParent = context.isParent;
1371
1367
  }
1372
1368
  }
1373
- function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1369
+ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, needMove) {
1374
1370
  const commits = [];
1375
1371
  function changeOffset() {
1376
1372
  offset++;
@@ -1395,7 +1391,7 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1395
1391
  }
1396
1392
  break;
1397
1393
  }
1398
- commit(offset);
1394
+ commit(offset, needMove);
1399
1395
  }
1400
1396
  }
1401
1397
  function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
@@ -1435,10 +1431,10 @@ function createNewView(start, nativeRenderer, context, parentComponent, effect)
1435
1431
  };
1436
1432
  }
1437
1433
  function updateText(newAtom, oldAtom, nativeRenderer, context) {
1438
- return function (offset) {
1434
+ return function (offset, needMove) {
1439
1435
  const nativeNode = oldAtom.nativeNode;
1440
1436
  newAtom.nativeNode = nativeNode;
1441
- if (newAtom.index - offset !== oldAtom.index) {
1437
+ if (needMove || newAtom.index - offset !== oldAtom.index) {
1442
1438
  insertNode(nativeRenderer, newAtom, context);
1443
1439
  }
1444
1440
  context.host = nativeNode;
@@ -1446,9 +1442,9 @@ function updateText(newAtom, oldAtom, nativeRenderer, context) {
1446
1442
  };
1447
1443
  }
1448
1444
  function updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponent) {
1449
- return function (offset) {
1445
+ return function (offset, needMove) {
1450
1446
  newAtom.nativeNode = oldAtom.nativeNode;
1451
- if (newAtom.index - offset !== oldAtom.index) {
1447
+ if (needMove || newAtom.index - offset !== oldAtom.index) {
1452
1448
  insertNode(nativeRenderer, newAtom, context);
1453
1449
  }
1454
1450
  context.host = newAtom.nativeNode;
@@ -1457,7 +1453,7 @@ function updateElement(newAtom, oldAtom, nativeRenderer, context, parentComponen
1457
1453
  };
1458
1454
  }
1459
1455
  function updateComponent(newAtom, reusedAtom, nativeRenderer, context) {
1460
- return function (offset) {
1456
+ return function (offset, needMove) {
1461
1457
  const component = reusedAtom.jsxNode;
1462
1458
  const newProps = newAtom.jsxNode.props;
1463
1459
  const oldTemplate = component.template;
@@ -1467,15 +1463,16 @@ function updateComponent(newAtom, reusedAtom, nativeRenderer, context) {
1467
1463
  componentViewCache.set(component, Object.assign({ atom: newAtom }, context));
1468
1464
  newAtom.jsxNode = component;
1469
1465
  if (newTemplate === oldTemplate) {
1470
- reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, newAtom.index - offset !== reusedAtom.index);
1471
- updateView(nativeRenderer, component);
1466
+ newAtom.child = reusedAtom.child;
1467
+ reuseComponentView(nativeRenderer, newAtom.child, context, needMove || newAtom.index - offset !== reusedAtom.index);
1468
+ component.rendered();
1472
1469
  return;
1473
1470
  }
1474
1471
  if (newTemplate) {
1475
1472
  newAtom.child = createChildChain(newTemplate, newAtom.isSvg);
1476
1473
  }
1477
1474
  if (newAtom.child) {
1478
- diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context);
1475
+ diff(nativeRenderer, component, newAtom.child, reusedAtom.child, context, needMove || newAtom.index - offset !== reusedAtom.index);
1479
1476
  }
1480
1477
  else if (reusedAtom.child) {
1481
1478
  let atom = reusedAtom.child;
@@ -1487,9 +1484,7 @@ function updateComponent(newAtom, reusedAtom, nativeRenderer, context) {
1487
1484
  component.rendered();
1488
1485
  };
1489
1486
  }
1490
- function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
1491
- let child = reusedAtom.child;
1492
- newAtom.child = child;
1487
+ function reuseComponentView(nativeRenderer, child, context, moveView) {
1493
1488
  const updateContext = (atom) => {
1494
1489
  if (atom.jsxNode instanceof Component) {
1495
1490
  let child = atom.child;
@@ -1794,7 +1789,7 @@ function updateElementChildren(newAtom, oldAtom, nativeRenderer, parentComponent
1794
1789
  host: newAtom.nativeNode,
1795
1790
  isParent: true,
1796
1791
  rootHost: context.rootHost
1797
- });
1792
+ }, false);
1798
1793
  }
1799
1794
  }
1800
1795
  function applyRefs(refs, nativeNode, binding) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "1.0.0-alpha.20",
3
+ "version": "1.0.0-alpha.21",
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": "b66ca589f7662cd518fc2e5955b3e3ff9de83f94",
53
+ "gitHead": "35403802377a499822c8801a48e68f85f9446563",
54
54
  "dependencies": {
55
55
  "reflect-metadata": "^0.2.2"
56
56
  }