2019-11-28 03:56:44 +00:00
|
|
|
import { DataTree } from "reducers";
|
|
|
|
|
import { JSONPath } from "jsonpath-plus";
|
|
|
|
|
import { createSelector } from "reselect";
|
|
|
|
|
import { getDataTree } from "./entitiesSelector";
|
|
|
|
|
|
2019-12-06 13:16:08 +00:00
|
|
|
export type NameBindingsWithData = Record<string, object>;
|
2019-11-28 03:56:44 +00:00
|
|
|
export const getNameBindingsWithData = createSelector(
|
|
|
|
|
getDataTree,
|
|
|
|
|
(dataTree: DataTree): NameBindingsWithData => {
|
|
|
|
|
const nameBindingsWithData: Record<string, object> = {};
|
|
|
|
|
Object.keys(dataTree.nameBindings).forEach(key => {
|
|
|
|
|
const nameBindings = dataTree.nameBindings[key];
|
|
|
|
|
const evaluatedValue = JSONPath({
|
|
|
|
|
path: nameBindings,
|
|
|
|
|
json: dataTree,
|
|
|
|
|
})[0];
|
|
|
|
|
if (evaluatedValue && key !== "undefined") {
|
|
|
|
|
nameBindingsWithData[key] = evaluatedValue;
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-12-18 11:59:12 +00:00
|
|
|
|
2019-12-19 09:33:27 +00:00
|
|
|
return nameBindingsWithData;
|
2019-12-18 11:59:12 +00:00
|
|
|
},
|
|
|
|
|
);
|