Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
D
default2
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yuri Bondarenko
default2
Commits
c7afb658
Commit
c7afb658
authored
Dec 09, 2018
by
Yuri Bondarenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new state
parent
3c937376
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
75 additions
and
71 deletions
+75
-71
src/assets/css/app.css
src/assets/css/app.css
+3
-4
src/components/button/button.css
src/components/button/button.css
+0
-10
src/components/component/index.js
src/components/component/index.js
+37
-5
src/components/header/index.html
src/components/header/index.html
+0
-5
src/components/header/index.js
src/components/header/index.js
+0
-21
src/components/swiper/index.js
src/components/swiper/index.js
+30
-24
src/components/swiper/swiper.css
src/components/swiper/swiper.css
+5
-2
No files found.
src/assets/css/app.css
View file @
c7afb658
/**
* Базовый CSS
*/
/* Библиотеки */
@import
url( '../../../node_modules/swiper/dist/css/swiper.min.css' )
;
/* CSS */
@import
url('../../components/common/common.css')
;
@import
url('../../components/swiper/swiper.css')
;
src/components/button/button.css
deleted
100644 → 0
View file @
3c937376
:root
{
--buttonText
:
#fff
;
--buttonBg
:
#f00
;
}
.button
{
color
:
var
(
--buttonText
);
background-color
:
var
(
--buttonBg
);
font-family
:
var
(
--font
);
}
\ No newline at end of file
src/components/component/index.js
View file @
c7afb658
...
...
@@ -24,17 +24,49 @@ export default class Component {
// дефолтное состояние
this
.
state
=
{};
// отрисовываем
this
.
render
();
this
.
setState
();
}
/**
* Установка состояния
*/
setState
(
state
=
{}
){
Object
.
assign
(
this
.
state
,
state
);
this
.
render
();
setState
=
(
newState
=
{}
)
=>
{
console
.
log
(
'
Component setState(): Compare states
'
,
this
.
objectEquals
(
this
.
state
,
newState
),
this
.
state
,
newState
);
if
(
!
this
.
objectEquals
(
this
.
state
,
newState
)
){
Object
.
assign
(
this
.
state
,
newState
);
this
.
render
();
}
}
/**
* Сравниваем два объекта
*/
objectEquals
=
(
x
,
y
)
=>
{
if
(
x
===
null
||
x
===
undefined
||
y
===
null
||
y
===
undefined
)
{
return
x
===
y
;
}
// after this just checking type of one would be enough
if
(
x
.
constructor
!==
y
.
constructor
)
{
return
false
;
}
// if they are functions, they should exactly refer to same one (because of closures)
if
(
x
instanceof
Function
)
{
return
x
===
y
;
}
// if they are regexps, they should exactly refer to same one (it is hard to better equality check on current ES)
if
(
x
instanceof
RegExp
)
{
return
x
===
y
;
}
if
(
x
===
y
||
x
.
valueOf
()
===
y
.
valueOf
())
{
return
true
;
}
if
(
Array
.
isArray
(
x
)
&&
x
.
length
!==
y
.
length
)
{
return
false
;
}
// if they are dates, they must had equal valueOf
if
(
x
instanceof
Date
)
{
return
false
;
}
// if they are strictly equal, they both need to be object at least
if
(
!
(
x
instanceof
Object
))
{
return
false
;
}
if
(
!
(
y
instanceof
Object
))
{
return
false
;
}
// recursive object equality check
var
p
=
Object
.
keys
(
x
);
return
Object
.
keys
(
y
).
every
(
function
(
i
)
{
return
p
.
indexOf
(
i
)
!==
-
1
;
})
&&
p
.
every
(
function
(
i
)
{
return
objectEquals
(
x
[
i
],
y
[
i
]);
});
}
...
...
src/components/header/index.html
deleted
100644 → 0
View file @
3c937376
<div
class=
"header"
>
<button
class=
"button"
>
Alert
</button>
</div>
\ No newline at end of file
src/components/header/index.js
deleted
100644 → 0
View file @
3c937376
import
Component
from
'
../component
'
;
export
default
class
Header
extends
Component
{
constructor
(
props
=
{
buttonSelector
:
'
.header .button
'
}
){
super
(
props
);
this
.
state
.
button
=
document
.
querySelector
(
this
.
props
.
buttonSelector
);
this
.
state
.
button
.
addEventListener
(
'
click
'
,
this
.
buttonClick
);
}
buttonClick
(){
alert
(
1
);
}
render
(){
return
true
;
}
}
\ No newline at end of file
src/components/swiper/index.js
View file @
c7afb658
...
...
@@ -10,9 +10,7 @@ export default class SwiperSlider extends Component {
constructor
(
props
=
{
selector
:
'
.swiper-container
'
,
options
:
{
// Optional parameters
// direction: 'vertical',
loop
:
true
,
spaceBetween
:
10
,
// If we need pagination
pagination
:
{
...
...
@@ -29,15 +27,11 @@ export default class SwiperSlider extends Component {
scrollbar
:
{
el
:
'
.swiper-scrollbar
'
,
},
slidesPerView
:
1
}
}
){
super
(
props
);
this
.
state
.
swiper
=
new
Swiper
(
this
.
props
.
selector
,
this
.
props
.
options
);
this
.
loadData
(
this
.
state
);
this
.
loadData
();
}
/**
...
...
@@ -53,7 +47,7 @@ export default class SwiperSlider extends Component {
'
variables
'
:
{
'
after
'
:
null
,
'
before
'
:
null
,
'
first
'
:
4
,
'
first
'
:
10
,
'
last
'
:
null
,
'
locale
'
:
'
RU
'
},
...
...
@@ -89,30 +83,42 @@ export default class SwiperSlider extends Component {
}`
})
})
.
then
(
(
response
)
=>
{
return
response
.
json
();
})
.
then
(
(
data
)
=>
{
.
then
(
(
response
)
=>
{
return
response
.
json
();
})
.
then
(
(
data
)
=>
{
data
.
data
.
albums
.
edges
.
forEach
(
(
album
,
index
)
=>
{
let
slides
=
[];
const
slide
=
`<div class="swiper-item">
<h3>Swiper
${
index
}
</h3>
<p>Swiper
${
index
}
slide</p>
<img src="
${
album
.
node
.
photos
[
0
].
resized
.
url
}
" alt="
${
album
.
node
.
title
}
" />
</div>`
;
data
.
data
.
albums
.
edges
.
forEach
(
(
album
,
index
)
=>
{
this
.
state
.
swiper
.
appendSlide
(
slide
);
});
const
slide
=
`<div class="swiper-item">
<h3>Swiper
${
index
}
</h3>
<p>Swiper
${
index
}
slide</p>
<img src="
${
album
.
node
.
photos
[
0
].
resized
.
url
}
" alt="
${
album
.
node
.
title
}
" />
</div>`
;
this
.
state
.
swiper
.
update
();
slides
[
index
]
=
slide
;
});
console
.
log
(
this
.
state
.
swiper
)
console
.
log
(
slides
);
this
.
setState
({
slides
:
slides
});
});
}
render
(){
// console.log( this.state.slides );
this
.
swiper
=
new
Swiper
(
this
.
props
.
selector
,
this
.
props
.
options
);
// this.swiper.appendSlide( this.state.slides );
console
.
log
(
'
Swiper class: render() called
'
);
}
}
\ No newline at end of file
src/components/swiper/swiper.css
View file @
c7afb658
.swiper-container
{
width
:
600px
;
height
:
300px
;
}
.swiper-item
{
width
:
200px
;
}
.swiper-item
img
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment