aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qtquick/canvas/twitterfriends/cache.js
blob: 6c8a1cd71a650f01aeffd713312bd77bc6899238 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var UserCache = function() {
  this._users = [];
}


UserCache.prototype.getById = function(id){
  for (var i=0; i < this._users.length; i++){
    var user = this._users[i];
    if (user.twitterId == id) {
      return user;
    }
  }
}
UserCache.prototype.getByName = function(name){
  for (var i=0; i < this._users.length; i++){
    var user = this._users[i];
    if (user.name == name)
        return user;
  }
}

UserCache.prototype.add = function(user){
  this._users[this._users.length] = user;
}


var cache = new UserCache;

function getById(id) {
    return cache.getById(id);
}

function getByName(name) {
    return cache.getByName(name);
}

function createTwitterUser(canvas) {
    var user = Qt.createQmlObject("import QtQuick 2.0; TwitterUser{}", canvas);
    user.canvas = canvas;
    cache.add(user);
    return user;
}