How to use the react-cosmos-shared2/util.replaceOrAddItem 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-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
          })
        })
      };
    });
  };
github react-cosmos / react-cosmos / packages / react-cosmos-playground2 / src / plugins / ControlPanel / StatePanel.js View on Github external
const [stateFxState] = getStateFixtureState(
      fixtureState,
      createElFxStateMatcher(decoratorId, elPath)
    );

    if (!stateFxState) {
      console.warn(`State instance id ${decoratorId} no longer exists`);
      return;
    }

    const { values } = stateFxState;
    const state = updateStateFixtureState({
      fixtureState,
      decoratorId,
      elPath,
      values: replaceOrAddItem(values, value => value.key === key, {
        serializable: true,
        key,
        stringified: value
      })
    });

    postRendererRequest({
      type: 'setFixtureState',
      payload: {
        rendererId: RENDERER_ID,
        fixturePath,
        fixtureStateChange: {
          state
        }
      }
    });
github react-cosmos / react-cosmos / packages / react-cosmos-playground2 / src / plugins / Notifications / pushNotification.tsx View on Github external
context.setState(prevState => ({
    ...prevState,
    timedNotifications: {
      timeoutId: createNotificationTimeout(context),
      items: replaceOrAddItem(
        getTimedNotifications(prevState),
        i => i.id === notification.id,
        notification
      )
    }
  }));
}
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
        )
      };
    });
  }
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-playground2 / src / plugins / Notifications / pushNotification.tsx View on Github external
context.setState(prevState => ({
    ...prevState,
    stickyNotifications: replaceOrAddItem(
      prevState.stickyNotifications,
      i => i.id === notification.id,
      notification
    )
  }));
}