forked from freeCodeCamp/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.coffee
More file actions
77 lines (66 loc) · 1.78 KB
/
Copy pathdocs.coffee
File metadata and controls
77 lines (66 loc) · 1.78 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class app.collections.Docs extends app.Collection
@model: 'Doc'
findBySlug: (slug) ->
@findBy('slug', slug) or @findBy('slug_without_version', slug)
sort: ->
@models.sort (a, b) ->
a = a.name.toLowerCase()
b = b.name.toLowerCase()
if a < b then -1 else if a > b then 1 else 0
# Load models concurrently.
# It's not pretty but I didn't want to import a promise library only for this.
CONCURRENCY = 3
load: (onComplete, onError, options) ->
i = 0
next = =>
if i < @models.length
@models[i].load(next, fail, options)
else if i is @models.length + CONCURRENCY - 1
onComplete()
i++
return
fail = (args...) ->
if onError
onError(args...)
onError = null
next()
return
next() for [0...CONCURRENCY]
return
clearCache: ->
doc.clearCache() for doc in @models
return
uninstall: (callback) ->
i = 0
next = =>
if i < @models.length
@models[i++].uninstall(next, next)
else
callback()
return
next()
return
getInstallStatuses: (callback) ->
app.db.versions @models, (statuses) ->
if statuses
for key, value of statuses
statuses[key] = installed: !!value, mtime: value
callback(statuses)
return
return
checkForUpdates: (callback) ->
@getInstallStatuses (statuses) =>
i = 0
if statuses
i += 1 for slug, status of statuses when @findBy('slug', slug).isOutdated(status)
callback(i)
return
return
updateInBackground: ->
@getInstallStatuses (statuses) =>
return unless statuses
for slug, status of statuses
doc = @findBy 'slug', slug
doc.install($.noop, $.noop) if doc.isOutdated(status)
return
return