Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
react-vanilla
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
Иван Кубота
react-vanilla
Commits
4450ec0f
Commit
4450ec0f
authored
Nov 17, 2020
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
build and update Store
parent
8c1c32e6
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
30 deletions
+83
-30
.gitignore
.gitignore
+1
-0
DOM.js
DOM.js
+26
-12
Store.js
Store.js
+55
-17
build.js
build.js
+1
-1
.touch
build/.touch
+0
-0
No files found.
.gitignore
View file @
4450ec0f
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
# production
# production
/build
/build
^/build/.touch
# misc
# misc
.DS_Store
.DS_Store
...
...
DOM.js
View file @
4450ec0f
...
@@ -80,8 +80,7 @@ NS.apply = function(a,b) {
...
@@ -80,8 +80,7 @@ NS.apply = function(a,b) {
prop
=
cfg
.
prop
,
prop
=
cfg
.
prop
,
on
=
cfg
.
on
||
{},
on
=
cfg
.
on
||
{},
renderTo
=
cfg
.
renderTo
,
renderTo
=
cfg
.
renderTo
,
el
=
cfg
.
el
||
(
type
in
customElementCreate
?
customElementCreate
[
type
](
type
,
cfg
)
:
document
.
createElement
(
type
)),
el
=
cfg
.
el
||
(
type
in
customElementCreate
?
customElementCreate
[
type
](
type
,
cfg
)
:
document
.
createElement
(
type
));
classList
=
el
.
classList
;
var
i
,
_i
,
name
;
var
i
,
_i
,
name
;
...
@@ -189,7 +188,7 @@ NS.apply = function(a,b) {
...
@@ -189,7 +188,7 @@ NS.apply = function(a,b) {
};
};
'div,template,span,input,label,canvas,span,textarea,table,tr,td,th,tBody,tHead'
.
split
(
','
).
forEach
(
function
(
name
){
'div,template,span,input,label,canvas,span,textarea,table,tr,td,th,tBody,tHead'
.
split
(
','
).
forEach
(
function
(
name
){
D
[
name
]
=
function
(){
D
[
name
]
=
function
(){
return
domEl
.
apply
(
null
,
[
name
].
concat
(
ArraySlice
.
call
(
arguments
)))
return
domEl
.
apply
(
null
,
[
name
].
concat
(
ArraySlice
.
call
(
arguments
)))
;
};
};
}
);
}
);
...
@@ -311,12 +310,14 @@ NS.apply = function(a,b) {
...
@@ -311,12 +310,14 @@ NS.apply = function(a,b) {
if
(
type
===
'function'
){
if
(
type
===
'function'
){
var
tmp
=
D
.
Text
(
''
);
//( {cls: 'zero-wrapper'} );
var
tmp
=
D
.
Text
(
''
);
//( {cls: 'zero-wrapper'} );
el
.
appendChild
(
tmp
);
el
.
appendChild
(
tmp
);
var
list
=
[];
var
list
=
[],
el
.
setAttribute
(
'data-hooked'
,
'yep'
);
isNotFragment
=
!
(
el
instanceof
DocumentFragment
);
// TODO: add attribute on real add to dom
isNotFragment
&&
el
.
setAttribute
(
'data-hooked'
,
'yep'
);
// maybe do it through outer weak map?
// maybe do it through outer weak map?
el
.
__un
=
el
.
__un
||
[]
;
isNotFragment
&&
(
el
.
__un
=
el
.
__un
||
[])
;
var
hookFn
;
var
hookFn
,
release
;
if
(
isHook
){
if
(
isHook
){
hookFn
=
function
(
val
){
hookFn
=
function
(
val
){
...
@@ -344,8 +345,8 @@ NS.apply = function(a,b) {
...
@@ -344,8 +345,8 @@ NS.apply = function(a,b) {
el
.
insertBefore
(
fragment
,
tmp
);
el
.
insertBefore
(
fragment
,
tmp
);
}
}
};
};
release
=
subEl
.
hook
(
hookFn
);
el
.
__un
.
push
(
subEl
.
hook
(
hookFn
)
);
isNotFragment
&&
el
.
__un
.
push
(
release
);
}
else
{
}
else
{
hookFn
=
function
(){
hookFn
=
function
(){
...
@@ -368,8 +369,8 @@ NS.apply = function(a,b) {
...
@@ -368,8 +369,8 @@ NS.apply = function(a,b) {
return
;
return
;
el
.
insertBefore
(
fragment
,
tmp
);
el
.
insertBefore
(
fragment
,
tmp
);
};
};
release
=
subEl
(
hookFn
);
el
.
__un
.
push
(
subEl
(
hookFn
)
);
isNotFragment
&&
el
.
__un
.
push
(
release
);
}
}
}
else
if
(
subEl
!==
void
0
&&
subEl
!==
false
&&
subEl
!==
null
){
}
else
if
(
subEl
!==
void
0
&&
subEl
!==
false
&&
subEl
!==
null
){
el
.
appendChild
(
D
.
Text
(
subEl
)
);
el
.
appendChild
(
D
.
Text
(
subEl
)
);
...
@@ -530,7 +531,20 @@ NS.apply = function(a,b) {
...
@@ -530,7 +531,20 @@ NS.apply = function(a,b) {
u
.
dom
=
_construct
(
ctor
,
u
.
cfg
,
u
.
p
);
u
.
dom
=
_construct
(
ctor
,
u
.
cfg
,
u
.
p
);
d
.
dom
&&
(
d
=
d
.
dom
);
d
.
dom
&&
(
d
=
d
.
dom
);
if
(
d
.
parentNode
){
if
(
d
.
parentNode
){
d
.
parentNode
.
replaceChild
(
'dom'
in
u
.
dom
?
u
.
dom
.
dom
:
u
.
dom
,
d
)
var
dParent
=
d
.
parentNode
,
isInDOM
=
D
.
isInDOM
(
dParent
),
newChild
=
u
.
dom
;
if
(
'dom'
in
u
.
dom
){
newChild
=
newChild
.
dom
;
newChild
.
__cmp
=
u
.
dom
;
}
isInDOM
&&
D
.
_recursiveCmpCall
(
dParent
,
d
,
'beforeRemoveFromDOM'
);
isInDOM
&&
D
.
_recursiveCmpCall
(
dParent
,
newChild
,
'beforeAddToDOM'
);
d
.
parentNode
.
replaceChild
(
newChild
,
d
)
isInDOM
&&
D
.
_recursiveCmpCall
(
dParent
,
d
,
'afterRemoveFromDOM'
);
isInDOM
&&
D
.
_recursiveCmpCall
(
dParent
,
newChild
,
'afterAddToDOM'
);
}
}
}
}
}
else
{
}
else
{
...
...
Store.js
View file @
4450ec0f
...
@@ -99,17 +99,17 @@ var StoreParent = function(parent, key, item) {
...
@@ -99,17 +99,17 @@ var StoreParent = function(parent, key, item) {
};
};
StoreParent
.
prototype
=
{
StoreParent
.
prototype
=
{
getKey
:
function
()
{
getKey
:
function
()
{
if
(
this
.
item
){
if
(
this
.
key
!==
null
&&
this
.
key
!==
void
0
){
return
this
.
key
;
}
else
{
var
idx
=
this
.
parent
.
_props
.
indexOf
(
this
.
item
);
var
idx
=
this
.
parent
.
_props
.
indexOf
(
this
.
item
);
if
(
idx
>
-
1
)
if
(
idx
>
-
1
)
return
idx
;
return
idx
;
console
.
error
(
'try to write to not existed item'
);
console
.
error
(
'try to write to not existed item'
);
}
else
{
return
this
.
key
;
}
}
},
},
getPointer
:
function
()
{
getPointer
:
function
()
{
return
this
.
parent
.
_props
[
this
.
getKey
()]
;
return
this
.
parent
.
get
(
this
.
getKey
())
;
}
}
};
};
Store
.
prototype
=
{
Store
.
prototype
=
{
...
@@ -182,15 +182,35 @@ Store.prototype = {
...
@@ -182,15 +182,35 @@ Store.prototype = {
key: String, val: any
key: String, val: any
key: {k: v, ...}
key: {k: v, ...}
*/
*/
set
:
function
(
key
,
val
,
changeList
)
{
set
:
function
(
key
,
val
,
changeList
,
bubbleState
)
{
var
isChangeList
=
changeList
!==
void
0
;
var
isChangeList
=
changeList
!==
void
0
;
changeList
=
changeList
||
[];
if
(
!
changeList
){
bubbleState
=
true
;
changeList
=
[];
}
var
type
=
typeof
key
;
var
type
=
typeof
key
;
if
(
bubbleState
&&
this
.
parent
){
var
parentKey
=
this
.
parent
.
getKey
();
if
(
type
===
'object'
){
Store
.
prototype
.
set
.
call
(
this
.
parent
.
parent
,
parentKey
,
key
);
}
else
{
Store
.
prototype
.
set
.
call
(
this
.
parent
.
parent
,
parentKey
+
'.'
+
key
,
val
);
}
return
this
;
}
else
{
bubbleState
=
false
}
if
(
type
===
'object'
){
if
(
type
===
'object'
){
for
(
let
k
in
key
){
for
(
let
k
in
key
){
this
.
set
(
k
,
key
[
k
],
changeList
);
this
.
set
(
k
,
key
[
k
],
changeList
,
bubbleState
);
}
}
this
.
_notify
(
changeList
);
this
.
_notify
(
changeList
);
return
this
;
return
this
;
...
@@ -203,18 +223,21 @@ Store.prototype = {
...
@@ -203,18 +223,21 @@ Store.prototype = {
_key
=
key
.
split
(
'.'
);
_key
=
key
.
split
(
'.'
);
}
else
if
(
type
===
'number'
){
}
else
if
(
type
===
'number'
){
_key
=
[
key
];
_key
=
[
key
];
}
}
this
.
_set
(
this
.
_set
(
_key
,
_key
,
val
,
val
,
this
.
parent
?
this
.
parent
.
getPointer
()
:
this
.
_props
,
this
.
_props
,
changeList
changeList
);
);
if
(
!
isChangeList
)
if
(
!
isChangeList
)
this
.
_notify
(
changeList
);
this
.
_notify
(
changeList
);
return
this
;
return
this
;
},
},
reSet
:
function
(
key
,
val
,
changeList
)
{
reSet
:
function
(
key
,
val
,
changeList
)
{
...
@@ -234,7 +257,7 @@ Store.prototype = {
...
@@ -234,7 +257,7 @@ Store.prototype = {
key
=
list
.
join
(
'.'
);
key
=
list
.
join
(
'.'
);
changeList
.
push
([
key
,
this
.
get
(
key
)]);
changeList
.
push
([
key
,
this
.
get
(
key
)]);
}
}
this
.
_notify
(
changeList
,
''
,
additional
)
if
(
this
.
parent
){
if
(
this
.
parent
){
changeListBubbled
.
push
(
this
.
parent
.
getKey
());
changeListBubbled
.
push
(
this
.
parent
.
getKey
());
if
(
prefix
)
{
if
(
prefix
)
{
...
@@ -242,19 +265,33 @@ Store.prototype = {
...
@@ -242,19 +265,33 @@ Store.prototype = {
}
else
{
}
else
{
this
.
parent
.
parent
.
_notifyBubble
(
changeListBubbled
,
this
.
parent
.
getKey
(),
additional
);
this
.
parent
.
parent
.
_notifyBubble
(
changeListBubbled
,
this
.
parent
.
getKey
(),
additional
);
}
}
}
else
{
this
.
_notify
(
changeList
,
''
,
additional
)
}
}
//debugger
//debugger
},
},
_notifyDeep
:
function
(
evt
,
fullKey
,
val
,
additional
)
{
this
.
events
.
fire
(
evt
,
fullKey
,
val
,
additional
);
this
.
fire
(
fullKey
,
val
,
additional
);
var
tokens
=
fullKey
.
split
(
'.'
);
if
(
tokens
.
length
>
1
){
if
(
tokens
[
0
]
in
this
.
arrays
){
this
.
arrays
[
tokens
[
0
]].
_notifyDeep
(
evt
,
tokens
.
slice
(
1
).
join
(
'.'
),
val
,
additional
);
}
else
if
(
this
.
items
.
has
(
this
.
_props
[
tokens
[
0
]])){
this
.
items
.
get
(
this
.
_props
[
tokens
[
0
]]).
_notifyDeep
(
evt
,
tokens
.
slice
(
1
).
join
(
'.'
),
val
,
additional
);
}
}
},
_notify
:
function
(
changeList
,
prefix
,
additional
)
{
_notify
:
function
(
changeList
,
prefix
,
additional
)
{
prefix
=
prefix
||
''
;
prefix
=
prefix
===
void
0
?
''
:
prefix
;
for
(
let
i
=
changeList
.
length
;
i
;
){
for
(
let
i
=
changeList
.
length
;
i
;
){
const
changeListElement
=
changeList
[
--
i
];
const
changeListElement
=
changeList
[
--
i
];
var
key
=
changeListElement
[
0
],
val
=
changeListElement
[
1
],
var
key
=
changeListElement
[
0
],
val
=
changeListElement
[
1
],
fullKey
=
prefix
+
(
key
===
''
?
''
:(
prefix
===
''
?
''
:
'.'
)
+
key
);
fullKey
=
prefix
+
(
key
===
''
?
''
:(
prefix
===
''
?
''
:
'.'
)
+
key
);
this
.
events
.
fire
(
'change'
,
fullKey
,
changeListElement
[
1
],
additional
);
this
.
_notifyDeep
(
'change'
,
fullKey
,
changeListElement
[
1
],
additional
)
this
.
fire
(
fullKey
,
changeListElement
[
1
],
additional
);
}
}
if
(
this
.
parent
){
if
(
this
.
parent
){
...
@@ -282,7 +319,7 @@ Store.prototype = {
...
@@ -282,7 +319,7 @@ Store.prototype = {
key
=
[
key
];
key
=
[
key
];
}
}
let
ref
=
this
.
parent
?
this
.
parent
.
parent
.
get
(
this
.
parent
.
getKey
()
)
:
this
,
let
ref
=
this
.
parent
?
this
.
parent
.
getPointer
(
)
:
this
,
lastStore
=
ref
,
i
,
_i
;
lastStore
=
ref
,
i
,
_i
;
for
(
i
=
0
,
_i
=
key
.
length
;
i
<
_i
;
i
++
){
for
(
i
=
0
,
_i
=
key
.
length
;
i
<
_i
;
i
++
){
...
@@ -371,7 +408,7 @@ Store.prototype = {
...
@@ -371,7 +408,7 @@ Store.prototype = {
return
this
;
return
this
;
},
},
bind
:
function
(
key
)
{
bind
:
function
(
key
)
{
return
new
StoreBinding
(
this
,
key
);
return
new
StoreBinding
(
this
,
key
);
},
},
val
:
function
(
key
)
{
val
:
function
(
key
)
{
const
me
=
this
;
const
me
=
this
;
...
@@ -654,7 +691,7 @@ ArrayStore.prototype = {
...
@@ -654,7 +691,7 @@ ArrayStore.prototype = {
}
}
return
i
<
_i
?
i
:
-
1
;
return
i
<
_i
?
i
:
-
1
;
}
else
{
}
else
{
return
this
.
_props
.
indexOf
(
a
);
return
this
.
_props
.
indexOf
(
a
);
}
}
},
},
toArray
:
function
()
{
toArray
:
function
()
{
...
@@ -779,7 +816,7 @@ ArrayStore.prototype = {
...
@@ -779,7 +816,7 @@ ArrayStore.prototype = {
}
}
};
};
ArrayStore
.
prototype
=
Object
.
assign
(
new
Store
(),
ArrayStore
.
prototype
);
ArrayStore
.
prototype
=
Object
.
assign
(
new
Store
(),
ArrayStore
.
prototype
);
Store
.
ArrayStore
=
ArrayStore
;
Store
.
ArrayStore
=
ArrayStore
;
typeof
module
===
'object'
&&
(
module
.
exports
=
Store
);
typeof
module
===
'object'
&&
(
module
.
exports
=
Store
);
(
typeof
window
===
'object'
)
&&
(
window
.
Store
=
Store
);
(
typeof
window
===
'object'
)
&&
(
window
.
Store
=
Store
);
\ No newline at end of file
build.js
View file @
4450ec0f
...
@@ -30,7 +30,7 @@ Object
...
@@ -30,7 +30,7 @@ Object
for
(
let
outFileName
in
build
){
for
(
let
outFileName
in
build
){
let
let
dest
=
path
.
join
(
dir
,
outFileName
),
dest
=
path
.
join
(
dir
,
outFileName
)
+
'.js'
,
source
=
header
+
source
=
header
+
(
await
minify
(
(
await
minify
(
build
[
outFileName
].
map
(
fileName
=>
hash
[
fileName
]
).
join
(
';'
)
build
[
outFileName
].
map
(
fileName
=>
hash
[
fileName
]
).
join
(
';'
)
...
...
build/.touch
0 → 100644
View file @
4450ec0f
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