pluotsorbet/libs/contacts.js

61 строка
1.2 KiB
JavaScript
Исходник Обычный вид История

2014-09-17 01:49:25 +04:00
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
'use strict';
var contacts = (function() {
function forEach(callback) {
var sender = DumbPipe.open("contacts", {}, function(message) {
if (message) {
callback(message);
} else {
DumbPipe.close(sender);
}
});
2014-09-17 01:49:25 +04:00
}
function getAll(callback) {
var contacts = [];
var sender = DumbPipe.open("contacts", {}, function(contact) {
if (!contact) {
callback(contacts);
DumbPipe.close(sender);
return;
}
contacts.push(contact);
});
}
var requestHandler = null;
function getNext(callback) {
if (requestHandler) {
callback(requestHandler());
return;
}
getAll(function(contacts) {
var idx = -1;
requestHandler = function() {
idx++;
if (idx < contacts.length) {
return contacts[idx];
}
requestHandler = null;
return null;
}
callback(requestHandler());
});
}
2014-09-17 01:49:25 +04:00
return {
forEach: forEach,
getNext: getNext,
2014-09-17 01:49:25 +04:00
};
})();