@viewfly/core 0.3.1 → 0.4.1
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.
- package/bundles/foundation/component.d.ts +1 -1
- package/bundles/foundation/injection-tokens.d.ts +0 -1
- package/bundles/foundation/renderer.d.ts +1 -1
- package/bundles/foundation/root.component.d.ts +2 -2
- package/bundles/index.esm.js +144 -150
- package/bundles/index.js +143 -150
- package/bundles/viewfly.d.ts +1 -2
- package/package.json +2 -2
|
@@ -26,7 +26,7 @@ export declare class Component extends ReflectiveInjector implements JSXTypeof<J
|
|
|
26
26
|
protected _dirty: boolean;
|
|
27
27
|
protected _changed: boolean;
|
|
28
28
|
private unWatch?;
|
|
29
|
-
private
|
|
29
|
+
private isFirstRendering;
|
|
30
30
|
private refs;
|
|
31
31
|
constructor(parentComponent: Injector | null, type: JSXInternal.ComponentSetup, props: Props, key?: Key | undefined);
|
|
32
32
|
markAsDirtied(): void;
|
|
@@ -3,7 +3,6 @@ export declare abstract class NativeRenderer<ElementNode = NativeNode, TextNode
|
|
|
3
3
|
abstract createElement(name: string, isSvg: boolean): ElementNode;
|
|
4
4
|
abstract createTextNode(textContent: string, isSvg: boolean): TextNode;
|
|
5
5
|
abstract setProperty(node: ElementNode, key: string, value: any, isSvg: boolean): void;
|
|
6
|
-
abstract appendChild(parent: ElementNode, newChild: ElementNode | TextNode, isSvg: boolean): void;
|
|
7
6
|
abstract prependChild(parent: ElementNode, newChild: ElementNode | TextNode, isSvg: boolean): void;
|
|
8
7
|
abstract removeProperty(node: ElementNode, key: string, isSvg: boolean): void;
|
|
9
8
|
abstract setStyle(target: ElementNode, key: string, value: any, isSvg: boolean): void;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { NativeNode, NativeRenderer } from './injection-tokens';
|
|
2
2
|
import { Component } from './component';
|
|
3
|
-
export declare function createRenderer(component: Component, nativeRenderer: NativeRenderer
|
|
3
|
+
export declare function createRenderer(component: Component, nativeRenderer: NativeRenderer): (host: NativeNode) => void;
|
|
@@ -5,7 +5,7 @@ import { Injector } from '../di/_api';
|
|
|
5
5
|
* Viewfly 根组件,用于实现组件状态更新事件通知
|
|
6
6
|
*/
|
|
7
7
|
export declare class RootComponent extends Component {
|
|
8
|
-
|
|
9
|
-
constructor(parentInjector: Injector | null, factory: JSXInternal.ComponentSetup);
|
|
8
|
+
private refresh;
|
|
9
|
+
constructor(parentInjector: Injector | null, factory: JSXInternal.ComponentSetup, refresh: () => void);
|
|
10
10
|
markAsChanged(changedComponent?: Component): void;
|
|
11
11
|
}
|
package/bundles/index.esm.js
CHANGED
|
@@ -551,22 +551,22 @@ function getObjectChanges(newProps, oldProps) {
|
|
|
551
551
|
add: [],
|
|
552
552
|
replace: []
|
|
553
553
|
};
|
|
554
|
-
|
|
554
|
+
for (const key in newProps) {
|
|
555
555
|
const leftValue = newProps[key];
|
|
556
556
|
const rightValue = oldProps[key];
|
|
557
557
|
if (Reflect.has(oldProps, key)) {
|
|
558
558
|
if (leftValue !== rightValue) {
|
|
559
559
|
changes.replace.push([key, leftValue, rightValue]);
|
|
560
560
|
}
|
|
561
|
-
|
|
561
|
+
continue;
|
|
562
562
|
}
|
|
563
563
|
changes.add.push([key, leftValue]);
|
|
564
|
-
}
|
|
565
|
-
|
|
564
|
+
}
|
|
565
|
+
for (const key in oldProps) {
|
|
566
566
|
if (!Reflect.has(newProps, key)) {
|
|
567
567
|
changes.remove.push([key, oldProps[key]]);
|
|
568
568
|
}
|
|
569
|
-
}
|
|
569
|
+
}
|
|
570
570
|
return changes;
|
|
571
571
|
}
|
|
572
572
|
function getArrayChanges(left, right) {
|
|
@@ -674,7 +674,7 @@ class Component extends ReflectiveInjector {
|
|
|
674
674
|
this.propsChangedDestroyCallbacks = [];
|
|
675
675
|
this._dirty = true;
|
|
676
676
|
this._changed = true;
|
|
677
|
-
this.
|
|
677
|
+
this.isFirstRendering = true;
|
|
678
678
|
}
|
|
679
679
|
markAsDirtied() {
|
|
680
680
|
this._dirty = true;
|
|
@@ -775,15 +775,19 @@ class Component extends ReflectiveInjector {
|
|
|
775
775
|
}
|
|
776
776
|
rendered() {
|
|
777
777
|
this.changedSubComponents.clear();
|
|
778
|
-
const is = this.
|
|
779
|
-
this.
|
|
778
|
+
const is = this.isFirstRendering;
|
|
779
|
+
this.isFirstRendering = false;
|
|
780
780
|
this._dirty = this._changed = false;
|
|
781
|
+
this.invokeUpdatedHooks();
|
|
781
782
|
if (is) {
|
|
782
|
-
this.invokeUpdatedHooks();
|
|
783
783
|
this.invokeMountHooks();
|
|
784
784
|
}
|
|
785
|
-
|
|
786
|
-
|
|
785
|
+
if (this.changed) {
|
|
786
|
+
Promise.resolve().then(() => {
|
|
787
|
+
if (this.parentComponent instanceof Component) {
|
|
788
|
+
this.parentComponent.markAsChanged(this);
|
|
789
|
+
}
|
|
790
|
+
});
|
|
787
791
|
}
|
|
788
792
|
}
|
|
789
793
|
destroy() {
|
|
@@ -1215,11 +1219,10 @@ function withMemo(canUseMemo, render) {
|
|
|
1215
1219
|
};
|
|
1216
1220
|
}
|
|
1217
1221
|
|
|
1218
|
-
function createRenderer(component, nativeRenderer
|
|
1222
|
+
function createRenderer(component, nativeRenderer) {
|
|
1219
1223
|
let isInit = true;
|
|
1220
1224
|
return function render(host) {
|
|
1221
1225
|
if (isInit) {
|
|
1222
|
-
nativeRenderer.setProperty(host, 'viewfly-version', version, false);
|
|
1223
1226
|
isInit = false;
|
|
1224
1227
|
const atom = {
|
|
1225
1228
|
jsxNode: component,
|
|
@@ -1339,87 +1342,11 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1339
1342
|
}
|
|
1340
1343
|
}
|
|
1341
1344
|
const commits = [];
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
const instance = reusedAtom.jsxNode;
|
|
1346
|
-
const newProps = newAtom.jsxNode.props;
|
|
1347
|
-
const oldTemplate = instance.template;
|
|
1348
|
-
const newTemplate = instance.update(newProps);
|
|
1349
|
-
instance.$$view = Object.assign({ atom: newAtom }, context);
|
|
1350
|
-
newAtom.jsxNode = instance;
|
|
1351
|
-
if (newTemplate === oldTemplate) {
|
|
1352
|
-
reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
|
|
1353
|
-
updateView(nativeRenderer, instance);
|
|
1354
|
-
return;
|
|
1355
|
-
}
|
|
1356
|
-
if (newTemplate) {
|
|
1357
|
-
linkTemplate(newTemplate, newAtom.jsxNode, newAtom);
|
|
1358
|
-
}
|
|
1359
|
-
if (newAtom.child) {
|
|
1360
|
-
diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex);
|
|
1361
|
-
}
|
|
1362
|
-
else if (reusedAtom.child) {
|
|
1363
|
-
let atom = reusedAtom.child;
|
|
1364
|
-
while (atom) {
|
|
1365
|
-
cleanView(nativeRenderer, atom, false);
|
|
1366
|
-
atom = atom.sibling;
|
|
1367
|
-
}
|
|
1368
|
-
}
|
|
1369
|
-
instance.rendered();
|
|
1370
|
-
});
|
|
1371
|
-
},
|
|
1372
|
-
updateElement: (newAtom, oldAtom, expectIndex, oldIndex) => {
|
|
1373
|
-
commits.push((offset) => {
|
|
1374
|
-
newAtom.nativeNode = oldAtom.nativeNode;
|
|
1375
|
-
const host = context.host;
|
|
1376
|
-
if (expectIndex - offset !== oldIndex) {
|
|
1377
|
-
if (context.isParent) {
|
|
1378
|
-
nativeRenderer.prependChild(host, newAtom.nativeNode, newAtom.isSvg);
|
|
1379
|
-
}
|
|
1380
|
-
else {
|
|
1381
|
-
nativeRenderer.insertAfter(newAtom.nativeNode, host, newAtom.isSvg);
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
context.host = newAtom.nativeNode;
|
|
1385
|
-
context.isParent = false;
|
|
1386
|
-
const applyRefs = updateNativeNodeProperties(nativeRenderer, newAtom.jsxNode, oldAtom.jsxNode, newAtom.nativeNode, newAtom.isSvg);
|
|
1387
|
-
if (newAtom.child) {
|
|
1388
|
-
diff(nativeRenderer, parentComponent, newAtom.child, oldAtom.child, {
|
|
1389
|
-
host: newAtom.nativeNode,
|
|
1390
|
-
isParent: true
|
|
1391
|
-
}, 0, 0);
|
|
1392
|
-
}
|
|
1393
|
-
else if (oldAtom.child) {
|
|
1394
|
-
let atom = oldAtom.child;
|
|
1395
|
-
while (atom) {
|
|
1396
|
-
cleanView(nativeRenderer, atom, false);
|
|
1397
|
-
atom = atom.sibling;
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
applyRefs();
|
|
1401
|
-
});
|
|
1402
|
-
},
|
|
1403
|
-
updateText: (newAtom, oldAtom) => {
|
|
1404
|
-
commits.push(() => {
|
|
1405
|
-
const nativeNode = oldAtom.nativeNode;
|
|
1406
|
-
if (newAtom.jsxNode.text !== oldAtom.jsxNode.text) {
|
|
1407
|
-
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode.text, newAtom.isSvg);
|
|
1408
|
-
}
|
|
1409
|
-
newAtom.nativeNode = nativeNode;
|
|
1410
|
-
context.host = nativeNode;
|
|
1411
|
-
context.isParent = false;
|
|
1412
|
-
});
|
|
1413
|
-
},
|
|
1414
|
-
create: (start) => {
|
|
1415
|
-
commits.push(() => {
|
|
1416
|
-
buildView(nativeRenderer, parentComponent, start, context);
|
|
1417
|
-
offset++;
|
|
1418
|
-
});
|
|
1419
|
-
}
|
|
1420
|
-
};
|
|
1345
|
+
function changeOffset() {
|
|
1346
|
+
offset++;
|
|
1347
|
+
}
|
|
1421
1348
|
while (newAtom) {
|
|
1422
|
-
firstDiffAtomIndexed = createChanges(newAtom, expectIndex, firstDiffAtomIndexed,
|
|
1349
|
+
firstDiffAtomIndexed = createChanges(newAtom, expectIndex, firstDiffAtomIndexed, nativeRenderer, commits, context, parentComponent, changeOffset);
|
|
1423
1350
|
newAtom = newAtom.sibling;
|
|
1424
1351
|
expectIndex++;
|
|
1425
1352
|
}
|
|
@@ -1442,28 +1369,34 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1442
1369
|
commit(offset);
|
|
1443
1370
|
}
|
|
1444
1371
|
}
|
|
1445
|
-
function createChanges(newAtom, expectIndex, diffAtomIndexed,
|
|
1372
|
+
function createChanges(newAtom, expectIndex, diffAtomIndexed, nativeRenderer, commits, context, parentComponent, effect) {
|
|
1446
1373
|
const startDiffAtom = diffAtomIndexed;
|
|
1374
|
+
const key = newAtom.jsxNode.key;
|
|
1447
1375
|
while (diffAtomIndexed) {
|
|
1448
1376
|
const { atom: diffAtom, index: diffIndex } = diffAtomIndexed;
|
|
1449
|
-
const key = newAtom.jsxNode.key;
|
|
1450
1377
|
const diffKey = diffAtom.jsxNode.key;
|
|
1451
|
-
if (key !== undefined
|
|
1378
|
+
if (key !== undefined) {
|
|
1452
1379
|
if (diffKey !== key) {
|
|
1453
1380
|
diffAtomIndexed = diffAtomIndexed.next;
|
|
1454
1381
|
continue;
|
|
1455
1382
|
}
|
|
1456
1383
|
}
|
|
1384
|
+
else if (diffKey !== undefined) {
|
|
1385
|
+
diffAtomIndexed = diffAtomIndexed.next;
|
|
1386
|
+
continue;
|
|
1387
|
+
}
|
|
1457
1388
|
if (newAtom.jsxNode.$$typeOf === diffAtom.jsxNode.$$typeOf) {
|
|
1389
|
+
let commit;
|
|
1458
1390
|
if (newAtom.jsxNode instanceof JSXElement) {
|
|
1459
|
-
|
|
1391
|
+
commit = updateElement(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context, parentComponent);
|
|
1460
1392
|
}
|
|
1461
1393
|
else if (newAtom.jsxNode instanceof JSXText) {
|
|
1462
|
-
|
|
1394
|
+
commit = updateText(newAtom, diffAtom, nativeRenderer, context);
|
|
1463
1395
|
}
|
|
1464
1396
|
else {
|
|
1465
|
-
|
|
1397
|
+
commit = updateComponent(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context);
|
|
1466
1398
|
}
|
|
1399
|
+
commits.push(commit);
|
|
1467
1400
|
const next = diffAtomIndexed.next;
|
|
1468
1401
|
const prev = diffAtomIndexed.prev;
|
|
1469
1402
|
if (!prev) {
|
|
@@ -1481,9 +1414,86 @@ function createChanges(newAtom, expectIndex, diffAtomIndexed, changeCommits) {
|
|
|
1481
1414
|
}
|
|
1482
1415
|
diffAtomIndexed = diffAtomIndexed.next;
|
|
1483
1416
|
}
|
|
1484
|
-
|
|
1417
|
+
commits.push(createNewView(newAtom, nativeRenderer, context, parentComponent, effect));
|
|
1485
1418
|
return startDiffAtom;
|
|
1486
1419
|
}
|
|
1420
|
+
function createNewView(start, nativeRenderer, context, parentComponent, effect) {
|
|
1421
|
+
return function () {
|
|
1422
|
+
buildView(nativeRenderer, parentComponent, start, context);
|
|
1423
|
+
effect();
|
|
1424
|
+
};
|
|
1425
|
+
}
|
|
1426
|
+
function updateText(newAtom, oldAtom, nativeRenderer, context) {
|
|
1427
|
+
return function () {
|
|
1428
|
+
const nativeNode = oldAtom.nativeNode;
|
|
1429
|
+
if (newAtom.jsxNode.text !== oldAtom.jsxNode.text) {
|
|
1430
|
+
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode.text, newAtom.isSvg);
|
|
1431
|
+
}
|
|
1432
|
+
newAtom.nativeNode = nativeNode;
|
|
1433
|
+
context.host = nativeNode;
|
|
1434
|
+
context.isParent = false;
|
|
1435
|
+
};
|
|
1436
|
+
}
|
|
1437
|
+
function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer, context, parentComponent) {
|
|
1438
|
+
return function (offset) {
|
|
1439
|
+
newAtom.nativeNode = oldAtom.nativeNode;
|
|
1440
|
+
const host = context.host;
|
|
1441
|
+
if (expectIndex - offset !== oldIndex) {
|
|
1442
|
+
if (context.isParent) {
|
|
1443
|
+
nativeRenderer.prependChild(host, newAtom.nativeNode, newAtom.isSvg);
|
|
1444
|
+
}
|
|
1445
|
+
else {
|
|
1446
|
+
nativeRenderer.insertAfter(newAtom.nativeNode, host, newAtom.isSvg);
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
context.host = newAtom.nativeNode;
|
|
1450
|
+
context.isParent = false;
|
|
1451
|
+
const applyRefs = updateNativeNodeProperties(nativeRenderer, newAtom.jsxNode, oldAtom.jsxNode, newAtom.nativeNode, newAtom.isSvg);
|
|
1452
|
+
if (newAtom.child) {
|
|
1453
|
+
diff(nativeRenderer, parentComponent, newAtom.child, oldAtom.child, {
|
|
1454
|
+
host: newAtom.nativeNode,
|
|
1455
|
+
isParent: true
|
|
1456
|
+
}, 0, 0);
|
|
1457
|
+
}
|
|
1458
|
+
else if (oldAtom.child) {
|
|
1459
|
+
let atom = oldAtom.child;
|
|
1460
|
+
while (atom) {
|
|
1461
|
+
cleanView(nativeRenderer, atom, false);
|
|
1462
|
+
atom = atom.sibling;
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
applyRefs();
|
|
1466
|
+
};
|
|
1467
|
+
}
|
|
1468
|
+
function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRenderer, context) {
|
|
1469
|
+
return function (offset) {
|
|
1470
|
+
const instance = reusedAtom.jsxNode;
|
|
1471
|
+
const newProps = newAtom.jsxNode.props;
|
|
1472
|
+
const oldTemplate = instance.template;
|
|
1473
|
+
const newTemplate = instance.update(newProps);
|
|
1474
|
+
instance.$$view = Object.assign({ atom: newAtom }, context);
|
|
1475
|
+
newAtom.jsxNode = instance;
|
|
1476
|
+
if (newTemplate === oldTemplate) {
|
|
1477
|
+
reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
|
|
1478
|
+
updateView(nativeRenderer, instance);
|
|
1479
|
+
return;
|
|
1480
|
+
}
|
|
1481
|
+
if (newTemplate) {
|
|
1482
|
+
linkTemplate(newTemplate, newAtom.jsxNode, newAtom);
|
|
1483
|
+
}
|
|
1484
|
+
if (newAtom.child) {
|
|
1485
|
+
diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex);
|
|
1486
|
+
}
|
|
1487
|
+
else if (reusedAtom.child) {
|
|
1488
|
+
let atom = reusedAtom.child;
|
|
1489
|
+
while (atom) {
|
|
1490
|
+
cleanView(nativeRenderer, atom, false);
|
|
1491
|
+
atom = atom.sibling;
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
instance.rendered();
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1487
1497
|
function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
|
|
1488
1498
|
let child = reusedAtom.child;
|
|
1489
1499
|
newAtom.child = child;
|
|
@@ -1551,9 +1561,9 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
1551
1561
|
}
|
|
1552
1562
|
component.rendered();
|
|
1553
1563
|
}
|
|
1554
|
-
function
|
|
1564
|
+
function createChainByJSXComponentOrJSXText(jsxNode, parent, isSvg) {
|
|
1555
1565
|
return {
|
|
1556
|
-
jsxNode
|
|
1566
|
+
jsxNode,
|
|
1557
1567
|
parent,
|
|
1558
1568
|
sibling: null,
|
|
1559
1569
|
child: null,
|
|
@@ -1578,16 +1588,6 @@ function createChainByJSXElement(component, element, parent, isSvg) {
|
|
|
1578
1588
|
}
|
|
1579
1589
|
return atom;
|
|
1580
1590
|
}
|
|
1581
|
-
function createChainByJSXText(node, parent, isSvg) {
|
|
1582
|
-
return {
|
|
1583
|
-
jsxNode: node,
|
|
1584
|
-
parent,
|
|
1585
|
-
sibling: null,
|
|
1586
|
-
child: null,
|
|
1587
|
-
nativeNode: null,
|
|
1588
|
-
isSvg
|
|
1589
|
-
};
|
|
1590
|
-
}
|
|
1591
1591
|
function createChainByChildren(component, children, parent, atoms, isSvg) {
|
|
1592
1592
|
for (const item of children) {
|
|
1593
1593
|
if (item !== null && typeof item !== 'undefined' && typeof item !== 'boolean') {
|
|
@@ -1595,20 +1595,20 @@ function createChainByChildren(component, children, parent, atoms, isSvg) {
|
|
|
1595
1595
|
atoms.push(createChainByJSXElement(component, item, parent, isSvg));
|
|
1596
1596
|
continue;
|
|
1597
1597
|
}
|
|
1598
|
-
if (item instanceof JSXComponent) {
|
|
1599
|
-
const childAtom = createChainByComponentFactory(item, parent, isSvg);
|
|
1600
|
-
atoms.push(childAtom);
|
|
1601
|
-
continue;
|
|
1602
|
-
}
|
|
1603
1598
|
if (typeof item === 'string' && item.length) {
|
|
1604
|
-
atoms.push(
|
|
1599
|
+
atoms.push(createChainByJSXComponentOrJSXText(new JSXText(item), parent, isSvg));
|
|
1605
1600
|
continue;
|
|
1606
1601
|
}
|
|
1607
1602
|
if (Array.isArray(item)) {
|
|
1608
1603
|
createChainByChildren(component, item, parent, atoms, isSvg);
|
|
1609
1604
|
continue;
|
|
1610
1605
|
}
|
|
1611
|
-
|
|
1606
|
+
if (item instanceof JSXComponent) {
|
|
1607
|
+
const childAtom = createChainByJSXComponentOrJSXText(item, parent, isSvg);
|
|
1608
|
+
atoms.push(childAtom);
|
|
1609
|
+
continue;
|
|
1610
|
+
}
|
|
1611
|
+
atoms.push(createChainByJSXComponentOrJSXText(new JSXText(String(item)), parent, isSvg));
|
|
1612
1612
|
}
|
|
1613
1613
|
}
|
|
1614
1614
|
return atoms;
|
|
@@ -1629,8 +1629,7 @@ function createElement(nativeRenderer, vNode, isSvg) {
|
|
|
1629
1629
|
const nativeNode = nativeRenderer.createElement(vNode.type, isSvg);
|
|
1630
1630
|
const props = vNode.props;
|
|
1631
1631
|
let bindingRefs;
|
|
1632
|
-
const
|
|
1633
|
-
for (const key of keys) {
|
|
1632
|
+
for (const key in props) {
|
|
1634
1633
|
if (key === 'children') {
|
|
1635
1634
|
continue;
|
|
1636
1635
|
}
|
|
@@ -1643,9 +1642,9 @@ function createElement(nativeRenderer, vNode, isSvg) {
|
|
|
1643
1642
|
}
|
|
1644
1643
|
if (key === 'style') {
|
|
1645
1644
|
const style = styleToObject(props.style);
|
|
1646
|
-
|
|
1645
|
+
for (const key in style) {
|
|
1647
1646
|
nativeRenderer.setStyle(nativeNode, key, style[key], isSvg);
|
|
1648
|
-
}
|
|
1647
|
+
}
|
|
1649
1648
|
continue;
|
|
1650
1649
|
}
|
|
1651
1650
|
if (/^on[A-Z]/.test(key)) {
|
|
@@ -1685,9 +1684,9 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1685
1684
|
continue;
|
|
1686
1685
|
}
|
|
1687
1686
|
if (key === 'style') {
|
|
1688
|
-
|
|
1687
|
+
for (const styleName in styleToObject(value)) {
|
|
1689
1688
|
nativeRenderer.removeStyle(nativeNode, styleName, isSvg);
|
|
1690
|
-
}
|
|
1689
|
+
}
|
|
1691
1690
|
continue;
|
|
1692
1691
|
}
|
|
1693
1692
|
if (/^on[A-Z]/.test(key)) {
|
|
@@ -1749,9 +1748,9 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1749
1748
|
}
|
|
1750
1749
|
if (key === 'style') {
|
|
1751
1750
|
const styleObj = styleToObject(value);
|
|
1752
|
-
|
|
1751
|
+
for (const styleName in styleObj) {
|
|
1753
1752
|
nativeRenderer.setStyle(nativeNode, styleName, styleObj[styleName], isSvg);
|
|
1754
|
-
}
|
|
1753
|
+
}
|
|
1755
1754
|
continue;
|
|
1756
1755
|
}
|
|
1757
1756
|
if (/^on[A-Z]/.test(key)) {
|
|
@@ -1785,61 +1784,65 @@ function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn, isSvg) {
|
|
|
1785
1784
|
vNode.on = on = {};
|
|
1786
1785
|
}
|
|
1787
1786
|
const type = key.replace(/^on/, '').toLowerCase();
|
|
1788
|
-
const delegate = function (...args) {
|
|
1789
|
-
return delegateObj.listenFn.apply(this, args);
|
|
1790
|
-
};
|
|
1791
1787
|
const delegateObj = {
|
|
1792
|
-
delegate
|
|
1788
|
+
delegate(...args) {
|
|
1789
|
+
return delegateObj.listenFn.apply(this, args);
|
|
1790
|
+
},
|
|
1793
1791
|
listenFn
|
|
1794
1792
|
};
|
|
1795
1793
|
on[type] = delegateObj;
|
|
1796
|
-
nativeRenderer.listen(nativeNode, type, delegate, isSvg);
|
|
1794
|
+
nativeRenderer.listen(nativeNode, type, delegateObj.delegate, isSvg);
|
|
1797
1795
|
}
|
|
1798
1796
|
|
|
1799
1797
|
/**
|
|
1800
1798
|
* Viewfly 根组件,用于实现组件状态更新事件通知
|
|
1801
1799
|
*/
|
|
1802
1800
|
class RootComponent extends Component {
|
|
1803
|
-
constructor(parentInjector, factory) {
|
|
1801
|
+
constructor(parentInjector, factory, refresh) {
|
|
1804
1802
|
super(parentInjector, factory, {});
|
|
1805
|
-
this.
|
|
1803
|
+
this.refresh = refresh;
|
|
1806
1804
|
}
|
|
1807
1805
|
markAsChanged(changedComponent) {
|
|
1808
|
-
var _a;
|
|
1809
1806
|
this._changed = true;
|
|
1810
1807
|
if (changedComponent) {
|
|
1811
1808
|
this.changedSubComponents.add(changedComponent);
|
|
1812
1809
|
}
|
|
1813
|
-
|
|
1810
|
+
this.refresh();
|
|
1814
1811
|
}
|
|
1815
1812
|
}
|
|
1816
1813
|
|
|
1817
1814
|
const viewflyErrorFn = makeError('Viewfly');
|
|
1818
|
-
const VERSION = "0.3.1";
|
|
1819
1815
|
function viewfly(config) {
|
|
1820
1816
|
const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
|
|
1821
1817
|
const appProviders = [];
|
|
1822
1818
|
const modules = [];
|
|
1823
1819
|
let destroyed = false;
|
|
1820
|
+
let appHost = null;
|
|
1824
1821
|
const rootComponent = new RootComponent(context || null, () => {
|
|
1825
1822
|
provide(appProviders);
|
|
1826
1823
|
return () => {
|
|
1827
1824
|
return destroyed ? null : root;
|
|
1828
1825
|
};
|
|
1826
|
+
}, function () {
|
|
1827
|
+
if (destroyed) {
|
|
1828
|
+
return;
|
|
1829
|
+
}
|
|
1830
|
+
nextTick(() => {
|
|
1831
|
+
render(appHost);
|
|
1832
|
+
});
|
|
1829
1833
|
});
|
|
1830
|
-
const render = createRenderer(rootComponent, nativeRenderer
|
|
1834
|
+
const render = createRenderer(rootComponent, nativeRenderer);
|
|
1831
1835
|
let isStarted = false;
|
|
1832
1836
|
let task = null;
|
|
1833
1837
|
function nextTick(callback) {
|
|
1834
1838
|
if (task !== null) {
|
|
1835
1839
|
return;
|
|
1836
1840
|
}
|
|
1837
|
-
task =
|
|
1841
|
+
task = Promise.resolve().then(() => {
|
|
1838
1842
|
task = null;
|
|
1839
1843
|
callback();
|
|
1840
1844
|
});
|
|
1841
1845
|
}
|
|
1842
|
-
let appHost = null;
|
|
1843
1846
|
const app = {
|
|
1844
1847
|
provide(providers) {
|
|
1845
1848
|
if (Array.isArray(providers)) {
|
|
@@ -1876,15 +1879,6 @@ function viewfly(config) {
|
|
|
1876
1879
|
if (!autoUpdate) {
|
|
1877
1880
|
return app;
|
|
1878
1881
|
}
|
|
1879
|
-
const refresh = () => {
|
|
1880
|
-
if (destroyed) {
|
|
1881
|
-
return;
|
|
1882
|
-
}
|
|
1883
|
-
render(host);
|
|
1884
|
-
};
|
|
1885
|
-
rootComponent.onChange = function () {
|
|
1886
|
-
nextTick(refresh);
|
|
1887
|
-
};
|
|
1888
1882
|
return app;
|
|
1889
1883
|
},
|
|
1890
1884
|
render() {
|
|
@@ -1906,4 +1900,4 @@ function viewfly(config) {
|
|
|
1906
1900
|
return app;
|
|
1907
1901
|
}
|
|
1908
1902
|
|
|
1909
|
-
export { Component, ForwardRef, Fragment, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXComponent, JSXElement, JSXText, NativeRenderer, NullInjector, Optional, Prop, Ref, ReflectiveInjector, RootComponent, Scope, Self, SkipSelf, THROW_IF_NOT_FOUND, Type,
|
|
1903
|
+
export { Component, ForwardRef, Fragment, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXComponent, JSXElement, JSXText, NativeRenderer, NullInjector, Optional, Prop, Ref, ReflectiveInjector, RootComponent, Scope, Self, SkipSelf, THROW_IF_NOT_FOUND, Type, createRenderer, forwardRef, getCurrentInstance, inject, jsx, jsxs, makeError, normalizeProvider, onMounted, onPropsChanged, onUnmounted, onUpdated, provide, useDerived, useEffect, useRef, useSignal, viewfly, withMemo };
|
package/bundles/index.js
CHANGED
|
@@ -553,22 +553,22 @@ function getObjectChanges(newProps, oldProps) {
|
|
|
553
553
|
add: [],
|
|
554
554
|
replace: []
|
|
555
555
|
};
|
|
556
|
-
|
|
556
|
+
for (const key in newProps) {
|
|
557
557
|
const leftValue = newProps[key];
|
|
558
558
|
const rightValue = oldProps[key];
|
|
559
559
|
if (Reflect.has(oldProps, key)) {
|
|
560
560
|
if (leftValue !== rightValue) {
|
|
561
561
|
changes.replace.push([key, leftValue, rightValue]);
|
|
562
562
|
}
|
|
563
|
-
|
|
563
|
+
continue;
|
|
564
564
|
}
|
|
565
565
|
changes.add.push([key, leftValue]);
|
|
566
|
-
}
|
|
567
|
-
|
|
566
|
+
}
|
|
567
|
+
for (const key in oldProps) {
|
|
568
568
|
if (!Reflect.has(newProps, key)) {
|
|
569
569
|
changes.remove.push([key, oldProps[key]]);
|
|
570
570
|
}
|
|
571
|
-
}
|
|
571
|
+
}
|
|
572
572
|
return changes;
|
|
573
573
|
}
|
|
574
574
|
function getArrayChanges(left, right) {
|
|
@@ -676,7 +676,7 @@ class Component extends ReflectiveInjector {
|
|
|
676
676
|
this.propsChangedDestroyCallbacks = [];
|
|
677
677
|
this._dirty = true;
|
|
678
678
|
this._changed = true;
|
|
679
|
-
this.
|
|
679
|
+
this.isFirstRendering = true;
|
|
680
680
|
}
|
|
681
681
|
markAsDirtied() {
|
|
682
682
|
this._dirty = true;
|
|
@@ -777,15 +777,19 @@ class Component extends ReflectiveInjector {
|
|
|
777
777
|
}
|
|
778
778
|
rendered() {
|
|
779
779
|
this.changedSubComponents.clear();
|
|
780
|
-
const is = this.
|
|
781
|
-
this.
|
|
780
|
+
const is = this.isFirstRendering;
|
|
781
|
+
this.isFirstRendering = false;
|
|
782
782
|
this._dirty = this._changed = false;
|
|
783
|
+
this.invokeUpdatedHooks();
|
|
783
784
|
if (is) {
|
|
784
|
-
this.invokeUpdatedHooks();
|
|
785
785
|
this.invokeMountHooks();
|
|
786
786
|
}
|
|
787
|
-
|
|
788
|
-
|
|
787
|
+
if (this.changed) {
|
|
788
|
+
Promise.resolve().then(() => {
|
|
789
|
+
if (this.parentComponent instanceof Component) {
|
|
790
|
+
this.parentComponent.markAsChanged(this);
|
|
791
|
+
}
|
|
792
|
+
});
|
|
789
793
|
}
|
|
790
794
|
}
|
|
791
795
|
destroy() {
|
|
@@ -1217,11 +1221,10 @@ function withMemo(canUseMemo, render) {
|
|
|
1217
1221
|
};
|
|
1218
1222
|
}
|
|
1219
1223
|
|
|
1220
|
-
function createRenderer(component, nativeRenderer
|
|
1224
|
+
function createRenderer(component, nativeRenderer) {
|
|
1221
1225
|
let isInit = true;
|
|
1222
1226
|
return function render(host) {
|
|
1223
1227
|
if (isInit) {
|
|
1224
|
-
nativeRenderer.setProperty(host, 'viewfly-version', version, false);
|
|
1225
1228
|
isInit = false;
|
|
1226
1229
|
const atom = {
|
|
1227
1230
|
jsxNode: component,
|
|
@@ -1341,87 +1344,11 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1341
1344
|
}
|
|
1342
1345
|
}
|
|
1343
1346
|
const commits = [];
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
const instance = reusedAtom.jsxNode;
|
|
1348
|
-
const newProps = newAtom.jsxNode.props;
|
|
1349
|
-
const oldTemplate = instance.template;
|
|
1350
|
-
const newTemplate = instance.update(newProps);
|
|
1351
|
-
instance.$$view = Object.assign({ atom: newAtom }, context);
|
|
1352
|
-
newAtom.jsxNode = instance;
|
|
1353
|
-
if (newTemplate === oldTemplate) {
|
|
1354
|
-
reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
|
|
1355
|
-
updateView(nativeRenderer, instance);
|
|
1356
|
-
return;
|
|
1357
|
-
}
|
|
1358
|
-
if (newTemplate) {
|
|
1359
|
-
linkTemplate(newTemplate, newAtom.jsxNode, newAtom);
|
|
1360
|
-
}
|
|
1361
|
-
if (newAtom.child) {
|
|
1362
|
-
diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex);
|
|
1363
|
-
}
|
|
1364
|
-
else if (reusedAtom.child) {
|
|
1365
|
-
let atom = reusedAtom.child;
|
|
1366
|
-
while (atom) {
|
|
1367
|
-
cleanView(nativeRenderer, atom, false);
|
|
1368
|
-
atom = atom.sibling;
|
|
1369
|
-
}
|
|
1370
|
-
}
|
|
1371
|
-
instance.rendered();
|
|
1372
|
-
});
|
|
1373
|
-
},
|
|
1374
|
-
updateElement: (newAtom, oldAtom, expectIndex, oldIndex) => {
|
|
1375
|
-
commits.push((offset) => {
|
|
1376
|
-
newAtom.nativeNode = oldAtom.nativeNode;
|
|
1377
|
-
const host = context.host;
|
|
1378
|
-
if (expectIndex - offset !== oldIndex) {
|
|
1379
|
-
if (context.isParent) {
|
|
1380
|
-
nativeRenderer.prependChild(host, newAtom.nativeNode, newAtom.isSvg);
|
|
1381
|
-
}
|
|
1382
|
-
else {
|
|
1383
|
-
nativeRenderer.insertAfter(newAtom.nativeNode, host, newAtom.isSvg);
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
context.host = newAtom.nativeNode;
|
|
1387
|
-
context.isParent = false;
|
|
1388
|
-
const applyRefs = updateNativeNodeProperties(nativeRenderer, newAtom.jsxNode, oldAtom.jsxNode, newAtom.nativeNode, newAtom.isSvg);
|
|
1389
|
-
if (newAtom.child) {
|
|
1390
|
-
diff(nativeRenderer, parentComponent, newAtom.child, oldAtom.child, {
|
|
1391
|
-
host: newAtom.nativeNode,
|
|
1392
|
-
isParent: true
|
|
1393
|
-
}, 0, 0);
|
|
1394
|
-
}
|
|
1395
|
-
else if (oldAtom.child) {
|
|
1396
|
-
let atom = oldAtom.child;
|
|
1397
|
-
while (atom) {
|
|
1398
|
-
cleanView(nativeRenderer, atom, false);
|
|
1399
|
-
atom = atom.sibling;
|
|
1400
|
-
}
|
|
1401
|
-
}
|
|
1402
|
-
applyRefs();
|
|
1403
|
-
});
|
|
1404
|
-
},
|
|
1405
|
-
updateText: (newAtom, oldAtom) => {
|
|
1406
|
-
commits.push(() => {
|
|
1407
|
-
const nativeNode = oldAtom.nativeNode;
|
|
1408
|
-
if (newAtom.jsxNode.text !== oldAtom.jsxNode.text) {
|
|
1409
|
-
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode.text, newAtom.isSvg);
|
|
1410
|
-
}
|
|
1411
|
-
newAtom.nativeNode = nativeNode;
|
|
1412
|
-
context.host = nativeNode;
|
|
1413
|
-
context.isParent = false;
|
|
1414
|
-
});
|
|
1415
|
-
},
|
|
1416
|
-
create: (start) => {
|
|
1417
|
-
commits.push(() => {
|
|
1418
|
-
buildView(nativeRenderer, parentComponent, start, context);
|
|
1419
|
-
offset++;
|
|
1420
|
-
});
|
|
1421
|
-
}
|
|
1422
|
-
};
|
|
1347
|
+
function changeOffset() {
|
|
1348
|
+
offset++;
|
|
1349
|
+
}
|
|
1423
1350
|
while (newAtom) {
|
|
1424
|
-
firstDiffAtomIndexed = createChanges(newAtom, expectIndex, firstDiffAtomIndexed,
|
|
1351
|
+
firstDiffAtomIndexed = createChanges(newAtom, expectIndex, firstDiffAtomIndexed, nativeRenderer, commits, context, parentComponent, changeOffset);
|
|
1425
1352
|
newAtom = newAtom.sibling;
|
|
1426
1353
|
expectIndex++;
|
|
1427
1354
|
}
|
|
@@ -1444,28 +1371,34 @@ function diff(nativeRenderer, parentComponent, newAtom, oldAtom, context, expect
|
|
|
1444
1371
|
commit(offset);
|
|
1445
1372
|
}
|
|
1446
1373
|
}
|
|
1447
|
-
function createChanges(newAtom, expectIndex, diffAtomIndexed,
|
|
1374
|
+
function createChanges(newAtom, expectIndex, diffAtomIndexed, nativeRenderer, commits, context, parentComponent, effect) {
|
|
1448
1375
|
const startDiffAtom = diffAtomIndexed;
|
|
1376
|
+
const key = newAtom.jsxNode.key;
|
|
1449
1377
|
while (diffAtomIndexed) {
|
|
1450
1378
|
const { atom: diffAtom, index: diffIndex } = diffAtomIndexed;
|
|
1451
|
-
const key = newAtom.jsxNode.key;
|
|
1452
1379
|
const diffKey = diffAtom.jsxNode.key;
|
|
1453
|
-
if (key !== undefined
|
|
1380
|
+
if (key !== undefined) {
|
|
1454
1381
|
if (diffKey !== key) {
|
|
1455
1382
|
diffAtomIndexed = diffAtomIndexed.next;
|
|
1456
1383
|
continue;
|
|
1457
1384
|
}
|
|
1458
1385
|
}
|
|
1386
|
+
else if (diffKey !== undefined) {
|
|
1387
|
+
diffAtomIndexed = diffAtomIndexed.next;
|
|
1388
|
+
continue;
|
|
1389
|
+
}
|
|
1459
1390
|
if (newAtom.jsxNode.$$typeOf === diffAtom.jsxNode.$$typeOf) {
|
|
1391
|
+
let commit;
|
|
1460
1392
|
if (newAtom.jsxNode instanceof JSXElement) {
|
|
1461
|
-
|
|
1393
|
+
commit = updateElement(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context, parentComponent);
|
|
1462
1394
|
}
|
|
1463
1395
|
else if (newAtom.jsxNode instanceof JSXText) {
|
|
1464
|
-
|
|
1396
|
+
commit = updateText(newAtom, diffAtom, nativeRenderer, context);
|
|
1465
1397
|
}
|
|
1466
1398
|
else {
|
|
1467
|
-
|
|
1399
|
+
commit = updateComponent(newAtom, diffAtom, expectIndex, diffIndex, nativeRenderer, context);
|
|
1468
1400
|
}
|
|
1401
|
+
commits.push(commit);
|
|
1469
1402
|
const next = diffAtomIndexed.next;
|
|
1470
1403
|
const prev = diffAtomIndexed.prev;
|
|
1471
1404
|
if (!prev) {
|
|
@@ -1483,9 +1416,86 @@ function createChanges(newAtom, expectIndex, diffAtomIndexed, changeCommits) {
|
|
|
1483
1416
|
}
|
|
1484
1417
|
diffAtomIndexed = diffAtomIndexed.next;
|
|
1485
1418
|
}
|
|
1486
|
-
|
|
1419
|
+
commits.push(createNewView(newAtom, nativeRenderer, context, parentComponent, effect));
|
|
1487
1420
|
return startDiffAtom;
|
|
1488
1421
|
}
|
|
1422
|
+
function createNewView(start, nativeRenderer, context, parentComponent, effect) {
|
|
1423
|
+
return function () {
|
|
1424
|
+
buildView(nativeRenderer, parentComponent, start, context);
|
|
1425
|
+
effect();
|
|
1426
|
+
};
|
|
1427
|
+
}
|
|
1428
|
+
function updateText(newAtom, oldAtom, nativeRenderer, context) {
|
|
1429
|
+
return function () {
|
|
1430
|
+
const nativeNode = oldAtom.nativeNode;
|
|
1431
|
+
if (newAtom.jsxNode.text !== oldAtom.jsxNode.text) {
|
|
1432
|
+
nativeRenderer.syncTextContent(nativeNode, newAtom.jsxNode.text, newAtom.isSvg);
|
|
1433
|
+
}
|
|
1434
|
+
newAtom.nativeNode = nativeNode;
|
|
1435
|
+
context.host = nativeNode;
|
|
1436
|
+
context.isParent = false;
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1439
|
+
function updateElement(newAtom, oldAtom, expectIndex, oldIndex, nativeRenderer, context, parentComponent) {
|
|
1440
|
+
return function (offset) {
|
|
1441
|
+
newAtom.nativeNode = oldAtom.nativeNode;
|
|
1442
|
+
const host = context.host;
|
|
1443
|
+
if (expectIndex - offset !== oldIndex) {
|
|
1444
|
+
if (context.isParent) {
|
|
1445
|
+
nativeRenderer.prependChild(host, newAtom.nativeNode, newAtom.isSvg);
|
|
1446
|
+
}
|
|
1447
|
+
else {
|
|
1448
|
+
nativeRenderer.insertAfter(newAtom.nativeNode, host, newAtom.isSvg);
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
context.host = newAtom.nativeNode;
|
|
1452
|
+
context.isParent = false;
|
|
1453
|
+
const applyRefs = updateNativeNodeProperties(nativeRenderer, newAtom.jsxNode, oldAtom.jsxNode, newAtom.nativeNode, newAtom.isSvg);
|
|
1454
|
+
if (newAtom.child) {
|
|
1455
|
+
diff(nativeRenderer, parentComponent, newAtom.child, oldAtom.child, {
|
|
1456
|
+
host: newAtom.nativeNode,
|
|
1457
|
+
isParent: true
|
|
1458
|
+
}, 0, 0);
|
|
1459
|
+
}
|
|
1460
|
+
else if (oldAtom.child) {
|
|
1461
|
+
let atom = oldAtom.child;
|
|
1462
|
+
while (atom) {
|
|
1463
|
+
cleanView(nativeRenderer, atom, false);
|
|
1464
|
+
atom = atom.sibling;
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
applyRefs();
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
function updateComponent(newAtom, reusedAtom, expectIndex, oldIndex, nativeRenderer, context) {
|
|
1471
|
+
return function (offset) {
|
|
1472
|
+
const instance = reusedAtom.jsxNode;
|
|
1473
|
+
const newProps = newAtom.jsxNode.props;
|
|
1474
|
+
const oldTemplate = instance.template;
|
|
1475
|
+
const newTemplate = instance.update(newProps);
|
|
1476
|
+
instance.$$view = Object.assign({ atom: newAtom }, context);
|
|
1477
|
+
newAtom.jsxNode = instance;
|
|
1478
|
+
if (newTemplate === oldTemplate) {
|
|
1479
|
+
reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, expectIndex - offset !== oldIndex);
|
|
1480
|
+
updateView(nativeRenderer, instance);
|
|
1481
|
+
return;
|
|
1482
|
+
}
|
|
1483
|
+
if (newTemplate) {
|
|
1484
|
+
linkTemplate(newTemplate, newAtom.jsxNode, newAtom);
|
|
1485
|
+
}
|
|
1486
|
+
if (newAtom.child) {
|
|
1487
|
+
diff(nativeRenderer, instance, newAtom.child, reusedAtom.child, context, expectIndex, oldIndex);
|
|
1488
|
+
}
|
|
1489
|
+
else if (reusedAtom.child) {
|
|
1490
|
+
let atom = reusedAtom.child;
|
|
1491
|
+
while (atom) {
|
|
1492
|
+
cleanView(nativeRenderer, atom, false);
|
|
1493
|
+
atom = atom.sibling;
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
instance.rendered();
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1489
1499
|
function reuseComponentView(nativeRenderer, newAtom, reusedAtom, context, moveView) {
|
|
1490
1500
|
let child = reusedAtom.child;
|
|
1491
1501
|
newAtom.child = child;
|
|
@@ -1553,9 +1563,9 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
1553
1563
|
}
|
|
1554
1564
|
component.rendered();
|
|
1555
1565
|
}
|
|
1556
|
-
function
|
|
1566
|
+
function createChainByJSXComponentOrJSXText(jsxNode, parent, isSvg) {
|
|
1557
1567
|
return {
|
|
1558
|
-
jsxNode
|
|
1568
|
+
jsxNode,
|
|
1559
1569
|
parent,
|
|
1560
1570
|
sibling: null,
|
|
1561
1571
|
child: null,
|
|
@@ -1580,16 +1590,6 @@ function createChainByJSXElement(component, element, parent, isSvg) {
|
|
|
1580
1590
|
}
|
|
1581
1591
|
return atom;
|
|
1582
1592
|
}
|
|
1583
|
-
function createChainByJSXText(node, parent, isSvg) {
|
|
1584
|
-
return {
|
|
1585
|
-
jsxNode: node,
|
|
1586
|
-
parent,
|
|
1587
|
-
sibling: null,
|
|
1588
|
-
child: null,
|
|
1589
|
-
nativeNode: null,
|
|
1590
|
-
isSvg
|
|
1591
|
-
};
|
|
1592
|
-
}
|
|
1593
1593
|
function createChainByChildren(component, children, parent, atoms, isSvg) {
|
|
1594
1594
|
for (const item of children) {
|
|
1595
1595
|
if (item !== null && typeof item !== 'undefined' && typeof item !== 'boolean') {
|
|
@@ -1597,20 +1597,20 @@ function createChainByChildren(component, children, parent, atoms, isSvg) {
|
|
|
1597
1597
|
atoms.push(createChainByJSXElement(component, item, parent, isSvg));
|
|
1598
1598
|
continue;
|
|
1599
1599
|
}
|
|
1600
|
-
if (item instanceof JSXComponent) {
|
|
1601
|
-
const childAtom = createChainByComponentFactory(item, parent, isSvg);
|
|
1602
|
-
atoms.push(childAtom);
|
|
1603
|
-
continue;
|
|
1604
|
-
}
|
|
1605
1600
|
if (typeof item === 'string' && item.length) {
|
|
1606
|
-
atoms.push(
|
|
1601
|
+
atoms.push(createChainByJSXComponentOrJSXText(new JSXText(item), parent, isSvg));
|
|
1607
1602
|
continue;
|
|
1608
1603
|
}
|
|
1609
1604
|
if (Array.isArray(item)) {
|
|
1610
1605
|
createChainByChildren(component, item, parent, atoms, isSvg);
|
|
1611
1606
|
continue;
|
|
1612
1607
|
}
|
|
1613
|
-
|
|
1608
|
+
if (item instanceof JSXComponent) {
|
|
1609
|
+
const childAtom = createChainByJSXComponentOrJSXText(item, parent, isSvg);
|
|
1610
|
+
atoms.push(childAtom);
|
|
1611
|
+
continue;
|
|
1612
|
+
}
|
|
1613
|
+
atoms.push(createChainByJSXComponentOrJSXText(new JSXText(String(item)), parent, isSvg));
|
|
1614
1614
|
}
|
|
1615
1615
|
}
|
|
1616
1616
|
return atoms;
|
|
@@ -1631,8 +1631,7 @@ function createElement(nativeRenderer, vNode, isSvg) {
|
|
|
1631
1631
|
const nativeNode = nativeRenderer.createElement(vNode.type, isSvg);
|
|
1632
1632
|
const props = vNode.props;
|
|
1633
1633
|
let bindingRefs;
|
|
1634
|
-
const
|
|
1635
|
-
for (const key of keys) {
|
|
1634
|
+
for (const key in props) {
|
|
1636
1635
|
if (key === 'children') {
|
|
1637
1636
|
continue;
|
|
1638
1637
|
}
|
|
@@ -1645,9 +1644,9 @@ function createElement(nativeRenderer, vNode, isSvg) {
|
|
|
1645
1644
|
}
|
|
1646
1645
|
if (key === 'style') {
|
|
1647
1646
|
const style = styleToObject(props.style);
|
|
1648
|
-
|
|
1647
|
+
for (const key in style) {
|
|
1649
1648
|
nativeRenderer.setStyle(nativeNode, key, style[key], isSvg);
|
|
1650
|
-
}
|
|
1649
|
+
}
|
|
1651
1650
|
continue;
|
|
1652
1651
|
}
|
|
1653
1652
|
if (/^on[A-Z]/.test(key)) {
|
|
@@ -1687,9 +1686,9 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1687
1686
|
continue;
|
|
1688
1687
|
}
|
|
1689
1688
|
if (key === 'style') {
|
|
1690
|
-
|
|
1689
|
+
for (const styleName in styleToObject(value)) {
|
|
1691
1690
|
nativeRenderer.removeStyle(nativeNode, styleName, isSvg);
|
|
1692
|
-
}
|
|
1691
|
+
}
|
|
1693
1692
|
continue;
|
|
1694
1693
|
}
|
|
1695
1694
|
if (/^on[A-Z]/.test(key)) {
|
|
@@ -1751,9 +1750,9 @@ function updateNativeNodeProperties(nativeRenderer, newVNode, oldVNode, nativeNo
|
|
|
1751
1750
|
}
|
|
1752
1751
|
if (key === 'style') {
|
|
1753
1752
|
const styleObj = styleToObject(value);
|
|
1754
|
-
|
|
1753
|
+
for (const styleName in styleObj) {
|
|
1755
1754
|
nativeRenderer.setStyle(nativeNode, styleName, styleObj[styleName], isSvg);
|
|
1756
|
-
}
|
|
1755
|
+
}
|
|
1757
1756
|
continue;
|
|
1758
1757
|
}
|
|
1759
1758
|
if (/^on[A-Z]/.test(key)) {
|
|
@@ -1787,61 +1786,65 @@ function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn, isSvg) {
|
|
|
1787
1786
|
vNode.on = on = {};
|
|
1788
1787
|
}
|
|
1789
1788
|
const type = key.replace(/^on/, '').toLowerCase();
|
|
1790
|
-
const delegate = function (...args) {
|
|
1791
|
-
return delegateObj.listenFn.apply(this, args);
|
|
1792
|
-
};
|
|
1793
1789
|
const delegateObj = {
|
|
1794
|
-
delegate
|
|
1790
|
+
delegate(...args) {
|
|
1791
|
+
return delegateObj.listenFn.apply(this, args);
|
|
1792
|
+
},
|
|
1795
1793
|
listenFn
|
|
1796
1794
|
};
|
|
1797
1795
|
on[type] = delegateObj;
|
|
1798
|
-
nativeRenderer.listen(nativeNode, type, delegate, isSvg);
|
|
1796
|
+
nativeRenderer.listen(nativeNode, type, delegateObj.delegate, isSvg);
|
|
1799
1797
|
}
|
|
1800
1798
|
|
|
1801
1799
|
/**
|
|
1802
1800
|
* Viewfly 根组件,用于实现组件状态更新事件通知
|
|
1803
1801
|
*/
|
|
1804
1802
|
class RootComponent extends Component {
|
|
1805
|
-
constructor(parentInjector, factory) {
|
|
1803
|
+
constructor(parentInjector, factory, refresh) {
|
|
1806
1804
|
super(parentInjector, factory, {});
|
|
1807
|
-
this.
|
|
1805
|
+
this.refresh = refresh;
|
|
1808
1806
|
}
|
|
1809
1807
|
markAsChanged(changedComponent) {
|
|
1810
|
-
var _a;
|
|
1811
1808
|
this._changed = true;
|
|
1812
1809
|
if (changedComponent) {
|
|
1813
1810
|
this.changedSubComponents.add(changedComponent);
|
|
1814
1811
|
}
|
|
1815
|
-
|
|
1812
|
+
this.refresh();
|
|
1816
1813
|
}
|
|
1817
1814
|
}
|
|
1818
1815
|
|
|
1819
1816
|
const viewflyErrorFn = makeError('Viewfly');
|
|
1820
|
-
const VERSION = "0.3.1";
|
|
1821
1817
|
function viewfly(config) {
|
|
1822
1818
|
const { context, nativeRenderer, autoUpdate, root } = Object.assign({ autoUpdate: true }, config);
|
|
1823
1819
|
const appProviders = [];
|
|
1824
1820
|
const modules = [];
|
|
1825
1821
|
let destroyed = false;
|
|
1822
|
+
let appHost = null;
|
|
1826
1823
|
const rootComponent = new RootComponent(context || null, () => {
|
|
1827
1824
|
provide(appProviders);
|
|
1828
1825
|
return () => {
|
|
1829
1826
|
return destroyed ? null : root;
|
|
1830
1827
|
};
|
|
1828
|
+
}, function () {
|
|
1829
|
+
if (destroyed) {
|
|
1830
|
+
return;
|
|
1831
|
+
}
|
|
1832
|
+
nextTick(() => {
|
|
1833
|
+
render(appHost);
|
|
1834
|
+
});
|
|
1831
1835
|
});
|
|
1832
|
-
const render = createRenderer(rootComponent, nativeRenderer
|
|
1836
|
+
const render = createRenderer(rootComponent, nativeRenderer);
|
|
1833
1837
|
let isStarted = false;
|
|
1834
1838
|
let task = null;
|
|
1835
1839
|
function nextTick(callback) {
|
|
1836
1840
|
if (task !== null) {
|
|
1837
1841
|
return;
|
|
1838
1842
|
}
|
|
1839
|
-
task =
|
|
1843
|
+
task = Promise.resolve().then(() => {
|
|
1840
1844
|
task = null;
|
|
1841
1845
|
callback();
|
|
1842
1846
|
});
|
|
1843
1847
|
}
|
|
1844
|
-
let appHost = null;
|
|
1845
1848
|
const app = {
|
|
1846
1849
|
provide(providers) {
|
|
1847
1850
|
if (Array.isArray(providers)) {
|
|
@@ -1878,15 +1881,6 @@ function viewfly(config) {
|
|
|
1878
1881
|
if (!autoUpdate) {
|
|
1879
1882
|
return app;
|
|
1880
1883
|
}
|
|
1881
|
-
const refresh = () => {
|
|
1882
|
-
if (destroyed) {
|
|
1883
|
-
return;
|
|
1884
|
-
}
|
|
1885
|
-
render(host);
|
|
1886
|
-
};
|
|
1887
|
-
rootComponent.onChange = function () {
|
|
1888
|
-
nextTick(refresh);
|
|
1889
|
-
};
|
|
1890
1884
|
return app;
|
|
1891
1885
|
},
|
|
1892
1886
|
render() {
|
|
@@ -1930,7 +1924,6 @@ exports.Self = Self;
|
|
|
1930
1924
|
exports.SkipSelf = SkipSelf;
|
|
1931
1925
|
exports.THROW_IF_NOT_FOUND = THROW_IF_NOT_FOUND;
|
|
1932
1926
|
exports.Type = Type;
|
|
1933
|
-
exports.VERSION = VERSION;
|
|
1934
1927
|
exports.createRenderer = createRenderer;
|
|
1935
1928
|
exports.forwardRef = forwardRef;
|
|
1936
1929
|
exports.getCurrentInstance = getCurrentInstance;
|
package/bundles/viewfly.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Provider } from './di/_api';
|
|
2
2
|
import { JSXInternal, NativeNode, NativeRenderer } from './foundation/_api';
|
|
3
3
|
import { Injector } from './di/_api';
|
|
4
|
-
export declare const VERSION: string;
|
|
5
4
|
/**
|
|
6
5
|
* Viewfly 配置项
|
|
7
6
|
*/
|
|
@@ -17,7 +16,7 @@ export interface Config {
|
|
|
17
16
|
}
|
|
18
17
|
export interface Application<T extends NativeNode = NativeNode> {
|
|
19
18
|
provide(providers: Provider | Provider[]): Application<T>;
|
|
20
|
-
mount(host: T
|
|
19
|
+
mount(host: T): Application<T>;
|
|
21
20
|
use(module: Module | Module[]): Application<T>;
|
|
22
21
|
render(): Application<T>;
|
|
23
22
|
destroy(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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,7 +47,7 @@
|
|
|
47
47
|
"bugs": {
|
|
48
48
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "7ca289c06cf646dab99157efea91ae9220b2abfd",
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"reflect-metadata": "^0.1.13"
|
|
53
53
|
}
|