Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
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
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
49ba9a70
Commit
49ba9a70
authored
Jul 05, 2016
by
Sean Hammond
Committed by
GitHub
Jul 05, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #19 from hypothesis/remove-prepend-transform
Simplify request preparation in `store.js`
parents
52b4235d
a2d9b07b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
20 deletions
+9
-20
store.js
h/static/scripts/store.js
+9
-20
No files found.
h/static/scripts/store.js
View file @
49ba9a70
'use strict'
;
var
angular
=
require
(
'angular'
);
var
get
=
require
(
'lodash.get'
);
var
retryUtil
=
require
(
'./retry-util'
);
var
urlUtil
=
require
(
'./util/url-util'
);
function
prependTransform
(
defaults
,
transform
)
{
// We can't guarantee that the default transformation is an array
var
result
=
angular
.
isArray
(
defaults
)
?
defaults
.
slice
(
0
)
:
[
defaults
];
result
.
unshift
(
transform
);
return
result
;
}
// stripInternalProperties returns a shallow clone of `obj`, lacking all
// properties that begin with a character that marks them as internal
// (currently '$' or '_');
/**
* Return a shallow clone of `obj` with all client-only properties removed.
* Client-only properties are marked by a '$' prefix.
*/
function
stripInternalProperties
(
obj
)
{
var
result
=
{};
...
...
@@ -39,8 +32,8 @@ function forEachSorted(obj, iterator, context) {
function
serializeValue
(
v
)
{
if
(
angular
.
isObject
(
v
)
)
{
return
angular
.
isDate
(
v
)
?
v
.
toISOString
()
:
angular
.
toJson
(
v
);
if
(
typeof
v
===
'object'
)
{
return
v
instanceof
Date
?
v
.
toISOString
()
:
JSON
.
stringify
(
v
);
}
return
v
;
}
...
...
@@ -69,8 +62,8 @@ function serializeParams(params) {
if
(
value
===
null
||
typeof
value
===
'undefined'
)
{
return
;
}
if
(
angular
.
isArray
(
value
))
{
angular
.
forEach
(
value
,
function
(
v
,
k
)
{
if
(
Array
.
isArray
(
value
))
{
value
.
forEach
(
function
(
v
)
{
parts
.
push
(
encodeUriQuery
(
key
)
+
'='
+
encodeUriQuery
(
serializeValue
(
v
)));
});
}
else
{
...
...
@@ -95,15 +88,11 @@ function createAPICall($http, links, route) {
var
descriptor
=
get
(
links
,
route
);
var
url
=
urlUtil
.
replaceURLParams
(
descriptor
.
url
,
params
);
var
req
=
{
data
:
data
,
data
:
data
?
stripInternalProperties
(
data
)
:
null
,
method
:
descriptor
.
method
,
params
:
url
.
params
,
paramSerializer
:
serializeParams
,
url
:
url
.
url
,
transformRequest
:
prependTransform
(
$http
.
defaults
.
transformRequest
,
stripInternalProperties
),
};
return
$http
(
req
);
}).
then
(
function
(
result
)
{
...
...
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