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
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Libraries
Javascript
Monster
Commits
fb796880
Verified
Commit
fb796880
authored
11 months ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
feat: new dataset feature refreshOnMutation #215
parent
df47406b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/components/datatable/dataset.mjs
+278
-202
278 additions, 202 deletions
source/components/datatable/dataset.mjs
with
278 additions
and
202 deletions
source/components/datatable/dataset.mjs
+
278
−
202
View file @
fb796880
...
...
@@ -129,6 +129,22 @@ class DataSet extends CustomElement {
index
:
0
,
},
features
:
{
/**
* @since 3.70.0
* @type {boolean}
*/
refreshOnMutation
:
true
,
},
/**
* @since 3.70.0
* @type {boolean}
*/
refreshOnMutation
:
{
selector
:
"
input, select, textarea
"
},
data
:
{},
});
...
...
@@ -144,6 +160,21 @@ class DataSet extends CustomElement {
return
"
monster-dataset
"
;
}
/**
* This method is called when the component is created.
* @since 3.70.0
* @returns {DataSet}
*/
refresh
()
{
// makes sure that handleDataSourceChanges is called
this
.
setOption
(
"
data
"
,
{});
return
this
;
}
/**
*
* @returns {Promise<unknown>}
*/
write
()
{
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
this
[
datasourceLinkedElementSymbol
])
{
...
...
@@ -176,7 +207,7 @@ class DataSet extends CustomElement {
if
(
isString
(
path
)
&&
path
!==
""
)
{
pathWithIndex
=
path
+
"
.
"
+
index
;
}
else
{
pathWithIndex
=
index
;
pathWithIndex
=
String
(
index
)
;
}
const
data
=
this
[
datasourceLinkedElementSymbol
].
data
;
...
...
@@ -211,7 +242,6 @@ class DataSet extends CustomElement {
[
assembleMethodSymbol
]()
{
super
[
assembleMethodSymbol
]();
// initControlReferences.call(self);
initEventHandler
.
call
(
this
);
const
selector
=
this
.
getOption
(
"
datasource.selector
"
);
...
...
@@ -237,6 +267,11 @@ class DataSet extends CustomElement {
handleDataSourceChanges
.
call
(
this
);
}),
);
if
(
this
.
getOption
(
"
features.refreshOnMutation
"
)
&&
this
.
getOption
(
"
refreshOnMutation.selector
"
))
{
initMutationObserver
.
call
(
this
);
}
}
/**
...
...
@@ -277,6 +312,47 @@ function updateOptionsFromArguments(options) {
}
}
/**
* @private
*/
function
initMutationObserver
()
{
const
config
=
{
attributes
:
false
,
childList
:
true
,
subtree
:
true
};
const
callback
=
(
mutationList
,
observer
)
=>
{
if
(
mutationList
.
length
===
0
)
{
return
;
}
let
doneFlag
=
false
;
for
(
const
mutation
of
mutationList
)
{
if
(
mutation
.
type
===
"
childList
"
)
{
for
(
const
node
of
mutation
.
addedNodes
)
{
if
(
node
instanceof
HTMLElement
&&
node
.
matches
(
this
.
getOption
(
"
refreshOnMutation.selector
"
)))
{
doneFlag
=
true
;
break
;
}
}
if
(
doneFlag
)
{
break
;
}
}
}
if
(
doneFlag
)
{
this
.
refresh
();
}
};
const
observer
=
new
MutationObserver
(
callback
);
observer
.
observe
(
this
,
config
);
}
/**
* @private
* @return {string}
...
...
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