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
Mukul
jio
Commits
6d8edb39
Commit
6d8edb39
authored
Apr 09, 2014
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
useless code removed
parent
c0c9301e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
209 deletions
+0
-209
src/jio.storage/replicatestorage.js
src/jio.storage/replicatestorage.js
+0
-209
No files found.
src/jio.storage/replicatestorage.js
View file @
6d8edb39
...
@@ -44,219 +44,10 @@
...
@@ -44,219 +44,10 @@
addStorageFunction
=
require
(
'
jio
'
).
addStorage
,
addStorageFunction
=
require
(
'
jio
'
).
addStorage
,
uniqueJSONStringify
=
require
(
'
jio
'
).
util
.
uniqueJSONStringify
;
uniqueJSONStringify
=
require
(
'
jio
'
).
util
.
uniqueJSONStringify
;
/**
* Test if the a value is a date
*
* @param {String,Number,Date} date The date to test
* @return {Boolean} true if success, else false
*/
function
isDate
(
date
)
{
return
!
isNaN
((
new
Date
(
date
===
null
?
undefined
:
date
)).
getTime
());
}
/**
* Executes a sequence of *then* callbacks. It acts like
* `smth().then(callback).then(callback)...`. The first callback is called
* with no parameter.
*
* Elements of `then_list` array can be a function or an array contaning at
* most three *then* callbacks: *onFulfilled*, *onRejected*, *onNotified*.
*
* When `cancel()` is executed, each then promises are cancelled at the same
* time.
*
* sequence(then_list): Promise
*
* @param {Array} then_list An array of *then* callbacks
* @return {Promise} A new promise
*/
function
sequence
(
then_list
)
{
var
promise_list
=
[];
return
new
Promise
(
function
(
resolve
,
reject
,
notify
)
{
var
i
,
length
=
then_list
.
length
;
promise_list
[
0
]
=
new
Promise
(
function
(
resolve
)
{
resolve
();
});
for
(
i
=
0
;
i
<
length
;
i
+=
1
)
{
if
(
Array
.
isArray
(
then_list
[
i
]))
{
promise_list
[
i
+
1
]
=
promise_list
[
i
].
then
(
then_list
[
i
][
0
],
then_list
[
i
][
1
],
then_list
[
i
][
2
]);
}
else
{
promise_list
[
i
+
1
]
=
promise_list
[
i
].
then
(
then_list
[
i
]);
}
}
promise_list
[
i
].
then
(
resolve
,
reject
,
notify
);
},
function
()
{
var
i
,
length
=
promise_list
.
length
;
for
(
i
=
0
;
i
<
length
;
i
+=
1
)
{
promise_list
[
i
].
cancel
();
}
});
}
function
success
(
promise
)
{
function
success
(
promise
)
{
return
promise
.
then
(
null
,
function
(
reason
)
{
return
reason
;
});
return
promise
.
then
(
null
,
function
(
reason
)
{
return
reason
;
});
}
}
// /**
// * Awaits for an answer from one promise only. Promises are cancelled only
// * by calling `first(promise_list).cancel()`.
// *
// * first(promise_list): Promise
// *
// * @param {Array} promise_list An array of promises
// * @return {Promise} A new promise
// */
// function first(promise_list) {
// var length = promise_list.length;
// promise_list = promise_list.slice();
// return new Promise(function (resolve, reject, notify) {
// var index, count = 0;
// function rejecter(answer) {
// count += 1;
// if (count === length) {
// return reject(answer);
// }
// }
// function notifier(index) {
// return function (notification) {
// notify({
// "index": index,
// "value": notification
// });
// };
// }
// for (index = 0; index < length; index += 1) {
// promise_list[index].then(resolve, rejecter, notifier(index));
// }
// }, function () {
// var index;
// for (index = 0; index < length; index += 1) {
// promise_list[index].cancel();
// }
// });
// }
/**
* Responds with the last resolved promise answer recieved. If all promises
* are rejected, it returns the latest rejected promise answer
* received. Promises are cancelled only by calling
* `last(promise_list).cancel()`.
*
* last(promise_list): Promise
*
* @param {Array} promise_list An array of promises
* @return {Promise} A new promise
*/
function
last
(
promise_list
)
{
var
length
=
promise_list
.
length
;
promise_list
=
promise_list
.
slice
();
return
new
Promise
(
function
(
resolve
,
reject
,
notify
)
{
var
index
,
last_answer
,
count
=
0
,
error_count
=
0
;
function
resolver
()
{
return
function
(
answer
)
{
count
+=
1
;
if
(
count
===
length
)
{
return
resolve
(
answer
);
}
last_answer
=
answer
;
};
}
function
rejecter
()
{
return
function
(
answer
)
{
error_count
+=
1
;
if
(
error_count
===
length
)
{
return
reject
(
answer
);
}
count
+=
1
;
if
(
count
===
length
)
{
return
resolve
(
last_answer
);
}
};
}
function
notifier
(
index
)
{
return
function
(
notification
)
{
notify
({
"
index
"
:
index
,
"
value
"
:
notification
});
};
}
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
promise_list
[
index
].
then
(
resolver
(),
rejecter
(),
notifier
(
index
));
}
},
function
()
{
var
index
;
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
promise_list
[
index
].
cancel
();
}
});
}
/**
* Responds with the last modified document recieved. If all promises are
* rejected, it returns the latest rejected promise answer received. Promises
* are cancelled only by calling `lastModified(promise_list).cancel()`. USE
* THIS FUNCTION ONLY FOR GET METHOD!
*
* lastModified(promise_list): Promise
*
* @param {Array} promise_list An array of promises
* @return {Promise} A new promise
*/
function
lastModified
(
promise_list
)
{
var
length
=
promise_list
.
length
;
promise_list
=
promise_list
.
slice
();
return
new
Promise
(
function
(
resolve
,
reject
,
notify
)
{
var
index
,
last_good_answer
,
last_answer
,
count
=
0
,
error_count
=
0
;
function
resolver
(
answer
)
{
last_answer
=
answer
;
if
(
last_good_answer
===
undefined
)
{
if
(
isDate
(
answer
.
data
.
modified
))
{
last_good_answer
=
answer
;
}
}
else
{
if
(
isDate
(
answer
.
data
.
modified
))
{
if
(
new
Date
(
last_good_answer
.
data
.
modified
)
<
new
Date
(
answer
.
data
.
modified
))
{
last_good_answer
=
answer
;
}
}
}
count
+=
1
;
if
(
count
===
length
)
{
return
resolve
(
last_good_answer
);
}
}
function
rejecter
(
answer
)
{
error_count
+=
1
;
if
(
error_count
===
length
)
{
return
reject
(
answer
);
}
count
+=
1
;
if
(
count
===
length
)
{
return
resolve
(
last_good_answer
||
last_answer
);
}
}
function
notifier
(
index
)
{
return
function
(
notification
)
{
notify
({
"
index
"
:
index
,
"
value
"
:
notification
});
};
}
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
promise_list
[
index
].
then
(
resolver
,
rejecter
,
notifier
(
index
));
}
},
function
()
{
var
index
;
for
(
index
=
0
;
index
<
length
;
index
+=
1
)
{
promise_list
[
index
].
cancel
();
}
});
}
/**
/**
* firstFulfilled(promises): promises< last_fulfilment_value >
* firstFulfilled(promises): promises< last_fulfilment_value >
*
*
...
...
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