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
91327d4c
Verified
Commit
91327d4c
authored
1 year ago
by
Volker Schukai
Browse files
Options
Downloads
Patches
Plain Diff
feat: new updaterTransformerMethodsSymbol method #163
parent
79c2c6e8
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/dom/updater.mjs
+32
-4
32 additions, 4 deletions
source/dom/updater.mjs
with
32 additions
and
4 deletions
source/dom/updater.mjs
+
32
−
4
View file @
91327d4c
...
@@ -29,20 +29,23 @@ import { validateArray, validateInstance } from "../types/validate.mjs";
...
@@ -29,20 +29,23 @@ import { validateArray, validateInstance } from "../types/validate.mjs";
import
{
Sleep
}
from
"
../util/sleep.mjs
"
;
import
{
Sleep
}
from
"
../util/sleep.mjs
"
;
import
{
clone
}
from
"
../util/clone.mjs
"
;
import
{
clone
}
from
"
../util/clone.mjs
"
;
import
{
trimSpaces
}
from
"
../util/trimspaces.mjs
"
;
import
{
trimSpaces
}
from
"
../util/trimspaces.mjs
"
;
import
{
addToObjectLink
}
from
"
./attributes.mjs
"
;
import
{
addAttributeToken
,
addToObjectLink
}
from
"
./attributes.mjs
"
;
import
{
updaterTransformerMethodsSymbol
}
from
"
./customelement.mjs
"
;
import
{
findTargetElementFromEvent
}
from
"
./events.mjs
"
;
import
{
findTargetElementFromEvent
}
from
"
./events.mjs
"
;
import
{
findDocumentTemplate
}
from
"
./template.mjs
"
;
import
{
findDocumentTemplate
}
from
"
./template.mjs
"
;
export
{
Updater
,
addObjectWithUpdaterToElement
};
export
{
Updater
,
addObjectWithUpdaterToElement
};
/**
/**
* The updater class connects an object with the dom. In this way, structures and contents in the DOM can be programmatically adapted via attributes.
* The updater class connects an object with the dom. In this way, structures and contents in the DOM can be
* programmatically adapted via attributes.
*
*
* For example, to include a string from an object, the attribute `data-monster-replace` can be used.
* For example, to include a string from an object, the attribute `data-monster-replace` can be used.
* a further explanation can be found under [monsterjs.org](https://monsterjs.org/)
* a further explanation can be found under [monsterjs.org](https://monsterjs.org/)
*
*
* Changes to attributes are made only when the direct values are changed. If you want to assign changes to other values
* Changes to attributes are made only when the direct values are changed. If you want to assign changes
* as well, you have to insert the attribute `data-monster-select-this`. This should be done with care, as it can reduce performance.
* to other values as well, you have to insert the attribute `data-monster-select-this`. This should be
* done with care, as it can reduce performance.
*
*
* @externalExample ../../example/dom/updater.mjs
* @externalExample ../../example/dom/updater.mjs
* @license AGPLv3
* @license AGPLv3
...
@@ -929,13 +932,38 @@ function addObjectWithUpdaterToElement(elements, symbol, object) {
...
@@ -929,13 +932,38 @@ function addObjectWithUpdaterToElement(elements, symbol, object) {
const
result
=
[];
const
result
=
[];
let
updaterCallbacks
=
[]
const
cb
=
this
?.[
updaterTransformerMethodsSymbol
]
if
(
this
instanceof
HTMLElement
&&
(
typeof
cb
===
"
function
"
))
{
let
callbacks
=
cb
();
if
(
typeof
callbacks
===
"
object
"
)
{
for
(
const
[
name
,
callback
]
of
Object
.
entries
(
callbacks
))
{
if
(
typeof
callback
===
"
function
"
)
{
updaterCallbacks
.
push
([
name
,
callback
]);
}
else
{
addAttributeToken
(
this
,
ATTRIBUTE_ERRORMESSAGE
,
`onUpdaterPipeCallbacks:
${
name
}
is not a function`
);
}
}
}
else
{
addAttributeToken
(
this
,
ATTRIBUTE_ERRORMESSAGE
,
`onUpdaterPipeCallbacks do not return an object with functions`
);
}
}
elements
.
forEach
((
element
)
=>
{
elements
.
forEach
((
element
)
=>
{
if
(
!
(
element
instanceof
HTMLElement
))
return
;
if
(
!
(
element
instanceof
HTMLElement
))
return
;
if
(
element
instanceof
HTMLTemplateElement
)
return
;
if
(
element
instanceof
HTMLTemplateElement
)
return
;
const
u
=
new
Updater
(
element
,
object
);
const
u
=
new
Updater
(
element
,
object
);
updaters
.
add
(
u
);
updaters
.
add
(
u
);
if
(
updaterCallbacks
.
length
>
0
)
{
for
(
const
[
name
,
callback
]
of
updaterCallbacks
)
{
u
.
setCallback
(
name
,
callback
);
}
}
result
.
push
(
result
.
push
(
u
.
run
().
then
(()
=>
{
u
.
run
().
then
(()
=>
{
return
u
.
enableEventProcessing
();
return
u
.
enableEventProcessing
();
...
...
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