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

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.
@@ -113,7 +113,7 @@ interface Prop {
113
113
  declare const Prop: PropDecorator;
114
114
 
115
115
  declare const THROW_IF_NOT_FOUND: any;
116
- declare class NullInjector extends Injector {
116
+ declare class NullInjector implements Injector {
117
117
  parentInjector: null;
118
118
  get(token: any, notFoundValue?: any, _?: InjectFlags): any;
119
119
  }
@@ -167,9 +167,8 @@ declare function normalizeProvider(provider: Provider): NormalizedProvider;
167
167
  /**
168
168
  * 反射注入器
169
169
  */
170
- declare class ReflectiveInjector extends Injector {
170
+ declare class ReflectiveInjector implements Injector {
171
171
  parentInjector: Injector | null;
172
- protected staticProviders: Provider[];
173
172
  protected scope?: Scope | undefined;
174
173
  protected normalizedProviders: NormalizedProvider[];
175
174
  protected recordValues: Map<Type<any> | AbstractType<any> | InjectionToken<any>, any>;
@@ -531,6 +530,8 @@ interface TextAtom {
531
530
  child: Atom | null;
532
531
  sibling: Atom | null;
533
532
  isSvg: boolean;
533
+ update: null | ((insertOffset: number) => void);
534
+ next: Atom | null;
534
535
  }
535
536
  interface ElementAtom {
536
537
  type: typeof ElementAtomType;
@@ -540,6 +541,8 @@ interface ElementAtom {
540
541
  child: Atom | null;
541
542
  sibling: Atom | null;
542
543
  isSvg: boolean;
544
+ update: null | ((insertOffset: number) => void);
545
+ next: Atom | null;
543
546
  }
544
547
  interface ComponentAtom {
545
548
  type: typeof ComponentAtomType;
@@ -549,6 +552,8 @@ interface ComponentAtom {
549
552
  child: Atom | null;
550
553
  sibling: Atom | null;
551
554
  isSvg: boolean;
555
+ update: null | ((insertOffset: number) => void);
556
+ next: Atom | null;
552
557
  }
553
558
  type Atom = TextAtom | ElementAtom | ComponentAtom;
554
559
  interface ComponentView {
@@ -234,9 +234,8 @@ const THROW_IF_NOT_FOUND = {
234
234
  const nullInjectorErrorFn = (token) => {
235
235
  return makeError('NullInjector')(`No provide for \`${stringify(token)}\`!`);
236
236
  };
237
- class NullInjector extends Injector {
237
+ class NullInjector {
238
238
  constructor() {
239
- super(...arguments);
240
239
  this.parentInjector = null;
241
240
  }
242
241
  /* eslint-disable-next-line */
@@ -411,11 +410,9 @@ const provideScopeError = (token) => {
411
410
  /**
412
411
  * 反射注入器
413
412
  */
414
- class ReflectiveInjector extends Injector {
413
+ class ReflectiveInjector {
415
414
  constructor(parentInjector, staticProviders, scope) {
416
- super();
417
415
  this.parentInjector = parentInjector;
418
- this.staticProviders = staticProviders;
419
416
  this.scope = scope;
420
417
  this.recordValues = new Map();
421
418
  this.normalizedProviders = staticProviders.map(provide => {
@@ -1301,7 +1298,9 @@ function createRenderer(component, nativeRenderer) {
1301
1298
  sibling: null,
1302
1299
  child: null,
1303
1300
  nativeNode: null,
1304
- isSvg: false
1301
+ isSvg: false,
1302
+ update: null,
1303
+ next: null
1305
1304
  };
1306
1305
  componentRender(nativeRenderer, component, atom, {
1307
1306
  isParent: true,
@@ -1371,72 +1370,61 @@ function applyChanges(nativeRenderer, component) {
1371
1370
  }
1372
1371
  }
1373
1372
  function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1374
- const commits = [];
1375
- function changeOffset() {
1376
- offset++;
1377
- }
1378
- while (newAtom) {
1379
- oldAtom = createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, changeOffset);
1380
- newAtom = newAtom.sibling;
1381
- }
1382
- let dirtyDiffAtom = oldAtom;
1383
- while (dirtyDiffAtom) {
1384
- cleanView(nativeRenderer, dirtyDiffAtom, true);
1385
- dirtyDiffAtom = dirtyDiffAtom.sibling;
1386
- }
1387
- let offset = 0;
1388
- for (let i = 0; i < commits.length; i++) {
1389
- const commit = commits[i];
1390
- while (oldAtom) {
1391
- if (oldAtom.index <= i) {
1392
- offset--;
1393
- oldAtom = oldAtom.sibling;
1394
- continue;
1395
- }
1396
- break;
1397
- }
1398
- commit(offset);
1399
- }
1400
- }
1401
- function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
1402
- const startDiffAtom = oldAtom;
1403
- const { jsxNode: newJsxNode, type } = newAtom;
1404
- const key = newJsxNode.key;
1405
- let prev = null;
1373
+ let updateAtom = newAtom;
1374
+ let insertOffset = 0;
1375
+ let deleteOffset = 0;
1406
1376
  while (oldAtom) {
1407
- const diffIndex = oldAtom.index;
1408
- if (type === oldAtom.type) {
1409
- let commit;
1410
- if (type === TextAtomType) {
1411
- commit = updateText(newAtom, oldAtom, nativeRenderer, context);
1412
- }
1413
- else {
1414
- const { key: diffKey, type: diffType } = oldAtom.jsxNode;
1415
- if (diffKey !== key || newJsxNode.type !== diffType) {
1416
- prev = oldAtom;
1417
- oldAtom = oldAtom.sibling;
1418
- continue;
1419
- }
1420
- if (type === ComponentAtomType) {
1421
- commit = updateComponent(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context);
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;
1422
1386
  }
1423
1387
  else {
1424
- commit = updateElement(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context, parentComponent);
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
+ }
1425
1399
  }
1426
1400
  }
1427
- commits.push(commit);
1428
- const next = oldAtom.sibling;
1429
- if (!prev) {
1430
- return next;
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;
1431
1408
  }
1432
- prev.sibling = next;
1433
- return startDiffAtom;
1409
+ prev = newAtom;
1410
+ newAtom = newAtom.next || newAtom.sibling;
1411
+ }
1412
+ if (!isUsed) {
1413
+ newAtom = startDiffAtom;
1414
+ deleteOffset++;
1415
+ cleanView(nativeRenderer, oldAtom, true);
1434
1416
  }
1435
- prev = oldAtom;
1436
1417
  oldAtom = oldAtom.sibling;
1437
1418
  }
1438
- commits.push(createNewView(newAtom, nativeRenderer, context, parentComponent, effect));
1439
- return startDiffAtom;
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
+ }
1440
1428
  }
1441
1429
  function createNewView(start, nativeRenderer, context, parentComponent, effect) {
1442
1430
  return function () {
@@ -1455,10 +1443,10 @@ function updateText(newAtom, oldAtom, nativeRenderer, context) {
1455
1443
  context.isParent = false;
1456
1444
  };
1457
1445
  }
1458
- function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer, context, parentComponent) {
1459
- return function (offset) {
1446
+ function updateElement(newAtom, oldAtom, deleteOffset, nativeRenderer, context, parentComponent) {
1447
+ return function (insertOffset) {
1460
1448
  newAtom.nativeNode = oldAtom.nativeNode;
1461
- if (expectIndex - offset !== oldIndex) {
1449
+ if (newAtom.index - insertOffset !== oldAtom.index - deleteOffset) {
1462
1450
  insertNode(nativeRenderer, newAtom, context);
1463
1451
  }
1464
1452
  context.host = newAtom.nativeNode;
@@ -1466,8 +1454,8 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
1466
1454
  updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComponent, context);
1467
1455
  };
1468
1456
  }
1469
- function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRenderer, context) {
1470
- return function (offset) {
1457
+ function updateComponent(newAtom, reusedAtom, deleteOffset, nativeRenderer, context) {
1458
+ return function (insertOffset) {
1471
1459
  const component = reusedAtom.jsxNode;
1472
1460
  const newProps = newAtom.jsxNode.props;
1473
1461
  const oldTemplate = component.template;
@@ -1477,7 +1465,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
1477
1465
  componentViewCache.set(component, Object.assign({ atom: newAtom }, context));
1478
1466
  newAtom.jsxNode = component;
1479
1467
  if (newTemplate === oldTemplate) {
1480
- reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
1468
+ reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, newAtom.index - insertOffset !== reusedAtom.index - deleteOffset);
1481
1469
  updateView(nativeRenderer, component);
1482
1470
  return;
1483
1471
  }
@@ -1572,7 +1560,9 @@ function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
1572
1560
  sibling: null,
1573
1561
  child: null,
1574
1562
  nativeNode: null,
1575
- isSvg
1563
+ isSvg,
1564
+ update: null,
1565
+ next: null
1576
1566
  };
1577
1567
  prevAtom.sibling = atom;
1578
1568
  return atom;
package/bundles/index.js CHANGED
@@ -236,9 +236,8 @@ const THROW_IF_NOT_FOUND = {
236
236
  const nullInjectorErrorFn = (token) => {
237
237
  return makeError('NullInjector')(`No provide for \`${stringify(token)}\`!`);
238
238
  };
239
- class NullInjector extends Injector {
239
+ class NullInjector {
240
240
  constructor() {
241
- super(...arguments);
242
241
  this.parentInjector = null;
243
242
  }
244
243
  /* eslint-disable-next-line */
@@ -413,11 +412,9 @@ const provideScopeError = (token) => {
413
412
  /**
414
413
  * 反射注入器
415
414
  */
416
- class ReflectiveInjector extends Injector {
415
+ class ReflectiveInjector {
417
416
  constructor(parentInjector, staticProviders, scope) {
418
- super();
419
417
  this.parentInjector = parentInjector;
420
- this.staticProviders = staticProviders;
421
418
  this.scope = scope;
422
419
  this.recordValues = new Map();
423
420
  this.normalizedProviders = staticProviders.map(provide => {
@@ -1303,7 +1300,9 @@ function createRenderer(component, nativeRenderer) {
1303
1300
  sibling: null,
1304
1301
  child: null,
1305
1302
  nativeNode: null,
1306
- isSvg: false
1303
+ isSvg: false,
1304
+ update: null,
1305
+ next: null
1307
1306
  };
1308
1307
  componentRender(nativeRenderer, component, atom, {
1309
1308
  isParent: true,
@@ -1373,72 +1372,61 @@ function applyChanges(nativeRenderer, component) {
1373
1372
  }
1374
1373
  }
1375
1374
  function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context) {
1376
- const commits = [];
1377
- function changeOffset() {
1378
- offset++;
1379
- }
1380
- while (newAtom) {
1381
- oldAtom = createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, changeOffset);
1382
- newAtom = newAtom.sibling;
1383
- }
1384
- let dirtyDiffAtom = oldAtom;
1385
- while (dirtyDiffAtom) {
1386
- cleanView(nativeRenderer, dirtyDiffAtom, true);
1387
- dirtyDiffAtom = dirtyDiffAtom.sibling;
1388
- }
1389
- let offset = 0;
1390
- for (let i = 0; i < commits.length; i++) {
1391
- const commit = commits[i];
1392
- while (oldAtom) {
1393
- if (oldAtom.index <= i) {
1394
- offset--;
1395
- oldAtom = oldAtom.sibling;
1396
- continue;
1397
- }
1398
- break;
1399
- }
1400
- commit(offset);
1401
- }
1402
- }
1403
- function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, parentComponent, effect) {
1404
- const startDiffAtom = oldAtom;
1405
- const { jsxNode: newJsxNode, type } = newAtom;
1406
- const key = newJsxNode.key;
1407
- let prev = null;
1375
+ let updateAtom = newAtom;
1376
+ let insertOffset = 0;
1377
+ let deleteOffset = 0;
1408
1378
  while (oldAtom) {
1409
- const diffIndex = oldAtom.index;
1410
- if (type === oldAtom.type) {
1411
- let commit;
1412
- if (type === TextAtomType) {
1413
- commit = updateText(newAtom, oldAtom, nativeRenderer, context);
1414
- }
1415
- else {
1416
- const { key: diffKey, type: diffType } = oldAtom.jsxNode;
1417
- if (diffKey !== key || newJsxNode.type !== diffType) {
1418
- prev = oldAtom;
1419
- oldAtom = oldAtom.sibling;
1420
- continue;
1421
- }
1422
- if (type === ComponentAtomType) {
1423
- commit = updateComponent(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context);
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;
1424
1388
  }
1425
1389
  else {
1426
- commit = updateElement(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context, parentComponent);
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
+ }
1427
1401
  }
1428
1402
  }
1429
- commits.push(commit);
1430
- const next = oldAtom.sibling;
1431
- if (!prev) {
1432
- return next;
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;
1433
1410
  }
1434
- prev.sibling = next;
1435
- return startDiffAtom;
1411
+ prev = newAtom;
1412
+ newAtom = newAtom.next || newAtom.sibling;
1413
+ }
1414
+ if (!isUsed) {
1415
+ newAtom = startDiffAtom;
1416
+ deleteOffset++;
1417
+ cleanView(nativeRenderer, oldAtom, true);
1436
1418
  }
1437
- prev = oldAtom;
1438
1419
  oldAtom = oldAtom.sibling;
1439
1420
  }
1440
- commits.push(createNewView(newAtom, nativeRenderer, context, parentComponent, effect));
1441
- return startDiffAtom;
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
+ }
1442
1430
  }
1443
1431
  function createNewView(start, nativeRenderer, context, parentComponent, effect) {
1444
1432
  return function () {
@@ -1457,10 +1445,10 @@ function updateText(newAtom, oldAtom, nativeRenderer, context) {
1457
1445
  context.isParent = false;
1458
1446
  };
1459
1447
  }
1460
- function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer, context, parentComponent) {
1461
- return function (offset) {
1448
+ function updateElement(newAtom, oldAtom, deleteOffset, nativeRenderer, context, parentComponent) {
1449
+ return function (insertOffset) {
1462
1450
  newAtom.nativeNode = oldAtom.nativeNode;
1463
- if (expectIndex - offset !== oldIndex) {
1451
+ if (newAtom.index - insertOffset !== oldAtom.index - deleteOffset) {
1464
1452
  insertNode(nativeRenderer, newAtom, context);
1465
1453
  }
1466
1454
  context.host = newAtom.nativeNode;
@@ -1468,8 +1456,8 @@ function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer,
1468
1456
  updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComponent, context);
1469
1457
  };
1470
1458
  }
1471
- function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRenderer, context) {
1472
- return function (offset) {
1459
+ function updateComponent(newAtom, reusedAtom, deleteOffset, nativeRenderer, context) {
1460
+ return function (insertOffset) {
1473
1461
  const component = reusedAtom.jsxNode;
1474
1462
  const newProps = newAtom.jsxNode.props;
1475
1463
  const oldTemplate = component.template;
@@ -1479,7 +1467,7 @@ function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRende
1479
1467
  componentViewCache.set(component, Object.assign({ atom: newAtom }, context));
1480
1468
  newAtom.jsxNode = component;
1481
1469
  if (newTemplate === oldTemplate) {
1482
- reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
1470
+ reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, newAtom.index - insertOffset !== reusedAtom.index - deleteOffset);
1483
1471
  updateView(nativeRenderer, component);
1484
1472
  return;
1485
1473
  }
@@ -1574,7 +1562,9 @@ function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
1574
1562
  sibling: null,
1575
1563
  child: null,
1576
1564
  nativeNode: null,
1577
- isSvg
1565
+ isSvg,
1566
+ update: null,
1567
+ next: null
1578
1568
  };
1579
1569
  prevAtom.sibling = atom;
1580
1570
  return atom;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viewfly/core",
3
- "version": "1.0.0-alpha.13",
3
+ "version": "1.0.0-alpha.14",
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": "ef79169385a2b104fc58cb0b38123443e5baccd7",
53
+ "gitHead": "48779d88f1390751bbd06e4c4581bf3dbe613a26",
54
54
  "dependencies": {
55
55
  "reflect-metadata": "^0.2.2"
56
56
  }