How to use the react-cosmos-shared2/fixtureState.findFixtureStateClassState 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 / classState / useFixtureState.ts View on Github external
if (!elRef) {
      delete elRefs.current[elPath];
      return;
    }

    // Only track instances with state
    const { state } = elRef;
    if (!state) {
      return;
    }

    elRefs.current[elPath] = elRef;
    setInitialState(initialStates.current, elPath, elRef);

    const elementId = { decoratorId, elPath };
    const fsClassState = findFixtureStateClassState(
      lastFixtureState.current,
      elementId
    );
    if (!fsClassState) {
      setFixtureState(prevFs => ({
        ...prevFs,
        classState: createFixtureStateClassState({
          fixtureState: prevFs,
          elementId,
          values: createValues(state),
          componentName: getComponentName(
            elRef.constructor as React.ComponentType
          )
        })
      }));
    } else {
github react-cosmos / react-cosmos / packages / react-cosmos-fixture / src / FixtureCapture / classState / useFixtureState.ts View on Github external
elPaths.forEach(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)
      const fsClassState = findFixtureStateClassState(fixtureState, elementId);
      if (!fsClassState) {
        if (initialStates.current[elPath]) {
          const { state } = initialStates.current[elPath];
          const elRef = elRefs.current[elPath];

          if (!isEqual(elRef.state, state)) {
            replaceState(elRef, state);
          }

          setFixtureState(prevFs => ({
            ...prevFs,
            classState: createFixtureStateClassState({
              fixtureState: prevFs,
              elementId,
              values: createValues(state),
              componentName: getComponentName(
github react-cosmos / react-cosmos / packages / react-cosmos-fixture / src / FixtureCapture / classState / useFixtureState.ts View on Github external
//   1. Element type is stateless
        //   2. Element type is a class, but doesn't have state. An instance exists
        //      but has been discarded because of its lack of state.
        //   3. Element instance unmounted and is about to remount. When this
        //      happens, the new instance will be handled when its ref fires again.
        if (!elRef) {
          return;
        }

        // The child's state can be out of sync with the fixture state for two
        // reasons:
        //   1. The child's state changed internally
        //   2. The fixture state changed
        // Here we're interested in the second scenario. In the first scenario
        // we want to let the component state override the fixture state.
        const prevFsClassState = findFixtureStateClassState(
          prevFixtureState.current,
          elementId
        );
        if (prevFsClassState && !isEqual(prevFsClassState, fsClassState)) {
          return replaceState(
            elRef,
            extendWithValues(elRef.state, fsClassState.values)
          );
        }
      }
    });
  }, [
github react-cosmos / react-cosmos / packages / react-cosmos-playground2 / src / plugins / ClassStatePanel / ClassStatePanel.tsx View on Github external
onFixtureStateChange(prevFs => {
      const fsClassState = findFixtureStateClassState(prevFs, elementId);
      if (!fsClassState) {
        console.warn(`Decorator id ${elementId} no longer exists`);
        return prevFs;
      }

      return {
        ...prevFs,
        classState: updateFixtureStateClassState({
          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 fsClassState = findFixtureStateClassState(fixtureState, elementId);
      if (!fsClassState) {
        console.warn(`Decorator id ${elementId} no longer exists`);
        return fixtureState;
      }

      const { values } = fsClassState;
      return {
        ...fixtureState,
        classState: updateFixtureStateClassState({
          fixtureState,
          elementId,
          values: replaceOrAddItem(values, stateVal => stateVal.key === key, {
            serializable: true,
            key,
            stringified: value
          })
github react-cosmos / react-cosmos / packages / react-cosmos-playground2 / src / plugins / ControlPanel / PropsState.tsx View on Github external
({ elementId, componentName, values }) => {
        const { decoratorId, elPath } = elementId;
        const classState = findFixtureStateClassState(fixtureState, elementId);

        return (
          <div>
            <p>
              <strong>{componentName}</strong>
            </p>
            <div>
              <p>Props</p>
              {values.map(({ key, serializable, stringified }) =&gt; (
                </div></div>