PromucFlow_constructor/app/client/src/normalizers/CanvasWidgetsNormalizer.tsx

28 lines
736 B
TypeScript
Raw Normal View History

2019-09-09 09:08:54 +00:00
import { normalize, schema, denormalize } from "normalizr";
import { WidgetProps } from "../widgets/BaseWidget";
2019-09-09 09:08:54 +00:00
import { ContainerWidgetProps } from "../widgets/ContainerWidget";
2019-03-21 17:42:23 +00:00
2019-09-09 09:08:54 +00:00
export const widgetSchema = new schema.Entity(
"canvasWidgets",
{},
{ idAttribute: "widgetId" },
);
2019-08-26 12:41:21 +00:00
widgetSchema.define({ children: [widgetSchema] });
2019-03-21 17:42:23 +00:00
class CanvasWidgetsNormalizer {
static normalize(
dsl: ContainerWidgetProps<WidgetProps>,
): { entities: any; result: any } {
return normalize(dsl, widgetSchema);
2019-09-09 09:08:54 +00:00
}
2019-03-21 17:42:23 +00:00
2019-09-09 09:08:54 +00:00
static denormalize(
pageWidgetId: string,
entities: any,
): ContainerWidgetProps<WidgetProps> {
2019-09-09 09:08:54 +00:00
return denormalize(pageWidgetId, widgetSchema, entities);
}
2019-03-21 17:42:23 +00:00
}
2019-09-09 09:08:54 +00:00
export default CanvasWidgetsNormalizer;