Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
TP3 - API DOM
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Paul Ripault
TP3 - API DOM
Commits
0592230f
Commit
0592230f
authored
5 years ago
by
Thomas Fritsch
Browse files
Options
Downloads
Patches
Plain Diff
D.1.1. + D.1.2. children multiples
parent
8baa6714
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/components/Component.js
+18
-3
18 additions, 3 deletions
js/components/Component.js
js/main.js
+8
-5
8 additions, 5 deletions
js/main.js
with
26 additions
and
8 deletions
js/components/Component.js
+
18
−
3
View file @
0592230f
...
...
@@ -10,9 +10,13 @@ export default class Component {
}
render
()
{
return
`<
${
this
.
tag
}
${
this
.
renderAttributes
()}
${
this
.
children
?
`>
${
this
.
children
}
</
${
this
.
tag
}
>`
:
'
/>
'
}
`
;
let
html
=
`<
${
this
.
tag
}
${
this
.
renderAttributes
()}
`
;
if
(
this
.
children
)
{
html
+=
`>
${
this
.
renderChildren
()}
</
${
this
.
tag
}
>`
;
}
else
{
html
+=
'
/>
'
;
}
return
html
;
}
renderAttributes
()
{
...
...
@@ -21,4 +25,15 @@ export default class Component {
}
return
''
;
}
renderChildren
()
{
if
(
this
.
children
instanceof
Array
)
{
return
this
.
children
.
reduce
(
(
html
,
child
)
=>
html
+
(
child
instanceof
Component
?
child
.
render
()
:
child
),
''
);
}
return
this
.
children
||
''
;
}
}
This diff is collapsed.
Click to expand it.
js/main.js
+
8
−
5
View file @
0592230f
...
...
@@ -2,10 +2,13 @@ import data from './data.js';
import
Component
from
'
./components/Component.js
'
;
import
Img
from
'
./components/Img.js
'
;
const
title
=
new
Component
(
'
h1
'
,
null
,
'
La
carte
'
);
const
title
=
new
Component
(
'
h1
'
,
null
,
[
'
La
'
,
'
'
,
'
carte
'
]
);
document
.
querySelector
(
'
.pageTitle
'
).
innerHTML
=
title
.
render
();
const
img
=
new
Img
(
'
https://images.unsplash.com/photo-1532246420286-127bcd803104?fit=crop&w=500&h=300
'
);
document
.
querySelector
(
'
.pizzasContainer
'
).
innerHTML
=
img
.
render
();
const
c
=
new
Component
(
'
article
'
,
{
name
:
'
class
'
,
value
:
'
media
'
},
[
new
Img
(
'
https://images.unsplash.com/photo-1532246420286-127bcd803104?fit=crop&w=500&h=300
'
),
'
Regina
'
,
]);
document
.
querySelector
(
'
.pizzasContainer
'
).
innerHTML
=
c
.
render
();
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