Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Monster
Manage
Activity
Members
Plan
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Javascript
Monster
Commits
37aeb339
Verified
Commit
37aeb339
authored
1 month ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
fix: handle updates better
parent
c5ecc0fe
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/dom/updater.mjs
+53
-29
53 additions, 29 deletions
source/dom/updater.mjs
with
53 additions
and
29 deletions
source/dom/updater.mjs
+
53
−
29
View file @
37aeb339
...
...
@@ -60,6 +60,18 @@ export { Updater, addObjectWithUpdaterToElement };
*/
const
timerElementEventHandlerSymbol
=
Symbol
(
"
timerElementEventHandler
"
);
/**
* @private
* @type {symbol}
*/
const
pendingDiffsSymbol
=
Symbol
(
"
pendingDiffs
"
);
/**
* @private
* @type {symbol}
*/
const
processingSymbol
=
Symbol
(
"
processing
"
);
/**
* The updater class connects an object with the DOM. In this way, structures and contents in the DOM can be
* programmatically adapted via attributes.
...
...
@@ -85,6 +97,7 @@ const timerElementEventHandlerSymbol = Symbol("timerElementEventHandler");
* @summary The updater class connects an object with the dom
*/
class
Updater
extends
Base
{
/**
* @since 1.8.0
* @param {HTMLElement} element
...
...
@@ -117,37 +130,48 @@ class Updater extends Base {
getCheckStateCallback
.
call
(
this
),
);
this
[
pendingDiffsSymbol
]
=
[];
this
[
processingSymbol
]
=
false
;
this
[
internalSymbol
].
subject
.
attachObserver
(
new
Observer
(()
=>
{
const
s
=
this
[
internalSymbol
].
subject
.
getRealSubject
();
const
diffResult
=
diff
(
this
[
internalSymbol
].
last
,
s
);
this
[
internalSymbol
].
last
=
clone
(
s
);
const
real
=
this
[
internalSymbol
].
subject
.
getRealSubject
();
const
diffResult
=
diff
(
this
[
internalSymbol
].
last
,
real
);
this
[
internalSymbol
].
last
=
clone
(
real
);
this
[
pendingDiffsSymbol
].
push
(
diffResult
);
return
this
.
#processQueue
();
}),
);
}
const
promises
=
[];
/**
* @private
* @return {Promise}
*/
async
#processQueue
()
{
if
(
this
[
processingSymbol
])
{
return
Promise
.
resolve
();
}
this
[
processingSymbol
]
=
true
;
while
(
this
[
pendingDiffsSymbol
].
length
>
0
)
{
const
diffResult
=
this
[
pendingDiffsSymbol
].
shift
();
for
(
const
[,
change
]
of
Object
.
entries
(
diffResult
))
{
promises
.
push
(
new
Promise
((
resolve
,
reject
)
=>
{
getWindow
().
requestAnimationFrame
(()
=>
{
await
new
Promise
((
resolve
,
reject
)
=>
{
try
{
removeElement
.
call
(
this
,
change
);
insertElement
.
call
(
this
,
change
);
updateContent
.
call
(
this
,
change
);
updateAttributes
.
call
(
this
,
change
);
resolve
();
}
catch
(
err
or
)
{
reject
(
err
or
);
}
catch
(
err
)
{
reject
(
err
);
}
});
}),
);
}
}
return
Promise
.
all
(
promises
);
}),
);
this
[
processingSymbol
]
=
false
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment