Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kus-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Кубота
kus-admin
Commits
c2a7b2a2
Commit
c2a7b2a2
authored
Jan 29, 2020
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
store hook mechanics, dom hooks mechanic, Boolean hook example
parent
01e21767
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
114 additions
and
20 deletions
+114
-20
DOM.js
src/core/DOM.js
+15
-3
LivestReloading.js
src/core/LivestReloading.js
+1
-1
Store.js
src/core/data/store/Store.js
+62
-5
Store.js
src/model/Store.js
+15
-6
Header.jsx
src/view/block/header/Header.jsx
+11
-5
Header.scss
src/view/block/header/Header.scss
+10
-0
No files found.
src/core/DOM.js
View file @
c2a7b2a2
...
...
@@ -113,6 +113,9 @@ NS.apply = function(a,b) {
if
(
typeof
type
===
'function'
){
return
type
(
cfg
,
[].
slice
.
call
(
arguments
,
2
));
}
if
(
typeof
type
===
'object'
&&
type
.
hook
){
return
type
.
hook
(
cfg
,
[].
slice
.
call
(
arguments
,
2
));
}
cfg
=
cfg
||
{};
var
cls
=
cfg
.
cls
||
cfg
[
'class'
]
||
cfg
.
className
,
style
=
cfg
.
style
,
...
...
@@ -143,6 +146,8 @@ NS.apply = function(a,b) {
if
(
cls
){
if
(
typeof
cls
===
'function'
){
cls
(
setters
.
cls
(
el
));
}
else
if
(
typeof
cls
===
'object'
&&
cls
.
hook
){
return
cls
.
hook
(
setters
.
cls
(
el
));
}
else
{
setters
.
cls
(
el
)(
cls
);
}
...
...
@@ -156,6 +161,8 @@ NS.apply = function(a,b) {
if
(
attr
.
hasOwnProperty
(
i
)){
if
(
typeof
attr
[
i
]
===
'function'
){
attr
[
i
](
setters
.
attr
(
el
,
i
)
);
}
else
if
(
typeof
attr
[
i
]
===
'object'
&&
attr
[
i
].
hook
){
return
attr
[
i
].
hook
(
setters
.
attr
(
el
,
i
));
}
else
{
setters
.
attr
(
el
,
i
)(
attr
[
i
]
);
}
...
...
@@ -239,6 +246,7 @@ NS.apply = function(a,b) {
return
;
}
if
(
type
!==
'object'
){
// TODO : add hook
if
(
type
===
'function'
){
//var tmp = D.Text();//( {cls: 'zero-wrapper'} );
//el.appendChild( tmp );
...
...
@@ -278,11 +286,11 @@ NS.apply = function(a,b) {
var
dpID
=
1
;
var
DataPiece
=
function
(
id
){
this
.
id
=
id
;};
DataPiece
.
prototype
=
{
value
:
void
0
,
update
:
function
(){}};
var
DataPieceFactory
=
function
(
refs
,
fn
)
{
var
DataPieceFactory
=
function
(
refs
,
fn
,
scope
)
{
var
id
=
dpID
++
;
var
dp
=
new
DataPiece
(
id
);
refs
.
push
(
dp
);
fn
(
function
(
val
)
{
fn
.
call
(
scope
,
function
(
val
)
{
dp
.
value
=
val
;
dp
.
update
();
});
...
...
@@ -312,7 +320,9 @@ NS.apply = function(a,b) {
out
.
push
(
token
);
}
else
if
(
typeof
token
===
'object'
){
if
(
token
instanceof
DataPiece
){
token
.
value
&&
out
.
push
(
token
.
value
);
token
.
value
&&
out
.
push
(
token
.
value
);
}
else
if
(
token
.
hook
){
args
[
i
]
=
DataPieceFactory
(
refs
,
token
.
hook
,
token
);
}
else
if
(
Array
.
isArray
(
token
)){
tmp
=
D
.
_cls
(
token
,
refs
,
depth
+
1
);
// TODO check for push tmp
...
...
@@ -323,6 +333,8 @@ NS.apply = function(a,b) {
token
[
key
].
value
&&
out
.
push
(
key
);
}
else
if
(
typeof
token
[
key
]
===
'function'
){
token
[
key
]
=
DataPieceFactory
(
refs
,
token
[
key
]);
}
else
if
(
typeof
token
[
key
]
===
'object'
&&
token
[
key
].
hook
){
token
[
key
]
=
DataPieceFactory
(
refs
,
token
[
key
].
hook
,
token
[
key
])
}
else
{
token
[
key
]
&&
out
.
push
(
key
);
}
...
...
src/core/LivestReloading.js
View file @
c2a7b2a2
...
...
@@ -33,7 +33,7 @@ async function subscribe() {
});
}
catch
(
e
){
console
.
error
(
e
)
console
.
error
(
e
)
}
//showMessage(message);
// Call subscribe() again to get the next message
...
...
src/core/data/store/Store.js
View file @
c2a7b2a2
...
...
@@ -190,11 +190,16 @@ Store.AGGREGATE = function(fn) {
};
for
(
let
i
=
0
;
i
<
_i
;
i
++
){
// set backward callback
args
[
i
](
val
=>
{
let
hook
=
val
=>
{
// update item corresponding value and check condition
vals
[
i
]
=
val
;
vals
[
i
]
=
val
;
check
();
})
};
if
(
args
[
i
]
instanceof
HookPrototype
){
args
[
i
].
hook
(
hook
)
}
else
{
args
[
i
](
hook
)
}
}
};
...
...
@@ -220,12 +225,64 @@ Store.OR = Store.AGGREGATE(function(values, length) {
Store
.
IF
=
function
(
cfg
,
children
){
return
function
(
update
){
if
(
'condition'
in
cfg
)
cfg
.
condition
(
function
(
cond
){
var
hook
=
function
(
cond
){
update
(
cond
?
children
:
null
);
}
);
};
if
(
cfg
.
condition
instanceof
HookPrototype
){
cfg
.
condition
.
hook
(
hook
);
}
else
{
cfg
.
condition
(
hook
);
}
}
};
Store
.
NOT
=
Store
.
AGGREGATE
(
function
(
values
,
length
)
{
return
!
values
[
0
];
});
var
HookPrototype
=
function
()
{};
HookPrototype
.
prototype
=
{
setter
:
function
(
val
)
{
return
val
;
},
//getter: function(val) { return val; },
set
:
function
(
val
)
{
val
=
this
.
setter
(
val
);
var
oldVal
=
this
.
get
();
if
(
!
this
.
equal
(
oldVal
,
val
)){
this
.
data
=
val
;
this
.
_emit
(
oldVal
,
val
);
}
},
equal
:
function
(
oldVal
,
newVal
){
return
newVal
===
oldVal
;
},
get
:
function
()
{
return
this
.
data
;
},
hook
:
function
(
fn
)
{
this
.
subscribers
.
push
(
fn
);
fn
(
this
.
get
());
},
_emit
:
function
(
oldVal
,
val
)
{
var
subscribers
=
this
.
subscribers
;
for
(
var
i
=
0
,
_i
=
subscribers
.
length
;
i
<
_i
;
i
++
){
subscribers
[
i
](
val
);
}
}
};
var
HookFactory
=
function
(
accessor
)
{
var
Hook
=
function
(
cfg
)
{
this
.
data
=
{};
this
.
subscribers
=
[];
this
.
set
(
cfg
);
};
Hook
.
prototype
=
Object
.
assign
(
new
HookPrototype
(),
accessor
);
return
Hook
;
};
Store
.
Value
=
{
Boolean
:
new
HookFactory
({
setter
:
function
(
val
)
{
return
!!
val
;
},
toggle
:
function
()
{
this
.
set
(
!
this
.
get
());
}
})
};
Store
.
HookPrototype
=
HookPrototype
;
typeof
module
===
'object'
&&
(
module
.
exports
=
Store
);
src/model/Store.js
View file @
c2a7b2a2
const
store
=
new
Store
({
let
latest
;
const
store
=
new
Store
(
latest
=
{
commit
:
window
.
CommitID
,
'navigation'
:
{
current
:
'
l
ogin'
current
:
'
L
ogin'
},
'account'
:
{
userID
:
5
,
...
...
@@ -16,19 +17,27 @@ const store = new Store({
try
{
var
data
=
JSON
.
parse
(
localStorage
.
getItem
(
'store'
)
);
window
.
addEventListener
&&
console
.
log
(
data
)
if
(
window
.
CommitID
!==
store
.
get
(
'commit'
)){
if
(
data
.
commit
!==
store
.
get
(
'commit'
)){
console
.
warn
(
'STORE: warn outdated:'
);
console
.
warn
(
'
\
t
\
tCurrent data: '
+
store
.
get
(
'commit'
),
store
.
_props
);
console
.
warn
(
'
\
t
\
tSaved data: '
+
window
.
CommitID
,
data
);
console
.
warn
(
'
\
tRun restoreStore() for restore saved state'
);
window
.
restoreStore
=
function
()
{
console
.
warn
(
'
\
tRun Store.restore() for restore saved state'
);
console
.
warn
(
'
\
tRun Store.update() for load latest default state'
);
Store
.
restore
=
function
()
{
for
(
var
k
in
data
){
if
(
k
!==
'commit'
){
store
.
set
(
k
,
data
[
k
]
);
}
}
};
Store
.
update
=
function
()
{
for
(
var
k
in
latest
){
if
(
k
!==
'commit'
){
store
.
set
(
k
,
latest
[
k
]
);
}
}
};
}
else
{
for
(
var
k
in
data
){
store
.
set
(
k
,
data
[
k
]
);
...
...
src/view/block/header/Header.jsx
View file @
c2a7b2a2
...
...
@@ -7,16 +7,22 @@ import { Page } from "../../page/Page";
const
{
IF
,
NOT
}
=
Store
;
export
default
D
.
declare
(
'view.block.Header'
,
()
=>
{
const
tempPageMenuHidden
=
new
Store
.
Value
.
Boolean
(
true
);
return
<
header
class=
{
D
.
cls
(
"page-header"
,
{
"page-header--inner"
:
(
NOT
(
store
.
valEqual
(
'navigation.current'
,
'login'
)))
})
}
>
<
div
class=
"button-temp"
>
{
Object
.
keys
(
Page
).
map
(
name
=>
<
button
type=
{
'button'
}
onClick=
{
()
=>
store
.
set
(
'navigation.current'
,
name
)
}
>
{
name
}
</
button
>
)
}
<
button
type=
{
"button"
}
onClick=
{
()
=>
tempPageMenuHidden
.
toggle
()
}
>
<
IF
condition=
{
tempPageMenuHidden
}
>
+
</
IF
>
<
IF
condition=
{
NOT
(
tempPageMenuHidden
)
}
>
–
</
IF
>
</
button
>
<
div
cls=
{
D
.
cls
({
'hidden'
:
tempPageMenuHidden
})
}
>
{
Object
.
keys
(
Page
).
map
(
name
=>
<
button
class=
"temp-button"
type=
{
'button'
}
onClick=
{
()
=>
store
.
set
(
'navigation.current'
,
name
)
}
>
{
name
}
</
button
>
)
}
</
div
>
</
div
>
<
IF
condition=
{
NOT
(
store
.
valEqual
(
'navigation.current'
,
'login'
))
}
>
<
div
className=
"page-header__wrapper"
>
...
...
src/view/block/header/Header.scss
View file @
c2a7b2a2
...
...
@@ -130,4 +130,14 @@
top
:
0
;
left
:
0
;
z-index
:
1
;
.hidden
{
display
:
none
;
}
.temp-button
{
display
:
block
;
margin
:
10px
;
width
:
160px
;
padding
:
8px
0
;
}
}
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