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
Labels
Merge Requests
18
Merge Requests
18
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
jio
Commits
e3bb0d86
Commit
e3bb0d86
authored
Dec 03, 2015
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Queries: drop unused code
parent
0b1dc6ee
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
32 additions
and
116 deletions
+32
-116
Gruntfile.js
Gruntfile.js
+8
-0
src/jio.js
src/jio.js
+0
-64
src/queries/core/complexquery.js
src/queries/core/complexquery.js
+2
-4
src/queries/core/globals.js
src/queries/core/globals.js
+1
-1
src/queries/core/query.js
src/queries/core/query.js
+7
-8
src/queries/core/queryfactory.js
src/queries/core/queryfactory.js
+2
-3
src/queries/core/serializer.js
src/queries/core/serializer.js
+2
-2
src/queries/core/simplequery.js
src/queries/core/simplequery.js
+2
-4
src/queries/core/tool.js
src/queries/core/tool.js
+8
-30
No files found.
Gruntfile.js
View file @
e3bb0d86
...
...
@@ -119,6 +119,14 @@ module.exports = function (grunt) {
],
options
:
{
errorsOnly
:
true
},
directives
:
{
maxlen
:
80
,
indent
:
2
,
maxerr
:
3
,
predef
:
[
'
jIO
'
]
}
},
examples
:
{
...
...
src/jio.js
View file @
e3bb0d86
...
...
@@ -71,70 +71,6 @@
}
util
.
ajax
=
ajax
;
/**
* Clones all native object in deep. Managed types: Object, Array, String,
* Number, Boolean, Function, null.
*
* It can also clone object which are serializable, like Date.
*
* To make a class serializable, you need to implement the `toJSON` function
* which returns a JSON representation of the object. The returned value is
* used as first parameter of the object constructor.
*
* @param {A} object The object to clone
* @return {A} The cloned object
*/
function
deepClone
(
object
)
{
var
i
,
cloned
;
if
(
Array
.
isArray
(
object
))
{
cloned
=
[];
for
(
i
=
0
;
i
<
object
.
length
;
i
+=
1
)
{
cloned
[
i
]
=
deepClone
(
object
[
i
]);
}
return
cloned
;
}
if
(
object
===
null
)
{
return
null
;
}
if
(
typeof
object
===
'
object
'
)
{
if
(
Object
.
getPrototypeOf
(
object
)
===
Object
.
prototype
)
{
cloned
=
{};
for
(
i
in
object
)
{
if
(
object
.
hasOwnProperty
(
i
))
{
cloned
[
i
]
=
deepClone
(
object
[
i
]);
}
}
return
cloned
;
}
if
(
object
instanceof
Date
)
{
// XXX this block is to enable phantomjs and browsers compatibility with
// Date.prototype.toJSON when it is an invalid date. In phantomjs, it
// returns `"Invalid Date"` but in browsers it returns `null`. In
// browsers, giving `null` as parameter to `new Date()` doesn't return
// an invalid date.
// Cloning a date with `return new Date(object)` has problems on
// Firefox.
// I don't know why... (Tested on Firefox 23)
if
(
isFinite
(
object
.
getTime
()))
{
return
new
Date
(
object
.
toJSON
());
}
return
new
Date
(
"
Invalid Date
"
);
}
// clone serializable objects
if
(
typeof
object
.
toJSON
===
'
function
'
)
{
return
new
(
Object
.
getPrototypeOf
(
object
).
constructor
)(
object
.
toJSON
());
}
// cannot clone
return
object
;
}
return
object
;
}
util
.
deepClone
=
deepClone
;
function
readBlobAsText
(
blob
,
encoding
)
{
var
fr
=
new
FileReader
();
return
new
RSVP
.
Promise
(
function
(
resolve
,
reject
,
notify
)
{
...
...
src/queries/core/complexquery.js
View file @
e3bb0d86
/*jslint
indent: 2, maxlen: 80, sloppy: true, nomen
: true */
/*jslint
sloppy
: true */
/*global Query: true, query_class_dict: true, inherits: true,
window, QueryFactory, RSVP */
...
...
@@ -35,12 +35,10 @@ function ComplexQuery(spec, key_schema) {
* @optional
*/
this
.
query_list
=
spec
.
query_list
||
[];
/*jslint unparam: true*/
this
.
query_list
=
this
.
query_list
.
map
(
// decorate the map to avoid sending the index as key_schema argument
function
(
o
,
i
)
{
return
QueryFactory
.
create
(
o
,
key_schema
);
}
function
(
o
)
{
return
QueryFactory
.
create
(
o
,
key_schema
);
}
);
/*jslint unparam: false*/
}
inherits
(
ComplexQuery
,
Query
);
...
...
src/queries/core/globals.js
View file @
e3bb0d86
/*jslint
indent: 2, maxlen: 80,
sloppy: true */
/*jslint sloppy: true */
var
query_class_dict
=
{};
src/queries/core/query.js
View file @
e3bb0d86
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global parseStringToObject: true, emptyFunction: true, sortOn: true, limit:
true, select: true, window, stringEscapeRegexpCharacters: true,
deepClone, RSVP*/
/*jslint sloppy: true */
/*global sortOn: true, limit: true, select: true, window, RSVP*/
/**
* The query to use to filter a list of objects.
...
...
@@ -19,7 +17,7 @@ function Query() {
* @param {Object} object The object shared in the parse process
* @param {Object} option Some option gave in parse()
*/
this
.
onParseStart
=
emptyFunction
;
//
this.onParseStart = emptyFunction;
/**
* Called when parsing a simple query. Must be overridden!
...
...
@@ -28,7 +26,7 @@ function Query() {
* @param {Object} object The object shared in the parse process
* @param {Object} option Some option gave in parse()
*/
this
.
onParseSimpleQuery
=
emptyFunction
;
//
this.onParseSimpleQuery = emptyFunction;
/**
* Called when parsing a complex query. Must be overridden!
...
...
@@ -37,7 +35,7 @@ function Query() {
* @param {Object} object The object shared in the parse process
* @param {Object} option Some option gave in parse()
*/
this
.
onParseComplexQuery
=
emptyFunction
;
//
this.onParseComplexQuery = emptyFunction;
/**
* Called after parsing the query. Must be overridden!
...
...
@@ -46,8 +44,9 @@ function Query() {
* @param {Object} object The object shared in the parse process
* @param {Object} option Some option gave in parse()
*/
this
.
onParseEnd
=
emptyFunction
;
//
this.onParseEnd = emptyFunction;
return
;
}
/**
...
...
src/queries/core/queryfactory.js
View file @
e3bb0d86
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global window, ComplexQuery, SimpleQuery, Query, parseStringToObject,
query_class_dict */
/*jslint sloppy: true */
/*global window, Query, parseStringToObject, query_class_dict */
/**
* Provides static methods to create Query object
...
...
src/queries/core/serializer.js
View file @
e3bb0d86
/*jslint
indent: 2, maxlen: 80, sloppy: true, nomen
: true */
/*global Query
, exports
*/
/*jslint
sloppy
: true */
/*global Query*/
function
objectToSearchText
(
query
)
{
var
str_list
=
[];
...
...
src/queries/core/simplequery.js
View file @
e3bb0d86
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global Query, inherits, query_class_dict, window,
searchTextToRegExp, RSVP */
/*jslint sloppy: true, nomen: true */
/*global inherits, query_class_dict, window, searchTextToRegExp, RSVP, Query */
var
checkKeySchema
=
function
(
key_schema
)
{
var
prop
;
...
...
@@ -114,7 +113,6 @@ SimpleQuery.prototype.match = function (item) {
value
=
null
,
key
=
this
.
key
;
/*jslint regexp: true */
if
(
!
(
/^
(?:
!
?
=|<=
?
|>=
?)
$/i
.
test
(
operator
)))
{
// `operator` is not correct, we have to change it to "like" or "="
if
(
/%/
.
test
(
this
.
value
))
{
...
...
src/queries/core/tool.js
View file @
e3bb0d86
/*jslint
indent: 2, maxlen: 80,
sloppy: true, nomen: true */
/*global Query, RSVP
, deepClone
*/
/*jslint sloppy: true, nomen: true */
/*global Query, RSVP*/
/**
* Escapes regexp special chars from a string.
...
...
@@ -106,22 +106,13 @@ function inherits(constructor, superConstructor) {
}
/**
* Does nothing
*/
function
emptyFunction
()
{
return
;
}
/**
* Filter a list of items, modifying them to select only wanted keys. If
* `clone` is true, then the method will act on a cloned list.
* Filter a list of items, modifying them to select only wanted keys.
*
* @param {Array} select_option Key list to keep
* @param {Array} list The item list to filter
* @param {Boolean} [clone=false] If true, modifies a clone of the list
* @return {Array} The filtered list
*/
function
select
(
select_option
,
list
,
clone
)
{
function
select
(
select_option
,
list
)
{
var
i
,
j
,
new_item
;
if
(
!
Array
.
isArray
(
select_option
))
{
throw
new
TypeError
(
"
jioquery.select():
"
+
...
...
@@ -131,9 +122,6 @@ function select(select_option, list, clone) {
throw
new
TypeError
(
"
jioquery.select():
"
+
"
Argument 2 is not of type Array
"
);
}
if
(
clone
===
true
)
{
list
=
deepClone
(
list
);
}
for
(
i
=
0
;
i
<
list
.
length
;
i
+=
1
)
{
new_item
=
{};
for
(
j
=
0
;
j
<
select_option
.
length
;
j
+=
1
)
{
...
...
@@ -154,23 +142,18 @@ function select(select_option, list, clone) {
Query
.
select
=
select
;
/**
* Sort a list of items, according to keys and directions. If `clone` is true,
* then the method will act on a cloned list.
* Sort a list of items, according to keys and directions.
*
* @param {Array} sort_on_option List of couples [key, direction]
* @param {Array} list The item list to sort
* @param {Boolean} [clone=false] If true, modifies a clone of the list
* @return {Array} The filtered list
*/
function
sortOn
(
sort_on_option
,
list
,
clone
)
{
function
sortOn
(
sort_on_option
,
list
)
{
var
sort_index
;
if
(
!
Array
.
isArray
(
sort_on_option
))
{
throw
new
TypeError
(
"
jioquery.sortOn():
"
+
"
Argument 1 is not of type 'array'
"
);
}
if
(
clone
)
{
list
=
deepClone
(
list
);
}
for
(
sort_index
=
sort_on_option
.
length
-
1
;
sort_index
>=
0
;
sort_index
-=
1
)
{
list
.
sort
(
sortFunction
(
...
...
@@ -184,15 +167,13 @@ function sortOn(sort_on_option, list, clone) {
Query
.
sortOn
=
sortOn
;
/**
* Limit a list of items, according to index and length. If `clone` is true,
* then the method will act on a cloned list.
* Limit a list of items, according to index and length.
*
* @param {Array} limit_option A couple [from, length]
* @param {Array} list The item list to limit
* @param {Boolean} [clone=false] If true, modifies a clone of the list
* @return {Array} The filtered list
*/
function
limit
(
limit_option
,
list
,
clone
)
{
function
limit
(
limit_option
,
list
)
{
if
(
!
Array
.
isArray
(
limit_option
))
{
throw
new
TypeError
(
"
jioquery.limit():
"
+
"
Argument 1 is not of type 'array'
"
);
...
...
@@ -201,9 +182,6 @@ function limit(limit_option, list, clone) {
throw
new
TypeError
(
"
jioquery.limit():
"
+
"
Argument 2 is not of type 'array'
"
);
}
if
(
clone
)
{
list
=
deepClone
(
list
);
}
list
.
splice
(
0
,
limit_option
[
0
]);
if
(
limit_option
[
1
])
{
list
.
splice
(
limit_option
[
1
]);
...
...
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