Files: b9445832e31d8b9279595a8b40c71be0fc1bc40e / keys.js
627 bytesRaw
1 | var computed = require('./computed') |
2 | |
3 | module.exports = Keys |
4 | |
5 | function 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