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
7b1945f7
Commit
7b1945f7
authored
Dec 08, 2020
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sync ability
parent
4450ec0f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
Store.js
Store.js
+53
-0
No files found.
Store.js
View file @
7b1945f7
...
@@ -445,8 +445,61 @@ Store.prototype = {
...
@@ -445,8 +445,61 @@ Store.prototype = {
},
},
valFalse
:
function
(
key
)
{
valFalse
:
function
(
key
)
{
return
this
.
valEqual
(
key
,
false
);
return
this
.
valEqual
(
key
,
false
);
},
sync
:
function
(
key
,
version
,
saveInterface
)
{
saveInterface
=
saveInterface
||
Store
.
SaveInterface
.
LocalStorage
;
var
iface
=
new
saveInterface
(
key
,
version
,
this
);
this
.
_props
.
_VERSION_
=
version
;
iface
.
load
(
function
(
err
,
data
)
{
if
(
err
)
return
;
if
(
data
.
_VERSION_
>=
version
){
if
(
!
(
'_VERSION_'
in
data
)
||
data
.
_VERSION_
===
version
){
for
(
var
k
in
data
){
this
.
set
(
k
,
data
[
k
]
);
}
}
}
else
{
iface
.
save
();
}
});
var
shouldSave
,
saveFn
=
function
()
{
iface
.
save
();
clearTimeout
(
shouldSave
)
shouldSave
=
false
;
};
this
.
events
.
on
(
'change'
,
function
()
{
if
(
!
shouldSave
)
shouldSave
=
setTimeout
(
saveFn
,
500
);
});
this
.
save
=
saveFn
;
}
};
Store
.
SaveInterface
=
{};
// interface for save and load data
Store
.
SaveInterface
.
LocalStorage
=
function
(
key
,
store
)
{
this
.
key
=
key
;
this
.
store
=
store
;
};
Store
.
SaveInterface
.
LocalStorage
.
prototype
=
{
load
:
function
(
cb
)
{
var
data
=
{};
try
{
data
=
JSON
.
parse
(
localStorage
.
getItem
(
this
.
key
)
);
}
catch
(
e
){}
cb
&&
cb
(
false
,
data
);
return
data
;
},
// Should support full save if arguments.length === 0
save
:
function
(
key
,
val
)
{
localStorage
.
setItem
(
this
.
key
,
JSON
.
stringify
(
this
.
store
.
_props
));
}
}
};
};
const
StoreBinding
=
function
(
store
,
key
){
const
StoreBinding
=
function
(
store
,
key
){
this
.
store
=
store
;
this
.
store
=
store
;
this
.
key
=
key
;
this
.
key
=
key
;
...
...
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