How to use the react-cosmos-shared2/fixtureState.extractValuesFromObject 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 / CaptureProps.js View on Github external
return false;
    }

    // Fixture state for this instance is populated on mount, so a transition
    // to an empty state means that this instance is expected to reset
    if (!next) {
      return true;
    }

    // If the fixture state for this instance has just been populated, we need
    // to compare its values against the default values, otherwise an additional
    // render cycle will be always run on init
    const prevKey = prev ? prev.renderKey : DEFAULT_RENDER_KEY;
    const prevValues = prev
      ? prev.values
      : extractValuesFromObject(children.props);

    if (next.renderKey !== prevKey) {
      return true;
    }

    // Because serialized fixture state changes are received remotely, a change
    // in one fixtureState.props instance will change the identity of all
    // fixtureState.props instances. So the only way to avoid useless re-renders
    // is to check if any value from the fixture state props changed.
    return !areValuesEqual(next.values, prevValues);
  }
github react-cosmos / react-cosmos / packages / react-cosmos-fixture / src / ComponentState.js View on Github external
setFixtureState(fixtureState => {
      const instanceId = getInstanceId(this);
      const componentName = getComponentName(getRefType(childRef));
      const stateInstance = {
        instanceId,
        componentName,
        values: extractValuesFromObject(componentState)
      };

      return {
        state: replaceOrAddItem(
          getFixtureStateState(fixtureState),
          state => state.instanceId === instanceId,
          stateInstance
        )
      };
    }, this.scheduleStateCheck);
  }
github react-cosmos / react-cosmos / packages / react-cosmos-fixture / src / CaptureProps.js View on Github external
setFixtureState(fixtureState => {
      const instanceProps = {
        instanceId,
        componentName,
        renderKey: DEFAULT_RENDER_KEY,
        values: extractValuesFromObject(children.props)
      };

      return {
        props: replaceOrAddItem(
          getFixtureStateProps(fixtureState),
          props => props.instanceId === instanceId,
          instanceProps
        )
      };
    });
  }