Apply prefer-const lint rule
This commit is contained in:
1 parent
b43088c03c
commit
09e6a360af
26 files changed
+217
-215
No files matched your search
+33
-31
@@ -91,7 +91,7 @@ function getAliasDeclarations(path, timestamp) {
|
||||
|
||||
for (let i = prefix.length; i < pattern.length; ++i) {
|
||||
if (Array.isArray(pattern[i])) {
|
||||
let pat = pattern[i];
|
||||
const pat = pattern[i];
|
||||
pattern[i] = "*";
|
||||
for (let j = 0; j < pat.length; j += 2)
|
||||
recursive(pat[j], pattern.slice(0, i + 1));
|
||||
@@ -110,10 +110,10 @@ function getAliasDeclarations(path, timestamp) {
|
||||
function unpack(deviceData, path, revision) {
|
||||
let allMatches = [];
|
||||
if (!path.alias) {
|
||||
for (let p of deviceData.paths.find(path, false, true))
|
||||
for (const p of deviceData.paths.find(path, false, true))
|
||||
if (deviceData.attributes.has(p, revision)) allMatches.push(p);
|
||||
} else {
|
||||
let wildcardPath = path.slice();
|
||||
const wildcardPath = path.slice();
|
||||
wildcardPath.wildcard = path.wildcard;
|
||||
for (let i = 0; i < wildcardPath.length; ++i) {
|
||||
if (Array.isArray(wildcardPath[i])) {
|
||||
@@ -122,13 +122,13 @@ function unpack(deviceData, path, revision) {
|
||||
}
|
||||
}
|
||||
|
||||
for (let p of deviceData.paths.find(wildcardPath, false, true))
|
||||
for (const p of deviceData.paths.find(wildcardPath, false, true))
|
||||
if (deviceData.attributes.has(p, revision)) allMatches.push(p);
|
||||
|
||||
for (let i = path.length - 1; i >= 0; --i) {
|
||||
if (Array.isArray(path[i])) {
|
||||
for (let j = 0; j < path[i].length; j += 2) {
|
||||
let p = wildcardPath.slice(0, i + 1).concat(path[i][j]);
|
||||
const p = wildcardPath.slice(0, i + 1).concat(path[i][j]);
|
||||
p.alias =
|
||||
((wildcardPath.alias & ((1 << (i + 1)) - 1)) + path[i][j].alias) <<
|
||||
(i + 1);
|
||||
@@ -136,10 +136,10 @@ function unpack(deviceData, path, revision) {
|
||||
((wildcardPath.wildcard & ((1 << (i + 1)) - 1)) +
|
||||
path[i][j].wildcard) <<
|
||||
(i + 1);
|
||||
let unpacked = unpack(deviceData, p, revision);
|
||||
let filtered = [];
|
||||
for (let up of unpacked) {
|
||||
let attributes = deviceData.attributes.get(up, revision);
|
||||
const unpacked = unpack(deviceData, p, revision);
|
||||
const filtered = [];
|
||||
for (const up of unpacked) {
|
||||
const attributes = deviceData.attributes.get(up, revision);
|
||||
if (
|
||||
attributes &&
|
||||
attributes.value &&
|
||||
@@ -171,8 +171,9 @@ function unpack(deviceData, path, revision) {
|
||||
if (a === b) continue;
|
||||
|
||||
// Use numeric sorting for numbers
|
||||
let ia = parseInt(a),
|
||||
ib = parseInt(b);
|
||||
const ia = parseInt(a);
|
||||
const ib = parseInt(b);
|
||||
|
||||
if (ia.toString() === a && ib.toString() === b) {
|
||||
a = ia;
|
||||
b = ib;
|
||||
@@ -188,7 +189,7 @@ function unpack(deviceData, path, revision) {
|
||||
}
|
||||
|
||||
function clear(deviceData, path, timestamp, attributes, changeFlags = 0) {
|
||||
let changeTrackers = {};
|
||||
const changeTrackers = {};
|
||||
|
||||
timestamp = timestamp || 0;
|
||||
|
||||
@@ -200,16 +201,16 @@ function clear(deviceData, path, timestamp, attributes, changeFlags = 0) {
|
||||
attributes.value = attributes.object;
|
||||
}
|
||||
|
||||
for (let p of deviceData.paths.find(
|
||||
for (const p of deviceData.paths.find(
|
||||
path,
|
||||
true,
|
||||
true,
|
||||
descendantsTimestamp ? 99 : path.length
|
||||
)) {
|
||||
let tracker = deviceData.trackers.get(p);
|
||||
for (let k in tracker) changeTrackers[k] |= tracker[k];
|
||||
const tracker = deviceData.trackers.get(p);
|
||||
for (const k in tracker) changeTrackers[k] |= tracker[k];
|
||||
|
||||
let currentTimestamp = deviceData.timestamps.get(p);
|
||||
const currentTimestamp = deviceData.timestamps.get(p);
|
||||
if (currentTimestamp === undefined) continue;
|
||||
|
||||
if (
|
||||
@@ -220,10 +221,10 @@ function clear(deviceData, path, timestamp, attributes, changeFlags = 0) {
|
||||
deviceData.attributes.delete(p);
|
||||
changeFlags |= 1;
|
||||
} else if (attributes && p.length == path.length) {
|
||||
let currentAttributes = deviceData.attributes.get(p);
|
||||
const currentAttributes = deviceData.attributes.get(p);
|
||||
if (currentAttributes) {
|
||||
let newAttrs;
|
||||
for (let attrName in attributes) {
|
||||
for (const attrName in attributes) {
|
||||
if (
|
||||
attrName in currentAttributes &&
|
||||
attributes[attrName] > currentAttributes[attrName][0]
|
||||
@@ -242,7 +243,7 @@ function clear(deviceData, path, timestamp, attributes, changeFlags = 0) {
|
||||
|
||||
// Note: For performance, we're merging all changes together rather than
|
||||
// mark changes based the exact parameters affected.
|
||||
for (let k in changeTrackers)
|
||||
for (const k in changeTrackers)
|
||||
if (changeTrackers[k] & changeFlags) deviceData.changes.add(k);
|
||||
}
|
||||
|
||||
@@ -264,7 +265,7 @@ function compareEquality(a, b) {
|
||||
function set(deviceData, path, timestamp, attributes, toClear) {
|
||||
path = deviceData.paths.add(path);
|
||||
|
||||
let currentTimestamp = deviceData.timestamps.get(path);
|
||||
const currentTimestamp = deviceData.timestamps.get(path);
|
||||
|
||||
let currentAttributes;
|
||||
|
||||
@@ -289,10 +290,10 @@ function set(deviceData, path, timestamp, attributes, toClear) {
|
||||
)
|
||||
attributes.value = [attributes.object[0]];
|
||||
|
||||
let newAttributes = Object.assign({}, currentAttributes, attributes);
|
||||
const newAttributes = Object.assign({}, currentAttributes, attributes);
|
||||
|
||||
if (currentAttributes) {
|
||||
for (let attrName in attributes) {
|
||||
for (const attrName in attributes) {
|
||||
timestamp = Math.max(timestamp, attributes[attrName][0]);
|
||||
if (!(attrName in currentAttributes))
|
||||
changeFlags |= CHANGE_FLAGS[attrName];
|
||||
@@ -331,7 +332,7 @@ function set(deviceData, path, timestamp, attributes, toClear) {
|
||||
deviceData.attributes.delete(path);
|
||||
changeFlags |= 1;
|
||||
} else if (path.wildcard) {
|
||||
for (let p of deviceData.paths.find(path, false, true, path.length)) {
|
||||
for (const p of deviceData.paths.find(path, false, true, path.length)) {
|
||||
if (timestamp > deviceData.timestamps.get(p)) {
|
||||
toClear = toClear || [];
|
||||
toClear.push([p, timestamp]);
|
||||
@@ -348,9 +349,9 @@ function set(deviceData, path, timestamp, attributes, toClear) {
|
||||
toClear = toClear || [];
|
||||
toClear.push([path, 0, { object: attributes.object[0] }, changeFlags]);
|
||||
} else {
|
||||
for (let p of deviceData.paths.find(path, true, false, path.length)) {
|
||||
let tracker = deviceData.trackers.get(p);
|
||||
for (let k in tracker)
|
||||
for (const p of deviceData.paths.find(path, true, false, path.length)) {
|
||||
const tracker = deviceData.trackers.get(p);
|
||||
for (const k in tracker)
|
||||
if (tracker[k] & changeFlags) deviceData.changes.add(k);
|
||||
}
|
||||
}
|
||||
@@ -363,7 +364,8 @@ function track(deviceData, path, marker, attributes) {
|
||||
path = deviceData.paths.add(path);
|
||||
let f = 1;
|
||||
|
||||
if (attributes) for (let attrName of attributes) f |= CHANGE_FLAGS[attrName];
|
||||
if (attributes)
|
||||
for (const attrName of attributes) f |= CHANGE_FLAGS[attrName];
|
||||
|
||||
let cur = deviceData.trackers.get(path);
|
||||
if (!cur) {
|
||||
@@ -376,11 +378,11 @@ function track(deviceData, path, marker, attributes) {
|
||||
|
||||
function clearTrackers(deviceData, tracker) {
|
||||
if (Array.isArray(tracker)) {
|
||||
for (let v of deviceData.trackers.values())
|
||||
for (let t of tracker) delete v[t];
|
||||
for (let t of tracker) deviceData.changes.delete(t);
|
||||
for (const v of deviceData.trackers.values())
|
||||
for (const t of tracker) delete v[t];
|
||||
for (const t of tracker) deviceData.changes.delete(t);
|
||||
} else {
|
||||
for (let v of deviceData.trackers.values()) delete v[tracker];
|
||||
for (const v of deviceData.trackers.values()) delete v[tracker];
|
||||
deviceData.changes.delete(tracker);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user