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
274eb82d
Commit
274eb82d
authored
Apr 24, 2021
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
import store tests
DOM: more complex recursive events Store: Working Store.Value.Array binding
parent
62b92199
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
32 deletions
+54
-32
DOM.js
DOM.js
+8
-2
Store.js
Store.js
+46
-30
store.js
test/store.js
+0
-0
No files found.
DOM.js
View file @
274eb82d
...
@@ -271,8 +271,14 @@ NS.apply = function(a,b) {
...
@@ -271,8 +271,14 @@ NS.apply = function(a,b) {
D
.
_recursiveCmpCall
=
function
(
el
,
sub
,
fnName
){
D
.
_recursiveCmpCall
=
function
(
el
,
sub
,
fnName
){
if
(
sub
.
__cmp
)
if
(
sub
.
__cmp
)
sub
.
__cmp
[
fnName
]
&&
sub
.
__cmp
[
fnName
](
el
);
sub
.
__cmp
[
fnName
]
&&
sub
.
__cmp
[
fnName
](
el
);
for
(
var
i
=
0
,
_i
=
sub
.
childNodes
.
length
;
i
<
_i
;
i
++
){
var
childNode
=
sub
.
childNodes
[
i
];
var
children
=
Array
.
isArray
(
sub
)
?
sub
:
sub
.
childNodes
;
for
(
var
i
=
0
,
_i
=
children
.
length
;
i
<
_i
;
i
++
){
var
childNode
=
children
[
i
];
if
(
'dom'
in
childNode
){
childNode
=
childNode
.
dom
;
}
D
.
_recursiveCmpCall
(
sub
,
childNode
,
fnName
);
D
.
_recursiveCmpCall
(
sub
,
childNode
,
fnName
);
}
}
};
};
...
...
Store.js
View file @
274eb82d
...
@@ -409,7 +409,7 @@ Store.prototype = {
...
@@ -409,7 +409,7 @@ Store.prototype = {
return
this
;
return
this
;
},
},
bind
:
function
(
key
)
{
bind
:
function
(
key
)
{
return
new
StoreBinding
(
this
,
key
);
return
Array
.
isArray
(
this
.
_props
[
key
])
?
this
.
array
(
key
):
new
StoreBinding
(
this
,
key
);
},
},
val
:
function
(
key
)
{
val
:
function
(
key
)
{
const
me
=
this
;
const
me
=
this
;
...
@@ -638,7 +638,7 @@ HookPrototype.prototype = {
...
@@ -638,7 +638,7 @@ HookPrototype.prototype = {
val
=
this
.
setter
(
val
);
val
=
this
.
setter
(
val
);
var
oldVal
=
this
.
get
();
var
oldVal
=
this
.
get
();
if
(
!
this
.
equal
(
oldVal
,
val
)){
if
(
!
this
.
equal
(
oldVal
,
val
)){
this
.
data
=
val
;
this
.
_props
=
val
;
this
.
_emit
(
oldVal
,
val
);
this
.
_emit
(
oldVal
,
val
);
}
}
},
},
...
@@ -646,7 +646,7 @@ HookPrototype.prototype = {
...
@@ -646,7 +646,7 @@ HookPrototype.prototype = {
return
newVal
===
oldVal
;
return
newVal
===
oldVal
;
},
},
get
:
function
()
{
get
:
function
()
{
return
this
.
data
;
return
this
.
_props
;
},
},
binding
:
function
()
{
binding
:
function
()
{
var
x
=
new
StoreBinding
();
var
x
=
new
StoreBinding
();
...
@@ -673,11 +673,11 @@ HookPrototype.prototype = {
...
@@ -673,11 +673,11 @@ HookPrototype.prototype = {
}
}
}
}
};
};
var
HookFactory
=
function
(
accessor
)
{
var
HookFactory
=
function
(
accessor
,
baseObjectCtor
)
{
var
Hook
=
function
(
cfg
)
{
var
Hook
=
function
(
cfg
)
{
if
(
!
(
this
instanceof
Hook
))
if
(
!
(
this
instanceof
Hook
))
return
new
Hook
(
cfg
);
return
new
Hook
(
cfg
);
this
.
data
=
{};
this
.
_props
=
baseObjectCtor
?
baseObjectCtor
(
this
,
cfg
)
:
{};
this
.
subscribers
=
[];
this
.
subscribers
=
[];
this
.
set
(
cfg
);
this
.
set
(
cfg
);
};
};
...
@@ -694,24 +694,7 @@ Store.getValue = function(val) {
...
@@ -694,24 +694,7 @@ Store.getValue = function(val) {
}
}
};
};
Store
.
Value
=
{
Boolean
:
new
HookFactory
({
setter
:
function
(
val
)
{
return
!!
val
;
},
toggle
:
function
()
{
this
.
set
(
!
this
.
get
());
}
}),
Number
:
new
HookFactory
({
setter
:
function
(
val
)
{
return
val
-
0
;
}
}),
String
:
new
HookFactory
({
setter
:
function
(
val
)
{
return
val
+
''
;
}
}),
Integer
:
new
HookFactory
({
setter
:
function
(
val
)
{
return
val
|
0
;
}
}),
Any
:
new
HookFactory
(),
Array
:
new
HookFactory
(),
Function
:
new
HookFactory
()
};
Store
.
HookPrototype
=
HookPrototype
;
Store
.
HookPrototype
=
HookPrototype
;
/*
/*
...
@@ -727,15 +710,19 @@ var fns = Array.prototype;
...
@@ -727,15 +710,19 @@ var fns = Array.prototype;
const
ArrayStore
=
function
(
cfg
)
{
const
ArrayStore
=
function
(
cfg
)
{
Store
.
call
(
this
,
cfg
);
Store
.
call
(
this
,
cfg
);
this
.
_exposeGet
();
this
.
length
=
this
.
_props
.
length
;
};
ArrayStore
.
prototype
=
{
_exposeGet
:
function
()
{
if
(
!
(
'get'
in
this
.
_props
)
){
if
(
!
(
'get'
in
this
.
_props
)
){
Object
.
defineProperties
(
this
.
_props
,
{
Object
.
defineProperties
(
this
.
_props
,
{
get
:
{
value
:
getter
,
enumerable
:
false
}
get
:
{
value
:
getter
,
enumerable
:
false
}
}
);
}
);
}
}
this
.
length
=
this
.
_props
.
length
;
return
this
.
_props
;
};
},
ArrayStore
.
prototype
=
{
length
:
0
,
length
:
0
,
indexOf
:
function
(
a
)
{
indexOf
:
function
(
a
)
{
if
(
typeof
a
===
'function'
){
if
(
typeof
a
===
'function'
){
...
@@ -814,7 +801,8 @@ ArrayStore.prototype = {
...
@@ -814,7 +801,8 @@ ArrayStore.prototype = {
}
else
if
(
type
===
'number'
){
}
else
if
(
type
===
'number'
){
_key
=
[
key
];
_key
=
[
key
];
}
}
if
(
_key
.
length
===
1
){
//if(_key.length === 1){
if
(
Array
.
isArray
(
key
)
&&
arguments
.
length
===
1
){
if
(
Array
.
isArray
(
key
)
&&
arguments
.
length
===
1
){
this
.
splice
.
apply
(
this
,
[
0
,
this
.
length
].
concat
(
key
)
)
this
.
splice
.
apply
(
this
,
[
0
,
this
.
length
].
concat
(
key
)
)
return
this
;
return
this
;
...
@@ -823,9 +811,9 @@ ArrayStore.prototype = {
...
@@ -823,9 +811,9 @@ ArrayStore.prototype = {
return
void
0
;
// for same behavior we return empty array
return
void
0
;
// for same behavior we return empty array
}
}
return
this
.
splice
(
key
,
1
,
item
)[
0
];
return
this
.
splice
(
key
,
1
,
item
)[
0
];
}
else
{
/*
}else{
return this.item(_key[0]).set(_key.slice(1), item);
return this.item(_key[0]).set(_key.slice(1), item);
}
}
*/
},
},
iterator
:
function
(
start
){
iterator
:
function
(
start
){
return
new
Iterator
(
this
,
start
);
return
new
Iterator
(
this
,
start
);
...
@@ -872,5 +860,32 @@ ArrayStore.prototype = {
...
@@ -872,5 +860,32 @@ ArrayStore.prototype = {
ArrayStore
.
prototype
=
Object
.
assign
(
new
Store
(),
ArrayStore
.
prototype
);
ArrayStore
.
prototype
=
Object
.
assign
(
new
Store
(),
ArrayStore
.
prototype
);
Store
.
ArrayStore
=
ArrayStore
;
Store
.
ArrayStore
=
ArrayStore
;
// Object.assign does not work with nested prototypes
ArrayStore
.
linearPrototype
=
{};
for
(
var
i
in
ArrayStore
.
prototype
){
ArrayStore
.
linearPrototype
[
i
]
=
ArrayStore
.
prototype
[
i
];
}
Store
.
Value
=
{
Boolean
:
new
HookFactory
({
setter
:
function
(
val
)
{
return
!!
val
;
},
toggle
:
function
()
{
this
.
set
(
!
this
.
get
());
}
}),
Number
:
new
HookFactory
({
setter
:
function
(
val
)
{
return
val
-
0
;
}
}),
String
:
new
HookFactory
({
setter
:
function
(
val
)
{
return
val
+
''
;
}
}),
Integer
:
new
HookFactory
({
setter
:
function
(
val
)
{
return
val
|
0
;
}
}),
Any
:
new
HookFactory
(),
Array
:
new
HookFactory
(
ArrayStore
.
linearPrototype
,
function
(
obj
){
return
obj
.
_exposeGet
.
call
({
_props
:
[]});
}),
Function
:
new
HookFactory
()
};
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
test/store.js
0 → 100644
View file @
274eb82d
This diff is collapsed.
Click to expand it.
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