Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
astro-wt
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
3f061832
authored
2024-07-12 16:22:06 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Convert the nodeProxyHandler to a class.
1 parent
eaa705ab
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
lib/html.ts
lib/html.ts
View file @
3f06183
...
...
@@ -307,34 +307,40 @@ export const createMatcher = (selector: string): Matcher => {
return
newMatcherCreater
()
}
const
nodeProxyHandler
=
{
class
NodeProxyHandler
{
#
cache
constructor
()
{
this
.
#
cache
=
{}
}
get
(
target
,
prop
,
receiver
)
{
const
{
_proxy
}
=
target
if
(
prop
in
_proxy
)
return
_proxy
[
prop
]
if
(
prop
in
this
.
#
cache
)
return
this
.
#
cache
[
prop
]
const
{
[
prop
]:
origValue
}
=
target
if
(
!
origValue
)
return
origValue
switch
(
prop
)
{
case
'attributes'
:
return
_proxy
[
prop
]
=
(
origValue
?
Object
.
fromEntries
(
Object
.
entries
(
origValue
).
map
(([
key
,
value
])
=>
{
return
this
.
#
cache
[
prop
]
=
(
origValue
?
Object
.
fromEntries
(
Object
.
entries
(
origValue
).
map
(([
key
,
value
])
=>
{
return
[
key
,
decode
(
value
)
]
}))
:
origValue
)
return
newValue
case
'parent'
:
return
_proxy
[
prop
]
=
proxyNode
(
origValue
)
return
this
.
#
cache
[
prop
]
=
proxyNode
(
origValue
)
case
'children'
:
return
_proxy
[
prop
]
=
origValue
.
map
((
child
)
=>
proxyNode
(
child
))
return
this
.
#
cache
[
prop
]
=
origValue
.
map
((
child
)
=>
proxyNode
(
child
))
default
:
if
(
typeof
origValue
===
'function'
)
{
return
this
.
#
cache
[
prop
]
=
(...
args
)
=>
{
origValue
.
apply
(
target
,
...
args
)
}
}
return
origValue
}
}
}
const
proxyNode
=
(
node
)
=>
{
const
{
_proxy
:
{
proxy
}
=
{}
}
=
node
if
(
proxy
)
return
proxy
const
newProxy
=
new
Proxy
(
node
,
nodeProxyHandler
)
node
.
_proxy
=
{
proxy
:
newProxy
}
return
newProxy
return
new
Proxy
(
node
,
new
NodeProxyHandler
())
}
export
const
parseHtml
=
(
html
:
string
):
NodeType
=>
{
...
...
Please
register
or
sign in
to post a comment