git ssb

1+

Matt McKegg / mutant



Tree: 91e3d5d798ebcef85048597e9a56b9f579613469

Files: 91e3d5d798ebcef85048597e9a56b9f579613469 / 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