Commit fa10ca34011578ba930c05f7c0cfb3fd1c465999
about refactor
mix irving committed on 4/3/2017, 6:02:19 AMParent: 0df4a099fb2371f61e7eeda542c84a1c9e70436e
Files changed
about/async/suggest.js | changed |
about/html/edit.js | changed |
about/async/suggest.js | ||
---|---|---|
@@ -16,9 +16,11 @@ | ||
16 | 16 | exports.create = function (api) { |
17 | 17 | var suggestions = null |
18 | 18 | var recentSuggestions = null |
19 | 19 | |
20 | - return nest('about.async.suggest', function () { | |
20 | + return nest('about.async.suggest', suggest) | |
21 | + | |
22 | + function suggest () { | |
21 | 23 | loadSuggestions() |
22 | 24 | return function (word) { |
23 | 25 | if (!word) { |
24 | 26 | return recentSuggestions() |
@@ -27,34 +29,34 @@ | ||
27 | 29 | return item.title.toLowerCase().startsWith(word.toLowerCase()) |
28 | 30 | }) |
29 | 31 | } |
30 | 32 | } |
31 | - }) | |
33 | + } | |
32 | 34 | |
33 | 35 | function loadSuggestions () { |
34 | - if (!suggestions) { | |
35 | - var id = api.keys.sync.id() | |
36 | - var following = api.contact.obs.following(id) | |
37 | - var recentlyUpdated = api.feed.obs.recent() | |
38 | - var contacts = computed([following, recentlyUpdated], function (a, b) { | |
39 | - var result = Array.from(a) | |
40 | - b.forEach((item, i) => { | |
41 | - if (!result.includes(item)) { | |
42 | - result.push(item) | |
43 | - } | |
44 | - }) | |
45 | - return result | |
36 | + if (suggestions) return | |
37 | + | |
38 | + var id = api.keys.sync.id() | |
39 | + var following = api.contact.obs.following(id) | |
40 | + var recentlyUpdated = api.feed.obs.recent() | |
41 | + var contacts = computed([following, recentlyUpdated], (a, b) => { | |
42 | + var result = Array.from(a) | |
43 | + b.forEach(item => { | |
44 | + if (!result.includes(item)) { | |
45 | + result.push(item) | |
46 | + } | |
46 | 47 | }) |
48 | + return result | |
49 | + }) | |
47 | 50 | |
48 | - recentSuggestions = map( | |
49 | - computed(recentlyUpdated, (items) => Array.from(items).slice(0, 10)), | |
50 | - suggestion, | |
51 | - {idle: true} | |
52 | - ) | |
53 | - suggestions = map(contacts, suggestion, {idle: true}) | |
54 | - watch(recentSuggestions) | |
55 | - watch(suggestions) | |
56 | - } | |
51 | + recentSuggestions = map( | |
52 | + computed(recentlyUpdated, (items) => Array.from(items).slice(0, 10)), | |
53 | + suggestion, | |
54 | + {idle: true} | |
55 | + ) | |
56 | + suggestions = map(contacts, suggestion, {idle: true}) | |
57 | + watch(recentSuggestions) | |
58 | + watch(suggestions) | |
57 | 59 | } |
58 | 60 | |
59 | 61 | function suggestion (id) { |
60 | 62 | var name = api.about.obs.name(id) |
Built with git-ssb-web