PromucFlow_constructor/app/client/src/selectors/nameBindingsWithDataSelector.ts

25 lines
790 B
TypeScript
Raw Normal View History

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;
}
});
return nameBindingsWithData;
},
);