aboutsummaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
authorHenry Jameson <me@hjkos.com>2020-01-20 01:44:11 +0200
committerHenry Jameson <me@hjkos.com>2020-01-20 01:44:11 +0200
commit2b36a62c5600738737e0fda4e0fc92e6e1f59c33 (patch)
treef0e78be6dd9ef702093469822363536ca0190737 /src/services
parent6e1c538e4182263a75fb65b0f3c5d1ad9de94541 (diff)
fix tests, integrate depenentless sorting into toposort for easier testing and
better guarantees
Diffstat (limited to 'src/services')
-rw-r--r--src/services/theme_data/theme_data.service.js22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/services/theme_data/theme_data.service.js b/src/services/theme_data/theme_data.service.js
index 36837b44..63bfb5af 100644
--- a/src/services/theme_data/theme_data.service.js
+++ b/src/services/theme_data/theme_data.service.js
@@ -540,7 +540,7 @@ const getDependencies = (key, inheritance) => {
* @property {Function} getDeps - function that returns dependencies for
* given value and inheritance object.
* @returns {String[]} keys of inheritance object, sorted in topological
- * order
+ * order. Additionally, dependency-less nodes will always be first in line
*/
export const topoSort = (
inheritance = SLOT_INHERITANCE,
@@ -579,7 +579,14 @@ export const topoSort = (
while (unprocessed.length > 0) {
step(unprocessed.pop())
}
- return output
+ return output.sort((a, b) => {
+ const depsA = getDeps(a, inheritance).length
+ const depsB = getDeps(b, inheritance).length
+
+ if (depsA === depsB || (depsB !== 0 && depsA !== 0)) return 0
+ if (depsA === 0 && depsB !== 0) return -1
+ if (depsB === 0 && depsA !== 0) return 1
+ })
}
/**
@@ -657,20 +664,13 @@ export const getLayerSlot = (
}
/**
- * topologically sorted SLOT_INHERITANCE + additional priority sort
+ * topologically sorted SLOT_INHERITANCE
*/
export const SLOT_ORDERED = topoSort(
Object.entries(SLOT_INHERITANCE)
.sort(([aK, aV], [bK, bV]) => ((aV && aV.priority) || 0) - ((bV && bV.priority) || 0))
.reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {})
-).sort((a, b) => {
- const depsA = getDependencies(a, SLOT_INHERITANCE).length
- const depsB = getDependencies(b, SLOT_INHERITANCE).length
-
- if (depsA === depsB || (depsB !== 0 && depsA !== 0)) return 0
- if (depsA === 0 && depsB !== 0) return -1
- if (depsB === 0 && depsA !== 0) return 1
-})
+)
/**
* Dictionary where keys are color slots and values are opacity associated