Skip to content

Commit

Permalink
Merge pull request #14 from paul-hanneforth/dev
Browse files Browse the repository at this point in the history
v3.0.7
  • Loading branch information
paul-hanneforth authored Jun 4, 2021
2 parents 735ba0b + f538533 commit f2d9c21
Show file tree
Hide file tree
Showing 46 changed files with 2,318 additions and 4,874 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
},
"env": {
"es6": true
}
},
"parser": "babel-eslint"
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
cookies.json
gen-docs.cmd
test.js
dev.js
dev.js
session.json
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs
101 changes: 101 additions & 0 deletions cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const { SearchResult, User, UserDetails, Post, PostDetails } = require("./class.js");

class FollowingList {

/**
* @constructor
* @param {User} user
* @param {User[]} following
* @property {User} user
* @property {User[]} following
*/
constructor(user, following) {
this.user = user;
this.following = following;
}

}
class FollowerList {

/**
* @constructor
* @param {User} user
* @param {User[]} follower
* @property {User} user
* @property {User[]} follower
*/
constructor(user, follower) {
this.user = user;
this.follower = follower;
}

}

class Cache {

/**
* @constructor
* @param {FollowingList[]} followingLists
* @param {FollowerList[]} followerLists
* @property {FollowingList[]} [ followingLists = [] ]
* @property {FollowerList[]} [ followerLists = [] ]
*/
constructor(followingLists, followerLists) {
this.followingLists = followingLists ? followingLists : [];
this.followerLists = followerLists ? followerLists : [];
}

/**
*
* @returns {Cache} empty cache
*/
static empty() {
return new Cache([], []);
}

/**
*
* @param {User} user
* @param {User[]} following
* @returns {Cache}
*/
addFollowingList(user, following) {
const newFollowingLists = this.followingLists.concat(new FollowingList(user, following));
const newCache = new Cache(newFollowingLists, this.followerLists);
return newCache;
}

/**
*
* @param {User} user
* @param {User[]} followers
* @returns {Cache}
*/
addFollowerList(user, followers) {
const newFollowerLists = this.followerLists.concat(new FollowerList(user, followers));
return new Cache(this.followingLists, newFollowerLists);
}

/**
*
* @param {User} user
* @returns {User[]} list of people who the specified user follows
*/
findFollowingList(user) {
const selectedFollowingList = this.followingLists.find(followingList => followingList.user.username === user.username);
return selectedFollowingList ? selectedFollowingList.following : [];
}

/**
*
* @param {User} user
* @returns {User[]} list of people who the specified user follows
*/
findFollowerList(user) {
const selectedFollowerList = this.followerLists.find(followerList => followerList.user.username === user.username);
return selectedFollowerList ? selectedFollowerList.follower : [];
}

}

module.exports = { Cache };
Loading

0 comments on commit f2d9c21

Please sign in to comment.