Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
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
Jérome Perrin
gitlab-ce
Commits
c1026567
Commit
c1026567
authored
May 16, 2017
by
winh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract Cache class from AjaxCache
parent
e15aee2b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
14 deletions
+88
-14
app/assets/javascripts/lib/utils/ajax_cache.js
app/assets/javascripts/lib/utils/ajax_cache.js
+4
-14
app/assets/javascripts/lib/utils/cache.js
app/assets/javascripts/lib/utils/cache.js
+19
-0
spec/javascripts/lib/utils/cache_spec.js
spec/javascripts/lib/utils/cache_spec.js
+65
-0
No files found.
app/assets/javascripts/lib/utils/ajax_cache.js
View file @
c1026567
class
AjaxCache
{
import
Cache
from
'
./cache
'
;
class
AjaxCache
extends
Cache
{
constructor
()
{
constructor
()
{
this
.
internalStorage
=
{
}
;
super
()
;
this
.
pendingRequests
=
{
};
this
.
pendingRequests
=
{
};
}
}
get
(
endpoint
)
{
return
this
.
internalStorage
[
endpoint
];
}
hasData
(
endpoint
)
{
return
Object
.
prototype
.
hasOwnProperty
.
call
(
this
.
internalStorage
,
endpoint
);
}
remove
(
endpoint
)
{
delete
this
.
internalStorage
[
endpoint
];
}
retrieve
(
endpoint
)
{
retrieve
(
endpoint
)
{
if
(
this
.
hasData
(
endpoint
))
{
if
(
this
.
hasData
(
endpoint
))
{
return
Promise
.
resolve
(
this
.
get
(
endpoint
));
return
Promise
.
resolve
(
this
.
get
(
endpoint
));
...
...
app/assets/javascripts/lib/utils/cache.js
0 → 100644
View file @
c1026567
class
Cache
{
constructor
()
{
this
.
internalStorage
=
{
};
}
get
(
key
)
{
return
this
.
internalStorage
[
key
];
}
hasData
(
key
)
{
return
Object
.
prototype
.
hasOwnProperty
.
call
(
this
.
internalStorage
,
key
);
}
remove
(
key
)
{
delete
this
.
internalStorage
[
key
];
}
}
export
default
Cache
;
spec/javascripts/lib/utils/cache_spec.js
0 → 100644
View file @
c1026567
import
Cache
from
'
~/lib/utils/cache
'
;
describe
(
'
Cache
'
,
()
=>
{
const
dummyKey
=
'
just some key
'
;
const
dummyValue
=
'
more than a value
'
;
let
cache
;
beforeEach
(()
=>
{
cache
=
new
Cache
();
});
describe
(
'
get
'
,
()
=>
{
it
(
'
return cached data
'
,
()
=>
{
cache
.
internalStorage
[
dummyKey
]
=
dummyValue
;
expect
(
cache
.
get
(
dummyKey
)).
toBe
(
dummyValue
);
});
it
(
'
returns undefined for missing data
'
,
()
=>
{
expect
(
cache
.
internalStorage
[
dummyKey
]).
toBe
(
undefined
);
expect
(
cache
.
get
(
dummyKey
)).
toBe
(
undefined
);
});
});
describe
(
'
hasData
'
,
()
=>
{
it
(
'
return true for cached data
'
,
()
=>
{
cache
.
internalStorage
[
dummyKey
]
=
dummyValue
;
expect
(
cache
.
hasData
(
dummyKey
)).
toBe
(
true
);
});
it
(
'
returns false for missing data
'
,
()
=>
{
expect
(
cache
.
internalStorage
[
dummyKey
]).
toBe
(
undefined
);
expect
(
cache
.
hasData
(
dummyKey
)).
toBe
(
false
);
});
});
describe
(
'
remove
'
,
()
=>
{
it
(
'
removes data from cache
'
,
()
=>
{
cache
.
internalStorage
[
dummyKey
]
=
dummyValue
;
cache
.
remove
(
dummyKey
);
expect
(
cache
.
internalStorage
[
dummyKey
]).
toBe
(
undefined
);
});
it
(
'
does nothing for missing data
'
,
()
=>
{
expect
(
cache
.
internalStorage
[
dummyKey
]).
toBe
(
undefined
);
cache
.
remove
(
dummyKey
);
expect
(
cache
.
internalStorage
[
dummyKey
]).
toBe
(
undefined
);
});
it
(
'
does not remove wrong data
'
,
()
=>
{
cache
.
internalStorage
[
dummyKey
]
=
dummyValue
;
cache
.
internalStorage
[
dummyKey
+
dummyKey
]
=
dummyValue
+
dummyValue
;
cache
.
remove
(
dummyKey
);
expect
(
cache
.
internalStorage
[
dummyKey
]).
toBe
(
undefined
);
expect
(
cache
.
internalStorage
[
dummyKey
+
dummyKey
]).
toBe
(
dummyValue
+
dummyValue
);
});
});
});
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