@@ -3,6 +3,31 @@ import { debounce } from "./delayers.js";
33import { Element } from "./element.js" ;
44import morphdom from "./morphdom/2.6.1/morphdom.js"
55
6+ export const MORPHDOM_OPTIONS = {
7+ childrenOnly : false ,
8+ // eslint-disable-next-line consistent-return
9+ getNodeKey ( node ) {
10+ // A node's unique identifier. Used to rearrange elements rather than
11+ // creating and destroying an element that already exists.
12+ if ( node . attributes ) {
13+ const key = node . getAttribute ( "unicorn:key" ) || node . id ;
14+
15+ if ( key ) {
16+ return key ;
17+ }
18+ }
19+ } ,
20+ // eslint-disable-next-line consistent-return
21+ onBeforeElUpdated ( fromEl , toEl ) {
22+ // Because morphdom also supports vDom nodes, it uses isSameNode to detect
23+ // sameness. When dealing with DOM nodes, we want isEqualNode, otherwise
24+ // isSameNode will ALWAYS return false.
25+ if ( fromEl . isEqualNode ( toEl ) ) {
26+ return false ;
27+ }
28+ } ,
29+ } ;
30+
631/**
732 * Encapsulate component.
833 */
@@ -259,7 +284,8 @@ export class Component {
259284
260285 /**
261286 * Sets all model values.
262- * @param {Object } elementToExclude Prevent a particular element from being updated. Object example: `{id: 'elementId', key: 'elementKey'}`.
287+ * @param {Object } elementToExclude Prevent a particular element from being updated.
288+ * Object example: `{id: 'elementId', key: 'elementKey'}`.
263289 */
264290 setModelValues ( elementToExclude ) {
265291 elementToExclude = elementToExclude || { } ;
@@ -353,31 +379,7 @@ export class Component {
353379 _component . errors = responseJson . errors || { } ;
354380 const rerenderedComponent = responseJson . dom ;
355381
356- const morphdomOptions = {
357- childrenOnly : false ,
358- getNodeKey ( node ) {
359- // A node's unique identifier. Used to rearrange elements rather than
360- // creating and destroying an element that already exists.
361- if ( node . attributes ) {
362- const key = node . getAttribute ( "unicorn:key" ) || node . id ;
363-
364- if ( key ) {
365- return key ;
366- }
367- }
368- } ,
369- onBeforeElUpdated ( fromEl , toEl ) {
370- // Because morphdom also supports vDom nodes, it uses isSameNode to detect
371- // sameness. When dealing with DOM nodes, we want isEqualNode, otherwise
372- // isSameNode will ALWAYS return false.
373- if ( fromEl . isEqualNode ( toEl ) ) {
374- return false ;
375- }
376- } ,
377- } ;
378-
379- // eslint-disable-next-line no-undef
380- morphdom ( _component . root , rerenderedComponent , morphdomOptions ) ;
382+ morphdom ( _component . root , rerenderedComponent , MORPHDOM_OPTIONS ) ;
381383
382384 // Refresh the checksum based on the new data
383385 _component . refreshChecksum ( ) ;
0 commit comments