git ssb

1+

Matt McKegg / mutant



Tree: d7a1130a598a37fd45555d78281b786778132101

Files: d7a1130a598a37fd45555d78281b786778132101 / keys.js

627 bytesRaw
1var computed = require('./computed')
2
3module.exports = Keys
4
5function Keys (collection) {
6 var result = []
7 var initialized = false
8 return computed(collection, function (value) {
9 var keys = Object.keys(value)
10 var changed = false
11 for (var i = 0; i < keys.length; i++) {
12 if (result[i] !== keys[i]) {
13 result[i] = keys[i]
14 changed = true
15 }
16 }
17
18 if (result.length !== keys.length) {
19 changed = true
20 result.length = keys.length
21 }
22
23 if (changed || !initialized) {
24 initialized = true
25 return result
26 } else {
27 return computed.NO_CHANGE
28 }
29 })
30}
31

Built with git-ssb-web