my-framework-almaz 2.0.6 → 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 +12 -13
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
function addEventListener
|
|
1
|
+
function addEventListener(eventName, handler, el) {
|
|
2
2
|
el.addEventListener(eventName, handler);
|
|
3
3
|
return handler
|
|
4
4
|
}
|
|
5
5
|
function addEventListeners(listeners = {}, el) {
|
|
6
6
|
const addedListeners = {};
|
|
7
7
|
Object.entries(listeners).forEach(([eventName, handler]) => {
|
|
8
|
-
const listener = addEventListener
|
|
8
|
+
const listener = addEventListener(eventName, handler, el);
|
|
9
9
|
addedListeners[eventName] = listener;
|
|
10
10
|
});
|
|
11
11
|
return addedListeners
|
|
@@ -399,7 +399,7 @@ function isNotEmptyString(str) {
|
|
|
399
399
|
return str !== ''
|
|
400
400
|
}
|
|
401
401
|
function isNotBlankOrEmptyString(str) {
|
|
402
|
-
isNotEmptyString(str.trim())
|
|
402
|
+
return isNotEmptyString(str.trim())
|
|
403
403
|
}
|
|
404
404
|
|
|
405
405
|
function patchDOM(oldVdom, newVdom, parentEl) {
|
|
@@ -441,20 +441,20 @@ function patchText(oldVdom, newVdom) {
|
|
|
441
441
|
function patchElement(oldVdom, newVdom) {
|
|
442
442
|
const el = oldVdom.el;
|
|
443
443
|
const {
|
|
444
|
-
class:
|
|
444
|
+
class: oldClass,
|
|
445
445
|
style: oldStyle,
|
|
446
446
|
on: oldEvents,
|
|
447
447
|
...oldAttrs
|
|
448
448
|
} = oldVdom.props;
|
|
449
449
|
const {
|
|
450
|
-
class:
|
|
450
|
+
class: newClass,
|
|
451
451
|
style: newStyle,
|
|
452
452
|
on: newEvents,
|
|
453
453
|
...newAttrs
|
|
454
454
|
} = newVdom.props;
|
|
455
455
|
const { listeners: oldListeners } = oldVdom;
|
|
456
456
|
patchAttrs(el, oldAttrs, newAttrs);
|
|
457
|
-
|
|
457
|
+
patchClasses(el, oldClass, newClass);
|
|
458
458
|
patchStyles(el, oldStyle, newStyle);
|
|
459
459
|
newVdom.listeners = patchEvents(el, oldListeners, oldEvents, newEvents);
|
|
460
460
|
}
|
|
@@ -467,7 +467,7 @@ function patchAttrs(el, oldAttrs, newAttrs) {
|
|
|
467
467
|
setAttribute(el, attr, newAttrs[attr]);
|
|
468
468
|
}
|
|
469
469
|
}
|
|
470
|
-
function
|
|
470
|
+
function patchClasses(el, oldClass, newClass) {
|
|
471
471
|
const oldClasses = toClassList(oldClass);
|
|
472
472
|
const newClasses = toClassList(newClass);
|
|
473
473
|
const { added, removed } = arraysDiff(oldClasses, newClasses);
|
|
@@ -478,6 +478,11 @@ function patchCalsses(el, oldClass, newClass) {
|
|
|
478
478
|
el.classList.add(...added);
|
|
479
479
|
}
|
|
480
480
|
}
|
|
481
|
+
function toClassList(classes = '') {
|
|
482
|
+
return Array.isArray(classes)
|
|
483
|
+
? classes.filter(isNotBlankOrEmptyString)
|
|
484
|
+
: classes.split(/(\s+)/).filter(isNotBlankOrEmptyString)
|
|
485
|
+
}
|
|
481
486
|
function patchStyles(el, oldStyle = {}, newStyle = {}) {
|
|
482
487
|
const { added, removed, updated } = objectsDiff(oldStyle, newStyle);
|
|
483
488
|
for (const style of removed) {
|
|
@@ -504,11 +509,6 @@ function patchEvents(
|
|
|
504
509
|
}
|
|
505
510
|
return addedListeneres
|
|
506
511
|
}
|
|
507
|
-
function toClassList(classes = '') {
|
|
508
|
-
return Array.isArray(classes)
|
|
509
|
-
? classes.filter(isNotBlankOrEmptyString)
|
|
510
|
-
: classes.split(/(\s+)/).filter(isNotBlankOrEmptyString)
|
|
511
|
-
}
|
|
512
512
|
function patchChildren(oldVdom, newVdom) {
|
|
513
513
|
const oldChildren = extractChildren(oldVdom);
|
|
514
514
|
const newChildren = extractChildren(newVdom);
|
|
@@ -563,7 +563,6 @@ function createApp({ state, view, reducers = {} }) {
|
|
|
563
563
|
}
|
|
564
564
|
function renderApp() {
|
|
565
565
|
const newVdom = view(state, emit);
|
|
566
|
-
console.log(newVdom);
|
|
567
566
|
vdom = patchDOM(vdom, newVdom, parentEl);
|
|
568
567
|
}
|
|
569
568
|
return {
|