my-framework-almaz 2.0.5 → 2.0.7
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/dist/my-framework-almaz.js +18 -21
- package/package.json +1 -1
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
function addEventListener
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
el.addEventListener(eventName, boundHandler);
|
|
6
|
-
return boundHandler
|
|
1
|
+
function addEventListener(eventName, handler, el) {
|
|
2
|
+
el.addEventListener(eventName, handler);
|
|
3
|
+
return handler
|
|
7
4
|
}
|
|
8
5
|
function addEventListeners(listeners = {}, el) {
|
|
9
6
|
const addedListeners = {};
|
|
10
7
|
Object.entries(listeners).forEach(([eventName, handler]) => {
|
|
11
|
-
const listener = addEventListener
|
|
8
|
+
const listener = addEventListener(eventName, handler, el);
|
|
12
9
|
addedListeners[eventName] = listener;
|
|
13
10
|
});
|
|
14
11
|
return addedListeners
|
|
@@ -182,14 +179,14 @@ function mapTextNodes(children) {
|
|
|
182
179
|
typeof child === 'string' ? hString(child) : child
|
|
183
180
|
)
|
|
184
181
|
}
|
|
185
|
-
function
|
|
182
|
+
function extractChildren(vdom) {
|
|
186
183
|
if (vdom.children == null) {
|
|
187
184
|
return []
|
|
188
185
|
}
|
|
189
186
|
const children = [];
|
|
190
187
|
for (const child of vdom.children) {
|
|
191
188
|
if (child.type === DOM_TYPES.FRAGMENT) {
|
|
192
|
-
children.push(...
|
|
189
|
+
children.push(...extractChildren(child));
|
|
193
190
|
} else {
|
|
194
191
|
children.push(child);
|
|
195
192
|
}
|
|
@@ -402,7 +399,7 @@ function isNotEmptyString(str) {
|
|
|
402
399
|
return str !== ''
|
|
403
400
|
}
|
|
404
401
|
function isNotBlankOrEmptyString(str) {
|
|
405
|
-
isNotEmptyString(str.trim())
|
|
402
|
+
return isNotEmptyString(str.trim())
|
|
406
403
|
}
|
|
407
404
|
|
|
408
405
|
function patchDOM(oldVdom, newVdom, parentEl) {
|
|
@@ -444,20 +441,20 @@ function patchText(oldVdom, newVdom) {
|
|
|
444
441
|
function patchElement(oldVdom, newVdom) {
|
|
445
442
|
const el = oldVdom.el;
|
|
446
443
|
const {
|
|
447
|
-
class:
|
|
444
|
+
class: oldClass,
|
|
448
445
|
style: oldStyle,
|
|
449
446
|
on: oldEvents,
|
|
450
447
|
...oldAttrs
|
|
451
448
|
} = oldVdom.props;
|
|
452
449
|
const {
|
|
453
|
-
class:
|
|
450
|
+
class: newClass,
|
|
454
451
|
style: newStyle,
|
|
455
452
|
on: newEvents,
|
|
456
453
|
...newAttrs
|
|
457
454
|
} = newVdom.props;
|
|
458
455
|
const { listeners: oldListeners } = oldVdom;
|
|
459
456
|
patchAttrs(el, oldAttrs, newAttrs);
|
|
460
|
-
|
|
457
|
+
patchClasses(el, oldClass, newClass);
|
|
461
458
|
patchStyles(el, oldStyle, newStyle);
|
|
462
459
|
newVdom.listeners = patchEvents(el, oldListeners, oldEvents, newEvents);
|
|
463
460
|
}
|
|
@@ -470,7 +467,7 @@ function patchAttrs(el, oldAttrs, newAttrs) {
|
|
|
470
467
|
setAttribute(el, attr, newAttrs[attr]);
|
|
471
468
|
}
|
|
472
469
|
}
|
|
473
|
-
function
|
|
470
|
+
function patchClasses(el, oldClass, newClass) {
|
|
474
471
|
const oldClasses = toClassList(oldClass);
|
|
475
472
|
const newClasses = toClassList(newClass);
|
|
476
473
|
const { added, removed } = arraysDiff(oldClasses, newClasses);
|
|
@@ -481,6 +478,11 @@ function patchCalsses(el, oldClass, newClass) {
|
|
|
481
478
|
el.classList.add(...added);
|
|
482
479
|
}
|
|
483
480
|
}
|
|
481
|
+
function toClassList(classes = '') {
|
|
482
|
+
return Array.isArray(classes)
|
|
483
|
+
? classes.filter(isNotBlankOrEmptyString)
|
|
484
|
+
: classes.split(/(\s+)/).filter(isNotBlankOrEmptyString)
|
|
485
|
+
}
|
|
484
486
|
function patchStyles(el, oldStyle = {}, newStyle = {}) {
|
|
485
487
|
const { added, removed, updated } = objectsDiff(oldStyle, newStyle);
|
|
486
488
|
for (const style of removed) {
|
|
@@ -507,14 +509,9 @@ function patchEvents(
|
|
|
507
509
|
}
|
|
508
510
|
return addedListeneres
|
|
509
511
|
}
|
|
510
|
-
function toClassList(classes = '') {
|
|
511
|
-
return Array.isArray(classes)
|
|
512
|
-
? classes.filter(isNotBlankOrEmptyString)
|
|
513
|
-
: classes.split(/(\s+)/).filter(isNotBlankOrEmptyString)
|
|
514
|
-
}
|
|
515
512
|
function patchChildren(oldVdom, newVdom) {
|
|
516
|
-
const oldChildren =
|
|
517
|
-
const newChildren =
|
|
513
|
+
const oldChildren = extractChildren(oldVdom);
|
|
514
|
+
const newChildren = extractChildren(newVdom);
|
|
518
515
|
const parentEl = oldVdom.el;
|
|
519
516
|
const diffSeq = arraysDiffSequence(
|
|
520
517
|
oldChildren,
|