All files / src/react-application react-application-content.tsx

100% Statements 29/29
100% Branches 7/7
100% Functions 2/2
100% Lines 29/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 301x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 15x 15x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 9x 9x 1x 1x  
import { withInjectables } from "@ogre-tools/injectable-react";
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
import React from "react";
import {
  ReactApplicationChildren,
  reactApplicationChildrenInjectionToken,
} from "./react-application-children-injection-token";
import type { IComputedValue } from "mobx";
import { observer, Observer } from "mobx-react";
 
type Dependencies = { contents: IComputedValue<ReactApplicationChildren[]> };
 
const NonInjectedContent = observer(({ contents }: Dependencies) => (
  <>
    {contents.get().map((child) => (
      <Observer key={child.id}>{() => (child.enabled.get() ? <child.Component /> : null)}</Observer>
    ))}
  </>
));
 
export const ReactApplicationContent = withInjectables<Dependencies>(
  NonInjectedContent,
 
  {
    getProps: (di) => ({
      contents: di.inject(computedInjectManyInjectable)(reactApplicationChildrenInjectionToken),
    }),
  },
);