Files: 78c1c971ce74b33515d5785a53347186166297db / modules / profile / obs / rank.js
789 bytesRaw
1 | var computed = require('mutant/computed') |
2 | var nest = require('depnest') |
3 | |
4 | exports.needs = nest({ |
5 | 'profile.obs.recentlyUpdated': 'first' |
6 | }) |
7 | |
8 | exports.gives = nest('profile.obs.rank') |
9 | |
10 | exports.create = function (api) { |
11 | return nest('profile.obs.rank', function (ids, max) { |
12 | var recent = api.profile.obs.recentlyUpdated() |
13 | |
14 | var result = computed([ids, recent], (ids, recent) => { |
15 | var result = [] |
16 | ids.forEach((id) => { |
17 | if (recent.includes(id)) { |
18 | result.push(id) |
19 | } |
20 | }) |
21 | ids.forEach((id) => { |
22 | if (!recent.includes(id)) { |
23 | result.push(id) |
24 | } |
25 | }) |
26 | if (max) { |
27 | result = result.slice(0, max) |
28 | } |
29 | return result |
30 | }, {nextTick: true}) |
31 | |
32 | result.sync = recent.sync |
33 | |
34 | return result |
35 | }) |
36 | } |
37 |
Built with git-ssb-web