@viewfly/core 1.0.0-alpha.12 → 1.0.0-alpha.13
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/index.d.ts +38 -40
- package/bundles/index.esm.js +23 -62
- package/bundles/index.js +23 -62
- package/package.json +2 -2
package/bundles/index.d.ts
CHANGED
|
@@ -211,45 +211,6 @@ declare abstract class NativeRenderer<ElementNode = NativeNode, TextNode = Nativ
|
|
|
211
211
|
abstract insertAfter(newNode: ElementNode | TextNode, ref: ElementNode | TextNode, isSvg: boolean): void;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
interface ListenDelegate {
|
|
215
|
-
delegate: () => any;
|
|
216
|
-
listenFn: ((...args: any[]) => any) | void;
|
|
217
|
-
}
|
|
218
|
-
interface TextAtom {
|
|
219
|
-
type: 'text';
|
|
220
|
-
index: number;
|
|
221
|
-
jsxNode: string;
|
|
222
|
-
nativeNode: NativeNode | null;
|
|
223
|
-
child: Atom | null;
|
|
224
|
-
sibling: Atom | null;
|
|
225
|
-
isSvg: boolean;
|
|
226
|
-
}
|
|
227
|
-
interface ElementAtom {
|
|
228
|
-
type: 'element';
|
|
229
|
-
index: number;
|
|
230
|
-
jsxNode: JSXNode<string>;
|
|
231
|
-
nativeNode: NativeNode | null;
|
|
232
|
-
child: Atom | null;
|
|
233
|
-
sibling: Atom | null;
|
|
234
|
-
isSvg: boolean;
|
|
235
|
-
}
|
|
236
|
-
interface ComponentAtom {
|
|
237
|
-
type: 'component';
|
|
238
|
-
index: number;
|
|
239
|
-
jsxNode: JSXNode<JSXInternal.ComponentSetup> | Component;
|
|
240
|
-
nativeNode: NativeNode | null;
|
|
241
|
-
child: Atom | null;
|
|
242
|
-
sibling: Atom | null;
|
|
243
|
-
isSvg: boolean;
|
|
244
|
-
}
|
|
245
|
-
type Atom = TextAtom | ElementAtom | ComponentAtom;
|
|
246
|
-
interface ComponentView {
|
|
247
|
-
atom: Atom;
|
|
248
|
-
host: NativeNode;
|
|
249
|
-
isParent: boolean;
|
|
250
|
-
rootHost: NativeNode;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
214
|
interface Props {
|
|
254
215
|
children?: JSXInternal.ViewNode | JSXInternal.ViewNode[];
|
|
255
216
|
}
|
|
@@ -261,7 +222,6 @@ interface JSXNode<T = string | JSXInternal.ComponentSetup> {
|
|
|
261
222
|
type: T;
|
|
262
223
|
props: Props & Record<string, any>;
|
|
263
224
|
key?: Key;
|
|
264
|
-
on?: Record<string, ListenDelegate>;
|
|
265
225
|
}
|
|
266
226
|
declare const JSXNodeFactory: {
|
|
267
227
|
createNode<T = string | JSXInternal.ComponentSetup<any>>(type: T, props: Props & Record<string, any>, key?: Key): JSXNode<T>;
|
|
@@ -560,6 +520,44 @@ declare global {
|
|
|
560
520
|
}
|
|
561
521
|
}
|
|
562
522
|
|
|
523
|
+
declare const TextAtomType: unique symbol;
|
|
524
|
+
declare const ElementAtomType: unique symbol;
|
|
525
|
+
declare const ComponentAtomType: unique symbol;
|
|
526
|
+
interface TextAtom {
|
|
527
|
+
type: typeof TextAtomType;
|
|
528
|
+
index: number;
|
|
529
|
+
jsxNode: string;
|
|
530
|
+
nativeNode: NativeNode | null;
|
|
531
|
+
child: Atom | null;
|
|
532
|
+
sibling: Atom | null;
|
|
533
|
+
isSvg: boolean;
|
|
534
|
+
}
|
|
535
|
+
interface ElementAtom {
|
|
536
|
+
type: typeof ElementAtomType;
|
|
537
|
+
index: number;
|
|
538
|
+
jsxNode: JSXNode<string>;
|
|
539
|
+
nativeNode: NativeNode | null;
|
|
540
|
+
child: Atom | null;
|
|
541
|
+
sibling: Atom | null;
|
|
542
|
+
isSvg: boolean;
|
|
543
|
+
}
|
|
544
|
+
interface ComponentAtom {
|
|
545
|
+
type: typeof ComponentAtomType;
|
|
546
|
+
index: number;
|
|
547
|
+
jsxNode: JSXNode<JSXInternal.ComponentSetup> | Component;
|
|
548
|
+
nativeNode: NativeNode | null;
|
|
549
|
+
child: Atom | null;
|
|
550
|
+
sibling: Atom | null;
|
|
551
|
+
isSvg: boolean;
|
|
552
|
+
}
|
|
553
|
+
type Atom = TextAtom | ElementAtom | ComponentAtom;
|
|
554
|
+
interface ComponentView {
|
|
555
|
+
atom: Atom;
|
|
556
|
+
host: NativeNode;
|
|
557
|
+
isParent: boolean;
|
|
558
|
+
rootHost: NativeNode;
|
|
559
|
+
}
|
|
560
|
+
|
|
563
561
|
/**
|
|
564
562
|
* Viewfly 配置项
|
|
565
563
|
*/
|
package/bundles/index.esm.js
CHANGED
|
@@ -634,6 +634,9 @@ function styleToObject(style) {
|
|
|
634
634
|
});
|
|
635
635
|
return obj;
|
|
636
636
|
}
|
|
637
|
+
const TextAtomType = Symbol('Text');
|
|
638
|
+
const ElementAtomType = Symbol('Element');
|
|
639
|
+
const ComponentAtomType = Symbol('Component');
|
|
637
640
|
|
|
638
641
|
const componentSetupStack = [];
|
|
639
642
|
const signalDepsStack = [];
|
|
@@ -741,8 +744,9 @@ class Component extends ReflectiveInjector {
|
|
|
741
744
|
};
|
|
742
745
|
}
|
|
743
746
|
update(newProps, forceUpdate = false) {
|
|
747
|
+
const oldProps = this.props;
|
|
744
748
|
if (!forceUpdate) {
|
|
745
|
-
const { add, remove, replace } = getObjectChanges(newProps,
|
|
749
|
+
const { add, remove, replace } = getObjectChanges(newProps, oldProps);
|
|
746
750
|
if (add.length || remove.length || replace.length) {
|
|
747
751
|
this.invokePropsChangedHooks(newProps);
|
|
748
752
|
}
|
|
@@ -766,7 +770,7 @@ class Component extends ReflectiveInjector {
|
|
|
766
770
|
}
|
|
767
771
|
}
|
|
768
772
|
if (typeof this.instance.$useMemo === 'function') {
|
|
769
|
-
if (this.instance.$useMemo(newProps,
|
|
773
|
+
if (this.instance.$useMemo(newProps, oldProps)) {
|
|
770
774
|
return this.template;
|
|
771
775
|
}
|
|
772
776
|
}
|
|
@@ -1291,7 +1295,7 @@ function createRenderer(component, nativeRenderer) {
|
|
|
1291
1295
|
if (isInit) {
|
|
1292
1296
|
isInit = false;
|
|
1293
1297
|
const atom = {
|
|
1294
|
-
type:
|
|
1298
|
+
type: ComponentAtomType,
|
|
1295
1299
|
index: 0,
|
|
1296
1300
|
jsxNode: component,
|
|
1297
1301
|
sibling: null,
|
|
@@ -1312,12 +1316,12 @@ function createRenderer(component, nativeRenderer) {
|
|
|
1312
1316
|
}
|
|
1313
1317
|
function buildView(nativeRenderer, parentComponent, atom, context) {
|
|
1314
1318
|
const { jsxNode, type } = atom;
|
|
1315
|
-
if (type ===
|
|
1319
|
+
if (type === ComponentAtomType) {
|
|
1316
1320
|
const component = new Component(parentComponent, jsxNode.type, jsxNode.props, jsxNode.key);
|
|
1317
1321
|
atom.jsxNode = component;
|
|
1318
1322
|
componentRender(nativeRenderer, component, atom, context);
|
|
1319
1323
|
}
|
|
1320
|
-
else if (type ===
|
|
1324
|
+
else if (type === ElementAtomType) {
|
|
1321
1325
|
createElement(nativeRenderer, atom, parentComponent, context);
|
|
1322
1326
|
}
|
|
1323
1327
|
else {
|
|
@@ -1403,7 +1407,7 @@ function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, paren
|
|
|
1403
1407
|
const diffIndex = oldAtom.index;
|
|
1404
1408
|
if (type === oldAtom.type) {
|
|
1405
1409
|
let commit;
|
|
1406
|
-
if (type ===
|
|
1410
|
+
if (type === TextAtomType) {
|
|
1407
1411
|
commit = updateText(newAtom, oldAtom, nativeRenderer, context);
|
|
1408
1412
|
}
|
|
1409
1413
|
else {
|
|
@@ -1413,7 +1417,7 @@ function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, paren
|
|
|
1413
1417
|
oldAtom = oldAtom.sibling;
|
|
1414
1418
|
continue;
|
|
1415
1419
|
}
|
|
1416
|
-
if (type ===
|
|
1420
|
+
if (type === ComponentAtomType) {
|
|
1417
1421
|
commit = updateComponent(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context);
|
|
1418
1422
|
}
|
|
1419
1423
|
else {
|
|
@@ -1531,7 +1535,7 @@ function cleanView(nativeRenderer, atom, needClean) {
|
|
|
1531
1535
|
nativeRenderer.remove(atom.nativeNode, atom.isSvg);
|
|
1532
1536
|
needClean = false;
|
|
1533
1537
|
}
|
|
1534
|
-
if (atom.type ===
|
|
1538
|
+
if (atom.type === ElementAtomType) {
|
|
1535
1539
|
const ref = atom.jsxNode.props[refKey];
|
|
1536
1540
|
applyRefs(ref, atom.nativeNode, false);
|
|
1537
1541
|
}
|
|
@@ -1560,9 +1564,9 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
1560
1564
|
}
|
|
1561
1565
|
component.rendered();
|
|
1562
1566
|
}
|
|
1563
|
-
function
|
|
1567
|
+
function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
|
|
1564
1568
|
const atom = {
|
|
1565
|
-
type
|
|
1569
|
+
type,
|
|
1566
1570
|
index: prevAtom.index + 1,
|
|
1567
1571
|
jsxNode,
|
|
1568
1572
|
sibling: null,
|
|
@@ -1573,38 +1577,11 @@ function createChainByJSXComponent(jsxNode, prevAtom, isSvg) {
|
|
|
1573
1577
|
prevAtom.sibling = atom;
|
|
1574
1578
|
return atom;
|
|
1575
1579
|
}
|
|
1576
|
-
function createChainByJSXText(jsxNode, prevAtom, isSvg) {
|
|
1577
|
-
const atom = {
|
|
1578
|
-
type: 'text',
|
|
1579
|
-
index: prevAtom.index + 1,
|
|
1580
|
-
jsxNode,
|
|
1581
|
-
sibling: null,
|
|
1582
|
-
child: null,
|
|
1583
|
-
nativeNode: null,
|
|
1584
|
-
isSvg
|
|
1585
|
-
};
|
|
1586
|
-
prevAtom.sibling = atom;
|
|
1587
|
-
return atom;
|
|
1588
|
-
}
|
|
1589
|
-
function createChainByJSXElement(element, prevAtom, isSvg) {
|
|
1590
|
-
isSvg = isSvg || element.type === 'svg';
|
|
1591
|
-
const atom = {
|
|
1592
|
-
type: 'element',
|
|
1593
|
-
index: prevAtom.index + 1,
|
|
1594
|
-
jsxNode: element,
|
|
1595
|
-
sibling: null,
|
|
1596
|
-
child: null,
|
|
1597
|
-
nativeNode: null,
|
|
1598
|
-
isSvg
|
|
1599
|
-
};
|
|
1600
|
-
prevAtom.sibling = atom;
|
|
1601
|
-
return atom;
|
|
1602
|
-
}
|
|
1603
1580
|
function createChainByNode(jsxNode, prevAtom, isSvg) {
|
|
1604
1581
|
const type = typeof jsxNode;
|
|
1605
1582
|
if (jsxNode !== null && type !== 'undefined' && type !== 'boolean') {
|
|
1606
1583
|
if (typeof jsxNode === 'string') {
|
|
1607
|
-
return
|
|
1584
|
+
return createChainByJSXNode(TextAtomType, jsxNode, prevAtom, isSvg);
|
|
1608
1585
|
}
|
|
1609
1586
|
if (Array.isArray(jsxNode)) {
|
|
1610
1587
|
return createChainByChildren(jsxNode, prevAtom, isSvg);
|
|
@@ -1612,13 +1589,13 @@ function createChainByNode(jsxNode, prevAtom, isSvg) {
|
|
|
1612
1589
|
if (type === 'object') {
|
|
1613
1590
|
const nodeType = typeof jsxNode.type;
|
|
1614
1591
|
if (nodeType === 'string') {
|
|
1615
|
-
return
|
|
1592
|
+
return createChainByJSXNode(ElementAtomType, jsxNode, prevAtom, isSvg || jsxNode.type === 'svg');
|
|
1616
1593
|
}
|
|
1617
1594
|
else if (nodeType === 'function') {
|
|
1618
|
-
return
|
|
1595
|
+
return createChainByJSXNode(ComponentAtomType, jsxNode, prevAtom, isSvg);
|
|
1619
1596
|
}
|
|
1620
1597
|
}
|
|
1621
|
-
return
|
|
1598
|
+
return createChainByJSXNode(TextAtomType, String(jsxNode), prevAtom, isSvg);
|
|
1622
1599
|
}
|
|
1623
1600
|
return prevAtom;
|
|
1624
1601
|
}
|
|
@@ -1673,7 +1650,7 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
|
|
|
1673
1650
|
if (listenerReg.test(key)) {
|
|
1674
1651
|
const listener = props[key];
|
|
1675
1652
|
if (typeof listener === 'function') {
|
|
1676
|
-
|
|
1653
|
+
nativeRenderer.listen(nativeNode, key, listener, isSvg);
|
|
1677
1654
|
}
|
|
1678
1655
|
continue;
|
|
1679
1656
|
}
|
|
@@ -1711,7 +1688,6 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1711
1688
|
const changes = getObjectChanges(newVNode.props, oldVNode.props);
|
|
1712
1689
|
let unBindRefs;
|
|
1713
1690
|
let bindRefs;
|
|
1714
|
-
newVNode.on = oldVNode.on;
|
|
1715
1691
|
newAtom.child = oldAtom.child;
|
|
1716
1692
|
for (const [key, value] of changes.remove) {
|
|
1717
1693
|
if (key === 'children') {
|
|
@@ -1731,9 +1707,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1731
1707
|
}
|
|
1732
1708
|
if (listenerReg.test(key)) {
|
|
1733
1709
|
if (typeof value === 'function') {
|
|
1734
|
-
|
|
1735
|
-
nativeRenderer.unListen(nativeNode, key, oldOn[key].delegate, isSvg);
|
|
1736
|
-
Reflect.deleteProperty(oldOn, key);
|
|
1710
|
+
nativeRenderer.unListen(nativeNode, key, value, isSvg);
|
|
1737
1711
|
}
|
|
1738
1712
|
continue;
|
|
1739
1713
|
}
|
|
@@ -1777,7 +1751,8 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1777
1751
|
continue;
|
|
1778
1752
|
}
|
|
1779
1753
|
if (listenerReg.test(key)) {
|
|
1780
|
-
|
|
1754
|
+
nativeRenderer.unListen(nativeNode, key, oldValue, isSvg);
|
|
1755
|
+
nativeRenderer.listen(nativeNode, key, newValue, isSvg);
|
|
1781
1756
|
continue;
|
|
1782
1757
|
}
|
|
1783
1758
|
if (key === refKey) {
|
|
@@ -1806,7 +1781,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1806
1781
|
}
|
|
1807
1782
|
if (listenerReg.test(key)) {
|
|
1808
1783
|
if (typeof value === 'function') {
|
|
1809
|
-
|
|
1784
|
+
nativeRenderer.listen(nativeNode, key, value, isSvg);
|
|
1810
1785
|
}
|
|
1811
1786
|
continue;
|
|
1812
1787
|
}
|
|
@@ -1829,20 +1804,6 @@ function applyRefs(refs, nativeNode, binding) {
|
|
|
1829
1804
|
}
|
|
1830
1805
|
}
|
|
1831
1806
|
}
|
|
1832
|
-
function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn, isSvg) {
|
|
1833
|
-
let on = vNode.on;
|
|
1834
|
-
if (!on) {
|
|
1835
|
-
vNode.on = on = {};
|
|
1836
|
-
}
|
|
1837
|
-
const delegateObj = {
|
|
1838
|
-
delegate(...args) {
|
|
1839
|
-
return delegateObj.listenFn.apply(this, args);
|
|
1840
|
-
},
|
|
1841
|
-
listenFn
|
|
1842
|
-
};
|
|
1843
|
-
on[key] = delegateObj;
|
|
1844
|
-
nativeRenderer.listen(nativeNode, key, delegateObj.delegate, isSvg);
|
|
1845
|
-
}
|
|
1846
1807
|
|
|
1847
1808
|
/**
|
|
1848
1809
|
* Viewfly 根组件,用于实现组件状态更新事件通知
|
package/bundles/index.js
CHANGED
|
@@ -636,6 +636,9 @@ function styleToObject(style) {
|
|
|
636
636
|
});
|
|
637
637
|
return obj;
|
|
638
638
|
}
|
|
639
|
+
const TextAtomType = Symbol('Text');
|
|
640
|
+
const ElementAtomType = Symbol('Element');
|
|
641
|
+
const ComponentAtomType = Symbol('Component');
|
|
639
642
|
|
|
640
643
|
const componentSetupStack = [];
|
|
641
644
|
const signalDepsStack = [];
|
|
@@ -743,8 +746,9 @@ class Component extends ReflectiveInjector {
|
|
|
743
746
|
};
|
|
744
747
|
}
|
|
745
748
|
update(newProps, forceUpdate = false) {
|
|
749
|
+
const oldProps = this.props;
|
|
746
750
|
if (!forceUpdate) {
|
|
747
|
-
const { add, remove, replace } = getObjectChanges(newProps,
|
|
751
|
+
const { add, remove, replace } = getObjectChanges(newProps, oldProps);
|
|
748
752
|
if (add.length || remove.length || replace.length) {
|
|
749
753
|
this.invokePropsChangedHooks(newProps);
|
|
750
754
|
}
|
|
@@ -768,7 +772,7 @@ class Component extends ReflectiveInjector {
|
|
|
768
772
|
}
|
|
769
773
|
}
|
|
770
774
|
if (typeof this.instance.$useMemo === 'function') {
|
|
771
|
-
if (this.instance.$useMemo(newProps,
|
|
775
|
+
if (this.instance.$useMemo(newProps, oldProps)) {
|
|
772
776
|
return this.template;
|
|
773
777
|
}
|
|
774
778
|
}
|
|
@@ -1293,7 +1297,7 @@ function createRenderer(component, nativeRenderer) {
|
|
|
1293
1297
|
if (isInit) {
|
|
1294
1298
|
isInit = false;
|
|
1295
1299
|
const atom = {
|
|
1296
|
-
type:
|
|
1300
|
+
type: ComponentAtomType,
|
|
1297
1301
|
index: 0,
|
|
1298
1302
|
jsxNode: component,
|
|
1299
1303
|
sibling: null,
|
|
@@ -1314,12 +1318,12 @@ function createRenderer(component, nativeRenderer) {
|
|
|
1314
1318
|
}
|
|
1315
1319
|
function buildView(nativeRenderer, parentComponent, atom, context) {
|
|
1316
1320
|
const { jsxNode, type } = atom;
|
|
1317
|
-
if (type ===
|
|
1321
|
+
if (type === ComponentAtomType) {
|
|
1318
1322
|
const component = new Component(parentComponent, jsxNode.type, jsxNode.props, jsxNode.key);
|
|
1319
1323
|
atom.jsxNode = component;
|
|
1320
1324
|
componentRender(nativeRenderer, component, atom, context);
|
|
1321
1325
|
}
|
|
1322
|
-
else if (type ===
|
|
1326
|
+
else if (type === ElementAtomType) {
|
|
1323
1327
|
createElement(nativeRenderer, atom, parentComponent, context);
|
|
1324
1328
|
}
|
|
1325
1329
|
else {
|
|
@@ -1405,7 +1409,7 @@ function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, paren
|
|
|
1405
1409
|
const diffIndex = oldAtom.index;
|
|
1406
1410
|
if (type === oldAtom.type) {
|
|
1407
1411
|
let commit;
|
|
1408
|
-
if (type ===
|
|
1412
|
+
if (type === TextAtomType) {
|
|
1409
1413
|
commit = updateText(newAtom, oldAtom, nativeRenderer, context);
|
|
1410
1414
|
}
|
|
1411
1415
|
else {
|
|
@@ -1415,7 +1419,7 @@ function createChanges(newAtom, oldAtom, nativeRenderer, commits, context, paren
|
|
|
1415
1419
|
oldAtom = oldAtom.sibling;
|
|
1416
1420
|
continue;
|
|
1417
1421
|
}
|
|
1418
|
-
if (type ===
|
|
1422
|
+
if (type === ComponentAtomType) {
|
|
1419
1423
|
commit = updateComponent(newAtom, oldAtom, newAtom.index, diffIndex, nativeRenderer, context);
|
|
1420
1424
|
}
|
|
1421
1425
|
else {
|
|
@@ -1533,7 +1537,7 @@ function cleanView(nativeRenderer, atom, needClean) {
|
|
|
1533
1537
|
nativeRenderer.remove(atom.nativeNode, atom.isSvg);
|
|
1534
1538
|
needClean = false;
|
|
1535
1539
|
}
|
|
1536
|
-
if (atom.type ===
|
|
1540
|
+
if (atom.type === ElementAtomType) {
|
|
1537
1541
|
const ref = atom.jsxNode.props[refKey];
|
|
1538
1542
|
applyRefs(ref, atom.nativeNode, false);
|
|
1539
1543
|
}
|
|
@@ -1562,9 +1566,9 @@ function componentRender(nativeRenderer, component, from, context) {
|
|
|
1562
1566
|
}
|
|
1563
1567
|
component.rendered();
|
|
1564
1568
|
}
|
|
1565
|
-
function
|
|
1569
|
+
function createChainByJSXNode(type, jsxNode, prevAtom, isSvg) {
|
|
1566
1570
|
const atom = {
|
|
1567
|
-
type
|
|
1571
|
+
type,
|
|
1568
1572
|
index: prevAtom.index + 1,
|
|
1569
1573
|
jsxNode,
|
|
1570
1574
|
sibling: null,
|
|
@@ -1575,38 +1579,11 @@ function createChainByJSXComponent(jsxNode, prevAtom, isSvg) {
|
|
|
1575
1579
|
prevAtom.sibling = atom;
|
|
1576
1580
|
return atom;
|
|
1577
1581
|
}
|
|
1578
|
-
function createChainByJSXText(jsxNode, prevAtom, isSvg) {
|
|
1579
|
-
const atom = {
|
|
1580
|
-
type: 'text',
|
|
1581
|
-
index: prevAtom.index + 1,
|
|
1582
|
-
jsxNode,
|
|
1583
|
-
sibling: null,
|
|
1584
|
-
child: null,
|
|
1585
|
-
nativeNode: null,
|
|
1586
|
-
isSvg
|
|
1587
|
-
};
|
|
1588
|
-
prevAtom.sibling = atom;
|
|
1589
|
-
return atom;
|
|
1590
|
-
}
|
|
1591
|
-
function createChainByJSXElement(element, prevAtom, isSvg) {
|
|
1592
|
-
isSvg = isSvg || element.type === 'svg';
|
|
1593
|
-
const atom = {
|
|
1594
|
-
type: 'element',
|
|
1595
|
-
index: prevAtom.index + 1,
|
|
1596
|
-
jsxNode: element,
|
|
1597
|
-
sibling: null,
|
|
1598
|
-
child: null,
|
|
1599
|
-
nativeNode: null,
|
|
1600
|
-
isSvg
|
|
1601
|
-
};
|
|
1602
|
-
prevAtom.sibling = atom;
|
|
1603
|
-
return atom;
|
|
1604
|
-
}
|
|
1605
1582
|
function createChainByNode(jsxNode, prevAtom, isSvg) {
|
|
1606
1583
|
const type = typeof jsxNode;
|
|
1607
1584
|
if (jsxNode !== null && type !== 'undefined' && type !== 'boolean') {
|
|
1608
1585
|
if (typeof jsxNode === 'string') {
|
|
1609
|
-
return
|
|
1586
|
+
return createChainByJSXNode(TextAtomType, jsxNode, prevAtom, isSvg);
|
|
1610
1587
|
}
|
|
1611
1588
|
if (Array.isArray(jsxNode)) {
|
|
1612
1589
|
return createChainByChildren(jsxNode, prevAtom, isSvg);
|
|
@@ -1614,13 +1591,13 @@ function createChainByNode(jsxNode, prevAtom, isSvg) {
|
|
|
1614
1591
|
if (type === 'object') {
|
|
1615
1592
|
const nodeType = typeof jsxNode.type;
|
|
1616
1593
|
if (nodeType === 'string') {
|
|
1617
|
-
return
|
|
1594
|
+
return createChainByJSXNode(ElementAtomType, jsxNode, prevAtom, isSvg || jsxNode.type === 'svg');
|
|
1618
1595
|
}
|
|
1619
1596
|
else if (nodeType === 'function') {
|
|
1620
|
-
return
|
|
1597
|
+
return createChainByJSXNode(ComponentAtomType, jsxNode, prevAtom, isSvg);
|
|
1621
1598
|
}
|
|
1622
1599
|
}
|
|
1623
|
-
return
|
|
1600
|
+
return createChainByJSXNode(TextAtomType, String(jsxNode), prevAtom, isSvg);
|
|
1624
1601
|
}
|
|
1625
1602
|
return prevAtom;
|
|
1626
1603
|
}
|
|
@@ -1675,7 +1652,7 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
|
|
|
1675
1652
|
if (listenerReg.test(key)) {
|
|
1676
1653
|
const listener = props[key];
|
|
1677
1654
|
if (typeof listener === 'function') {
|
|
1678
|
-
|
|
1655
|
+
nativeRenderer.listen(nativeNode, key, listener, isSvg);
|
|
1679
1656
|
}
|
|
1680
1657
|
continue;
|
|
1681
1658
|
}
|
|
@@ -1713,7 +1690,6 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1713
1690
|
const changes = getObjectChanges(newVNode.props, oldVNode.props);
|
|
1714
1691
|
let unBindRefs;
|
|
1715
1692
|
let bindRefs;
|
|
1716
|
-
newVNode.on = oldVNode.on;
|
|
1717
1693
|
newAtom.child = oldAtom.child;
|
|
1718
1694
|
for (const [key, value] of changes.remove) {
|
|
1719
1695
|
if (key === 'children') {
|
|
@@ -1733,9 +1709,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1733
1709
|
}
|
|
1734
1710
|
if (listenerReg.test(key)) {
|
|
1735
1711
|
if (typeof value === 'function') {
|
|
1736
|
-
|
|
1737
|
-
nativeRenderer.unListen(nativeNode, key, oldOn[key].delegate, isSvg);
|
|
1738
|
-
Reflect.deleteProperty(oldOn, key);
|
|
1712
|
+
nativeRenderer.unListen(nativeNode, key, value, isSvg);
|
|
1739
1713
|
}
|
|
1740
1714
|
continue;
|
|
1741
1715
|
}
|
|
@@ -1779,7 +1753,8 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1779
1753
|
continue;
|
|
1780
1754
|
}
|
|
1781
1755
|
if (listenerReg.test(key)) {
|
|
1782
|
-
|
|
1756
|
+
nativeRenderer.unListen(nativeNode, key, oldValue, isSvg);
|
|
1757
|
+
nativeRenderer.listen(nativeNode, key, newValue, isSvg);
|
|
1783
1758
|
continue;
|
|
1784
1759
|
}
|
|
1785
1760
|
if (key === refKey) {
|
|
@@ -1808,7 +1783,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
1808
1783
|
}
|
|
1809
1784
|
if (listenerReg.test(key)) {
|
|
1810
1785
|
if (typeof value === 'function') {
|
|
1811
|
-
|
|
1786
|
+
nativeRenderer.listen(nativeNode, key, value, isSvg);
|
|
1812
1787
|
}
|
|
1813
1788
|
continue;
|
|
1814
1789
|
}
|
|
@@ -1831,20 +1806,6 @@ function applyRefs(refs, nativeNode, binding) {
|
|
|
1831
1806
|
}
|
|
1832
1807
|
}
|
|
1833
1808
|
}
|
|
1834
|
-
function bindEvent(nativeRenderer, vNode, key, nativeNode, listenFn, isSvg) {
|
|
1835
|
-
let on = vNode.on;
|
|
1836
|
-
if (!on) {
|
|
1837
|
-
vNode.on = on = {};
|
|
1838
|
-
}
|
|
1839
|
-
const delegateObj = {
|
|
1840
|
-
delegate(...args) {
|
|
1841
|
-
return delegateObj.listenFn.apply(this, args);
|
|
1842
|
-
},
|
|
1843
|
-
listenFn
|
|
1844
|
-
};
|
|
1845
|
-
on[key] = delegateObj;
|
|
1846
|
-
nativeRenderer.listen(nativeNode, key, delegateObj.delegate, isSvg);
|
|
1847
|
-
}
|
|
1848
1809
|
|
|
1849
1810
|
/**
|
|
1850
1811
|
* Viewfly 根组件,用于实现组件状态更新事件通知
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/core",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.13",
|
|
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": "
|
|
53
|
+
"gitHead": "ef79169385a2b104fc58cb0b38123443e5baccd7",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"reflect-metadata": "^0.2.2"
|
|
56
56
|
}
|