How to use the react-cosmos-shared2/fixtureState.findFixtureStateProps function in react-cosmos-shared2

To help you get started, we’ve selected a few react-cosmos-shared2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github react-cosmos / react-cosmos / packages / react-cosmos-fixture / src / FixtureCapture / props / index.ts View on Github external
elPaths.forEach(elPath => {
      const childEl = getExpectedElementAtPath(fixture, elPath);
      const elementId = { decoratorId, elPath };
      // Component fixture state can be provided before the fixture mounts (eg.
      // a previous snapshot of a fixture state or the current fixture state
      // from another renderer)
      if (!findFixtureStateProps(fixtureState, elementId)) {
        const componentName = getComponentName(childEl.type);
        setFixtureState(prevFs => ({
          ...prevFs,
          props: createFixtureStateProps({
            fixtureState: prevFs,
            elementId,
            values: createValues(childEl.props),
            componentName
          })
        }));
      } else if (
        !areNodesEqual(
          childEl,
          getElementAtPath(prevFixtureRef.current, elPath)
        )
      ) {
github react-cosmos / react-cosmos / packages / react-cosmos-fixture / src / FixtureCapture / props / extendFixtureProps.ts View on Github external
return elPaths.reduce((extendedFixture, elPath): React.ReactNode => {
    const elementId = { decoratorId, elPath };
    const fsProps = findFixtureStateProps(fixtureState, elementId);

    return setElementAtPath(extendedFixture, elPath, element => {
      if (!fsProps || componentTypeChanged(fsProps.componentName)) {
        return {
          ...element,
          key: getElRenderKey(elPath, DEFAULT_RENDER_KEY)
        };
      }

      // Prevent overriding child elements with outdated "children" prop values
      // stored in fixture state
      // See https://github.com/react-cosmos/react-cosmos/pull/920 for context
      const originalProps = element.props;
      const extendedProps = extendWithValues(originalProps, fsProps.values);

      // HACK alert: Editing React Element by hand
github react-cosmos / react-cosmos / packages / react-cosmos-playground2 / src / plugins / PropsPanel / PropsPanel / shared.ts View on Github external
return prevFs => {
    const fsProps = findFixtureStateProps(prevFs, elementId);
    if (!fsProps) {
      const elId = stringifyElementId(elementId);
      console.warn(`Trying to update missing element with ID: ${elId}`);
      return prevFs;
    }

    return {
      ...prevFs,
      props: cb(prevFs)
    };
  };
}
github react-cosmos / react-cosmos / packages / react-cosmos-playground2 / src / plugins / PropsPanel / PropsPanel.tsx View on Github external
setFixtureState(prevFs => {
      const fsProps = findFixtureStateProps(prevFs, elementId);
      if (!fsProps) {
        console.warn(`Element id ${elementId} no longer exists`);
        return prevFs;
      }

      return {
        ...prevFs,
        props: updateFixtureStateProps({
          fixtureState: prevFs,
          elementId,
          values
        })
      };
    });
  };
github react-cosmos / react-cosmos / packages / react-cosmos-playground2 / src / plugins / ControlPanel / PropsState.tsx View on Github external
setFixtureState(fixtureState => {
      const fsProps = findFixtureStateProps(fixtureState, elementId);
      if (!fsProps) {
        console.warn(`Element id ${elementId} no longer exists`);
        return fixtureState;
      }

      const { values } = fsProps;
      return {
        ...fixtureState,
        props: updateFixtureStateProps({
          fixtureState,
          elementId,
          values: replaceOrAddItem(values, propVal => propVal.key === key, {
            serializable: true,
            key,
            stringified: value
          })