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
3b2575a3
Commit
3b2575a3
authored
Feb 17, 2022
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Store Feature: Binding.valEqual +test
parent
3a185893
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
0 deletions
+76
-0
Store.js
Store.js
+13
-0
store.js
test/store.js
+63
-0
No files found.
Store.js
View file @
3b2575a3
...
...
@@ -678,6 +678,19 @@ HookPrototype.prototype = {
for
(
var
i
=
0
,
_i
=
subscribers
.
length
;
i
<
_i
;
i
++
){
subscribers
[
i
](
val
);
}
},
valEqual
:
function
(
compareTo
)
{
var
me
=
this
;
return
function
backwardCallback
(
update
)
{
var
cache
;
me
.
hook
(
function
(
val
)
{
var
result
=
me
.
equal
(
val
,
compareTo
);
if
(
result
!==
cache
){
cache
=
result
;
update
(
cache
);
}
});
}
}
};
var
HookFactory
=
function
(
accessor
,
baseObjectCtor
)
{
...
...
test/store.js
View file @
3b2575a3
...
...
@@ -370,3 +370,65 @@ describe('Bug with subscribing to multiple bindings', function() {
}
);
});
});
describe
(
'Feature. Binding.valEqual'
,
function
()
{
it
(
'Should trigger fn when value is changed'
,
function
()
{
var
str
=
new
Store
.
Value
.
String
(
'123'
);
var
changes
=
[];
str
.
valEqual
(
'16'
)(
changes
.
push
.
bind
(
changes
));
//false +init
str
.
set
(
'17'
);
//false
str
.
set
(
'123'
)
//false
str
.
set
(
'17'
);
//false
str
.
set
(
'16'
);
//true +change
str
.
set
(
'88'
)
//false +change
str
.
set
(
'16'
);
//true +change
str
.
set
(
'16'
);
//true
assert
.
deepEqual
(
changes
,
[
false
,
true
,
false
,
true
]);
var
str
=
new
Store
.
Value
.
String
(
'123'
);
var
changes
=
[];
str
.
valEqual
(
'123'
)(
changes
.
push
.
bind
(
changes
));
//true +init
str
.
set
(
'17'
);
//false +change
str
.
set
(
'123'
)
//true +change
str
.
set
(
'17'
);
//false +change
str
.
set
(
'16'
);
//false
str
.
set
(
'88'
)
//false
str
.
set
(
'16'
);
//false
str
.
set
(
'16'
);
//false
assert
.
deepEqual
(
changes
,
[
true
,
false
,
true
,
false
]);
})
});
\ No newline at end of file
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