Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Yaxel Perez
jio
Commits
66c28293
Commit
66c28293
authored
Feb 16, 2019
by
Yaxel Perez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
made the thing async
parent
40764fad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
33 deletions
+68
-33
src/jio.storage/liststorage.js
src/jio.storage/liststorage.js
+32
-17
src/jio.storage/nocapacitystorage.js
src/jio.storage/nocapacitystorage.js
+0
-1
test/jio.storage/liststorage.tests.js
test/jio.storage/liststorage.tests.js
+36
-15
No files found.
src/jio.storage/liststorage.js
View file @
66c28293
...
...
@@ -15,19 +15,31 @@
"
type
"
:
"
indexeddb
"
,
"
database
"
:
randomId
()
});
this
.
_signature_storage
.
put
(
"
_
"
,
{
list
:
[]
});
}
ListStorage
.
prototype
.
post
=
function
()
{
var
id
=
this
.
_sub_storage
.
post
.
apply
(
this
.
_sub_storage
,
arguments
);
this
.
_signature_storage
.
get
(
'
_
'
).
then
(
function
(
storage
)
{
this
.
_signature_storage
.
put
(
'
_
'
,
{
list
:
storage
.
list
.
concat
(
id
)
});
}).
fail
(
function
(
err
)
{
throw
err
;
ListStorage
.
prototype
.
list
=
function
()
{
// lazily initialize the list in _signature_storage
var
ctx
=
this
;
return
this
.
_signature_storage
.
get
(
'
_
'
).
then
(
function
(
list
)
{
return
list
;
}).
fail
(
function
()
{
return
ctx
.
_signature_storage
.
put
(
'
_
'
,
[]).
then
(
function
()
{
return
[];
});
});
return
id
;
};
ListStorage
.
prototype
.
post
=
function
()
{
var
ctx
=
this
;
return
this
.
_sub_storage
.
post
.
apply
(
this
.
_sub_storage
,
arguments
)
.
then
(
function
(
id
)
{
return
ctx
.
list
().
then
(
function
(
list
)
{
list
.
push
(
id
);
return
ctx
.
_signature_storage
.
put
(
'
_
'
,
list
).
then
(
function
()
{
return
id
;
});
});
});
};
ListStorage
.
prototype
.
get
=
function
()
{
...
...
@@ -35,7 +47,16 @@
};
ListStorage
.
prototype
.
put
=
function
()
{
return
this
.
_sub_storage
.
put
.
apply
(
this
.
_sub_storage
,
arguments
);
var
ctx
=
this
;
return
this
.
_sub_storage
.
put
.
apply
(
this
.
_sub_storage
,
arguments
)
.
then
(
function
(
id
)
{
return
ctx
.
list
().
then
(
function
(
list
)
{
list
.
push
(
id
);
return
ctx
.
_signature_storage
.
put
(
'
_
'
,
list
).
then
(
function
()
{
return
id
;
});
});
});
};
ListStorage
.
prototype
.
remove
=
function
(
id
)
{
...
...
@@ -44,11 +65,5 @@
this
.
_signature_storage
.
put
(
"
_
"
,
{
list
:
updated_list
});
};
ListStorage
.
prototype
.
list
=
function
()
{
return
this
.
_sub_storage
.
get
(
"
_
"
).
then
(
function
(
storage
)
{
return
storage
.
list
;
});
};
jIO
.
addStorage
(
"
list
"
,
ListStorage
);
}(
jIO
));
src/jio.storage/nocapacitystorage.js
View file @
66c28293
...
...
@@ -24,7 +24,6 @@
/*jslint nomen: true*/
(
function
(
jIO
)
{
"
use strict
"
;
console
.
log
(
"
Nocapacity
"
);
function
NoCapacityStorage
(
spec
)
{
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
...
...
test/jio.storage/liststorage.tests.js
View file @
66c28293
(
function
(
jIO
,
RSVP
,
QUnit
)
{
// (function (jIO, RSVP, QUnit) {
(
function
(
jIO
,
QUnit
)
{
"
use strict
"
;
QUnit
.
module
(
"
ListStorage
"
);
...
...
@@ -14,7 +14,9 @@
QUnit
.
expect
(
0
);
});
QUnit
.
test
(
'
list method returns ordered list of ids
'
,
function
(
assert
)
{
// NOTE: list method is implicitly tested in the following two methods
QUnit
.
test
(
'
post method correctly records ids
'
,
function
(
assert
)
{
QUnit
.
stop
();
QUnit
.
expect
(
1
);
...
...
@@ -26,22 +28,41 @@
type
:
'
memory
'
}
}
}),
ids
=
[
jio
.
post
({}),
jio
.
post
({}),
jio
.
post
({})];
});
RSVP
.
all
(
ids
).
then
(
function
(
values
)
{
jio
.
list
().
then
(
function
(
l
ist
)
{
jio
.
post
({}).
then
(
function
(
id1
)
{
jio
.
post
({}).
then
(
function
(
id2
)
{
jio
.
list
().
then
(
function
(
l
)
{
QUnit
.
start
();
assert
.
equal
(
values
,
jio
.
list
());
}).
fail
(
function
(
err
)
{
assert
.
ok
(
false
,
err
);
assert
.
deepEqual
(
l
,
[
id1
,
id2
]);
});
});
}).
fail
(
console
.
error
);
});
QUnit
.
test
(
'
put method correctly records ids
'
,
function
(
assert
)
{
QUnit
.
stop
();
QUnit
.
expect
(
1
);
var
jio
=
jIO
.
createJIO
({
type
:
'
list
'
,
sub_storage
:
{
type
:
'
uuid
'
,
sub_storage
:
{
type
:
'
memory
'
}
}
).
fail
(
function
(
err
)
{
QUnit
.
start
();
assert
.
ok
(
false
,
err
);
});
jio
.
put
(
'
test
'
,
{}).
then
(
function
(
id1
)
{
jio
.
put
(
'
test2
'
,
{}).
then
(
function
(
id2
)
{
jio
.
list
().
then
(
function
(
l
)
{
QUnit
.
start
();
assert
.
deepEqual
(
l
,
[
id1
,
id2
]);
});
});
}).
fail
(
console
.
error
);
});
}(
jIO
,
RSVP
,
QUnit
));
// }(jIO, RSVP, QUnit));
}(
jIO
,
QUnit
));
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