Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Toolkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
digital blueprint
Web Component Framework
Toolkit
Commits
be243cdd
Unverified
Commit
be243cdd
authored
4 years ago
by
Bekerle, Patrizio
Browse files
Options
Downloads
Patches
Plain Diff
Re-implement "properties" and "lastProperties" handling (dbp/apps/signature#32)
parent
a8c527e6
No related branches found
Branches containing commit
No related tags found
Loading
Pipeline
#16045
passed
4 years ago
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
packages/provider/src/provider.js
+21
-19
21 additions, 19 deletions
packages/provider/src/provider.js
with
21 additions
and
19 deletions
packages/provider/src/provider.js
+
21
−
19
View file @
be243cdd
...
@@ -4,30 +4,32 @@ export class Provider extends HTMLElement {
...
@@ -4,30 +4,32 @@ export class Provider extends HTMLElement {
this
.
callbackStore
=
[];
this
.
callbackStore
=
[];
this
.
root
=
false
;
this
.
root
=
false
;
// Previously we used direct properties like this["lang"] (instead of this.properties["lang"]) for storing the
// properties, but the "lang" property seems to be updated before the event from the MutationObserver, so we
// cannot observe a value change directly (as workaround we use another property (e.g. "langValue") instead of "lang")
this
.
properties
=
{};
// We need to store our own "last values" because we cannot be sure what the MutationObserver detects
this
.
lastProperties
=
{};
console
.
log
(
'
Provider constructor()
'
);
console
.
log
(
'
Provider constructor()
'
);
}
}
/**
getProperty
(
name
)
{
* The "lang" property seems to be updated before the event from the MutationObserver, so we cannot observe a value change directly
return
this
.
properties
[
name
];
* Workaround: use another property (e.g. "langValue") instead of "lang"
*
* @param name
* @returns {string|*}
*/
static
getPropertyName
(
name
)
{
return
name
===
'
lang
'
?
'
langValue
'
:
name
;
}
}
getValue
(
name
)
{
setProperty
(
name
,
value
)
{
return
this
[
Provider
.
getPropertyName
(
name
)];
this
.
lastProperties
[
name
]
=
value
;
this
.
properties
[
name
]
=
value
;
}
}
setValue
(
name
,
value
)
{
hasPropertyChanged
(
name
,
value
)
{
this
[
Provider
.
ge
tPropert
yName
(
name
)
]
=
value
;
return
this
.
las
tPropert
ies
[
name
]
!=
=
value
;
}
}
hasProperty
(
name
)
{
hasProperty
(
name
)
{
return
Object
.
hasOwnProperty
.
call
(
this
,
Provider
.
getPropertyName
(
name
)
)
;
return
Object
.
hasOwnProperty
.
call
(
this
.
properties
,
name
);
}
}
connectedCallback
()
{
connectedCallback
()
{
...
@@ -41,7 +43,7 @@ export class Provider extends HTMLElement {
...
@@ -41,7 +43,7 @@ export class Provider extends HTMLElement {
console
.
log
(
'
Provider(
'
+
that
.
id
+
'
) eventListener("subscribe",..) name "
'
+
name
+
'
" found.
'
);
console
.
log
(
'
Provider(
'
+
that
.
id
+
'
) eventListener("subscribe",..) name "
'
+
name
+
'
" found.
'
);
that
.
callbackStore
.
push
({
name
:
name
,
callback
:
e
.
detail
.
callback
,
sender
:
e
.
detail
.
sender
});
that
.
callbackStore
.
push
({
name
:
name
,
callback
:
e
.
detail
.
callback
,
sender
:
e
.
detail
.
sender
});
e
.
detail
.
callback
(
that
.
get
Value
(
name
));
e
.
detail
.
callback
(
that
.
get
Property
(
name
));
e
.
stopPropagation
();
e
.
stopPropagation
();
}
}
},
false
);
},
false
);
...
@@ -70,7 +72,7 @@ export class Provider extends HTMLElement {
...
@@ -70,7 +72,7 @@ export class Provider extends HTMLElement {
if
(
that
.
hasProperty
(
name
)
||
that
.
root
)
{
if
(
that
.
hasProperty
(
name
)
||
that
.
root
)
{
console
.
log
(
'
Provider(
'
+
that
.
id
+
'
) eventListener("set-property",..) name "
'
+
name
+
'
" found.
'
);
console
.
log
(
'
Provider(
'
+
that
.
id
+
'
) eventListener("set-property",..) name "
'
+
name
+
'
" found.
'
);
that
.
set
Value
(
name
,
value
);
that
.
set
Property
(
name
,
value
);
that
.
callbackStore
.
forEach
(
item
=>
{
that
.
callbackStore
.
forEach
(
item
=>
{
if
(
item
.
name
===
name
)
{
if
(
item
.
name
===
name
)
{
...
@@ -93,9 +95,9 @@ export class Provider extends HTMLElement {
...
@@ -93,9 +95,9 @@ export class Provider extends HTMLElement {
const
name
=
mutation
.
attributeName
;
const
name
=
mutation
.
attributeName
;
const
value
=
that
.
getAttribute
(
name
);
const
value
=
that
.
getAttribute
(
name
);
if
(
that
.
getValue
(
name
)
!==
value
)
{
if
(
that
.
hasPropertyChanged
(
name
,
value
)
)
{
console
.
log
(
'
Provider (
'
+
that
.
id
+
'
) observed attribute "
'
+
name
+
'
" changed
'
);
console
.
log
(
'
Provider (
'
+
that
.
id
+
'
) observed attribute "
'
+
name
+
'
" changed
'
);
that
.
set
Value
(
name
,
value
);
that
.
set
Property
(
name
,
value
);
that
.
callbackStore
.
forEach
(
item
=>
{
that
.
callbackStore
.
forEach
(
item
=>
{
if
(
item
.
name
===
name
)
{
if
(
item
.
name
===
name
)
{
...
@@ -121,7 +123,7 @@ export class Provider extends HTMLElement {
...
@@ -121,7 +123,7 @@ export class Provider extends HTMLElement {
continue
;
continue
;
}
}
this
[
attrs
[
i
].
name
]
=
attrs
[
i
].
value
;
this
.
setProperty
(
attrs
[
i
].
name
,
attrs
[
i
].
value
)
;
console
.
log
(
'
Provider (
'
+
that
.
id
+
'
) found attribute "
'
+
attrs
[
i
].
name
+
'
" = "
'
+
attrs
[
i
].
value
+
'
"
'
);
console
.
log
(
'
Provider (
'
+
that
.
id
+
'
) found attribute "
'
+
attrs
[
i
].
name
+
'
" = "
'
+
attrs
[
i
].
value
+
'
"
'
);
}
}
}
}
...
...
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